1. Learn
  2. /
  3. Courses
  4. /
  5. Financial Trading in Python

Exercise

Conduct a strategy optimization

You have an SMA-based signal strategy to trade stocks. However, you are not sure what lookback period to use for calculating the SMA that can optimize the strategy performance. You plan to run multiple backtests on different input parameters. Also, you want the capability to assess the strategy on trading different stocks or based on different historical periods.

The bt package has been imported for you. Also, the historical price data of the Tesla stock has been preloaded in price_data.

Instructions 1/3

undefined XP
    1
    2
    3
  • Complete the function signal_strategy so that it will calculate sma using price_data based on a given period.
  • Define a signal strategy by comparing price_data and sma, and return a bt backtest.