Skip to content

Automatic closing of the positions at the end of the simulation #343

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

Closed
gaborvecsei opened this issue May 5, 2021 · 3 comments · Fixed by #393
Closed

Automatic closing of the positions at the end of the simulation #343

gaborvecsei opened this issue May 5, 2021 · 3 comments · Fixed by #393
Labels
enhancement New feature or request Hacktoberfest https://hacktoberfest.digitalocean.com

Comments

@gaborvecsei
Copy link

This is just a question about whats in the title.

  • Why is the framework closing the positions automatically at the end of the simulation?
  • Is there any way to prevent that?
@kernc
Copy link
Owner

kernc commented May 5, 2021

Why is the framework closing the positions automatically at the end of the simulation?

So the trades can produce some stats. See #183, f77786e.

@gaborvecsei
Copy link
Author

So the trades can produce some stats. See #183, f77786e.

I understand that the unclosed trades wouldn't appearing in the final stats but that could be also a stat. E.g.:

  • still open positions
  • allocated money in those positions
  • return should be calculated only for the closed positions

Maybe a parameter like autoclose_open_positions in bt.run() would be useful, so people can decide if they want the feature or not.

I raised this question because the still open positions is also a good measure of a strategy. If the strategy fails to close the positions, this auto-closing can give the false feeling that the Strategy is working fine.

@replacementAI
Copy link

Still able to see open trades that are closed because they are the last ones.

Benouare added a commit to Benouare/backtesting.py that referenced this issue May 15, 2023
kernc added a commit that referenced this issue Jan 30, 2025
* ENH: Add the possibility to close trades at end of bt.run (#273 & #343)

* Change parameter name, simplify tests
* Fix failing test

---------

Co-authored-by: Bénouare <[email protected]>
Co-authored-by: benoit <[email protected]>
Co-authored-by: Kernc <[email protected]>
mmortall pushed a commit to mmortall/backtesting-ext.py that referenced this issue Feb 3, 2025
* ENH: Add the possibility to close trades at end of bt.run (kernc#273 & kernc#343)

* Change parameter name, simplify tests
* Fix failing test

---------

Co-authored-by: Bénouare <[email protected]>
Co-authored-by: benoit <[email protected]>
Co-authored-by: Kernc <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Hacktoberfest https://hacktoberfest.digitalocean.com
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants