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.
Deze oefening maakt deel uit van de cursus
Financial Trading in Python
Praktische interactieve oefening
Probeer deze oefening eens door deze voorbeeldcode in te vullen.
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)