-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
SignalStrategy: 6 signals, 5 trades #495
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I got the same error when trying to use the code found in the page "Library of Composable Base Strategies" (https://kernc.github.io/backtesting.py/doc/examples/Strategies%20Library.html, class SmaCross) to replicate the results found in the "Quick Start User Guide" (https://kernc.github.io/backtesting.py/doc/examples/Quick%20Start%20User%20Guide.html, class SmaCross). The very first trade of the code which uses the SignalStrategy subclass is never performed, even for a test run with only one signal (no trade was performed in this case). In the former code, the signals are generated in advance, in a vectored manner, and the subclass SignalStrategy is used. As far as I could investigate, the problem seems to be the following code found in the run() method of the Backtest class:
The code above is used to skip the first few ticks in which the indicators all have NANs in them. So, the "+1" in front is used to ensure that there are at least two days in a row with no NANs in any indicator (not sure if this is necessary). It is all OK for a standard run, but in the case in which the SignalStrategy is used, the very first trade is always ignored. Does it make sense? |
Thanks! The issue seems to be in backtesting.py/backtesting/lib.py Lines 411 to 413 in 0ce24d8
Since any zeros are replaced with NaNs, along with +1 in Backtest.run() , this skips past the first signal.
|
Discussed in #486
Originally posted by AetherTL September 30, 2021

The entry size plot shows a short signal was received at around March 1987, but no trade has been made, I don't know why
I was using the HSI index as the dataset, and the strategy is simple, if the Z-value < -threshold the short the index, if >threshold then long it, it works at Oct 87 but failed at March, I am confusing now
Issue: #486 (comment)
Example in https://colab.research.google.com/drive/1l4Ki7tcdlhjEqfcuhdETdxbupIwyB6KS?usp=sharing
The text was updated successfully, but these errors were encountered: