-
Notifications
You must be signed in to change notification settings - Fork 430
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
positions should not mix NaN and 0s #218
Merged
Merged
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
Codecov ReportAttention: Patch coverage is
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## master #218 +/- ##
==========================================
+ Coverage 45.50% 45.52% +0.02%
==========================================
Files 4 4
Lines 1936 1935 -1
Branches 449 449
==========================================
Hits 881 881
+ Misses 998 997 -1
Partials 57 57 ☔ View full report in Codecov by Sentry. |
I propose a simple fix to the fact that the `positions` property for `StrategyBase` class in a situation when a position was opened and then closed returns NaN for the current date for the closed positions. This is not coherent with the behaviour of the property for the past, i.e. positions that open mid-backtest have zero positions filled from the backtest start to the current moment. Alternative fix would be to change line 884, so `positions` property of `SecurityBase` to: `return self._positions.loc[:self.>root.<now] but I think it would be less efficient and clumsy. For the purposes when you just want to print the positions timeseries, having it coherently filled with zeros when you, well, have zero position in a security would be optimal.
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.
I propose a simple fix to the fact that the
positions
property forStrategyBase
class in a situation when a position was opened and then closed returns NaN for the current date for the closed positions.This is not coherent with the behaviour of the property for the past, i.e. positions that open mid-backtest have zero positions filled from the backtest start to the current moment.
Alternative fix would be to change line 884, so
positions
property ofSecurityBase
to:return self._positions.loc[:self.**root.**now
(stars for emphasis)but I think it would be less efficient and clumsy.
For the purposes when you just want to print the positions timeseries, having it coherently filled with zeros when you, well, have zero position in a security would be optimal.