backtesting.py icon indicating copy to clipboard operation
backtesting.py copied to clipboard

Automatic closing of the positions at the end of the simulation

Open gaborvecsei opened this issue 3 years ago • 3 comments

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?

gaborvecsei avatar May 05 '21 17:05 gaborvecsei

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

So the trades can produce some stats. See https://github.com/kernc/backtesting.py/issues/183, https://github.com/kernc/backtesting.py/commit/f77786e5216f536f4eb50475c750cdd7d438502f.

kernc avatar May 05 '21 18:05 kernc

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.

gaborvecsei avatar May 06 '21 07:05 gaborvecsei

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

replacementAI avatar Nov 23 '21 15:11 replacementAI