Skip to content
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 1 commit into from
Jun 28, 2024
Merged

Conversation

mkeds
Copy link
Contributor

@mkeds mkeds commented May 22, 2020

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 (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.

@codecov-commenter
Copy link

codecov-commenter commented May 22, 2020

Codecov Report

Attention: Patch coverage is 0% with 1 line in your changes missing coverage. Please review.

Project coverage is 45.52%. Comparing base (dadbc4d) to head (c0bda68).
Report is 15 commits behind head on master.

Files Patch % Lines
bt/core.py 0.00% 1 Missing ⚠️

❗ 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.
📢 Have feedback on the report? Share it here.

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
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants