-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
ZIGZAG : Backtesting safe mode boolean flag. #874
Open
80sVectorz
wants to merge
17
commits into
twopirllc:development
Choose a base branch
from
80sVectorz:backtest-safe-zigzag-mode
base: development
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
ZIGZAG : Backtesting safe mode boolean flag. #874
80sVectorz
wants to merge
17
commits into
twopirllc:development
from
80sVectorz:backtest-safe-zigzag-mode
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Improved zigzag.py 'returns' description in main function docstring
Development
The nb_find_zigzag function calculation in reverse tripped me up.
Development
…torz/pandas-ta into backtest-safe-zigzag-mode
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Original problem
Currently, the zigzag indicator can't be used for back-testing purposes, as the pivot indices are placed before their actual detection would have happened.
A column that shows at what bar index the pivot was confirmed would be fantastic. The column could either have the absolute index or an offset. Along with the disregard of lag in pivot detection, there's the bigger issue of zigzag swing points moving when lower or higher pivots are detected.
Solution
To solve the issue, I've implemented a new back testing mode into the existing zigzag implementation.
When the new
backtest_mode
boolean flag is enabled, the function uses a modified version of the existingnb_find_zigzags
.This function run from front to back instead of from back to front, making it easy to track changes to existing zigzag swings.
The new function includes any raising or lowering of the swing points as new entries. Those entries should be treated as updates and not as new zigzag points.
After the zigzag points are found, an offset equal to half the pivot detection window or
floor(legs/2)
is added to the existing offset parameter. This ensures the lag of detecting pivots is accounted for.Other changes
Along with the main feature came some other changes:
np.shift
instead ofnp.roll
Personal ramblings
At first, this seemed like a very daunting task. But after deciphering the code, the solution did come to me pretty quickly.
I did trip up on the
nb_find_zigzags
function using a reversed approach quite a lot.Overall, a fun and good challenge!