Backtesting.py backtest statistics only shows nans and 0

370 views Asked by At

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

2

There are 2 answers

0
kbs On BEST ANSWER

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.

1
Daan On

In your strategy, you seem to place a buy order if your vortex-based condition is met. However, you never close the position (with self.position.close()). If you don't close the position, your trade will never end, which does not make room for a second trade.

To fix this, you need to either implement an exit strategy or use a take-profit (and optionally a stop-loss).

Hopefully this helps.