Perform a strategy benchmarking
You are wondering: instead of spending energy actively trading a stock, what if you just sit back and hold the stock for a period of time. Does your active trading strategy generate better profits than a passive buy-and-hold strategy? To answer this question, you plan to perform a benchmarking test.
The bt
package has been imported for you. Also, the historical price data of the Tesla stock has been preloaded in price_data
.
In addition, the three strategy backtests sma10
, sma30
. sma50
from the previous exercise have been pre-loaded, and can be used directly.
This exercise is part of the course
Financial Trading in Python
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
def buy_and_hold(price_data, name):
# Define the benchmark strategy
bt_strategy = bt.Strategy(name,
[____,
bt.algos.SelectAll(),
bt.algos.WeighEqually(),
bt.algos.Rebalance()])
# Return the backtest
return ____(bt_strategy, price_data)