Search code examples
pythonalgorithmic-tradingback-testing

Backtesting.py backtest statistics only shows nans and 0


I am trying to backtest a momentum strategy using Backtesting.py. I've gathered the data and computed indicator values using pandas_ta. I've defined short and long trading conditions. Now I just need Backtesting.py to run a backtest so that I can determine the performance of my strategy on historical data.

I am expecting stats from bt.run() to show me values instead of nan and 0.

I am working using this notebook: https://github.com/kbs-code/algo_trader/blob/master/backtests/backtestingdotpy_SPY_weekly_vortex.ipynb

EDIT: The name of this notebook is now https://github.com/kbs-code/algo_trader/blob/master/backtests/debugging_example_backtestingdotpy.ipynb

Thanks


Solution

  • The backtester must use "self.data.foo" and not "self.foo" in order to use values inside any column. Please see the updated notebook with troubleshooting proof.