The last operations are always lost in Backtesting
The last operations are always lost in Backtesting
18 May 2019, 08:22
Every time I backtest my code, the equity chart always ends with a considerable equity drawdown:
I speculate it is because when the simulation ends, whatever open positions existed at that moment where just cut off and their equity not returned, but lost.
I've searched through the API to modify my code to adequately close all positions or not open more when the simulation end is near, but AFAIK there's nothing in the API that'll tell me the time of the simulation's end.
Could we fix this? Anything I could do to avoid this? Otherwise, the Sharpe ratio and other calculations are incorrectly mistaken.
Replies
nmaxcom
20 May 2019, 16:09
Hi,
What you are showing to us is the values that the equity fluctuated in between since closing the last position.
I'm not sure that sentence makes syntactical sense, could you clarify?
I use Print() every time a position is opened or closed. During the backtesting, positions open and close. But near the end, positions open and the backtesting ends. So in the log, you'd see it ends with "positions opened" X amount of times instead of "positions closed." So programmatically speaking my code doesn't have the chance to close those positions.
@nmaxcom
PanagiotisCharalampous
20 May 2019, 16:17
Hi nmaxcom,
I mean that since you closed the last position and until the end of the backtesting, the equity fluctuated between 6344.63 and 4980.22. It is seems there is a position open when the backtesting is completed.
Best Regards,
Panagiotis
@PanagiotisCharalampous
Symposium
21 May 2019, 03:23
RE:
nmaxcom said:
Hi,
What you are showing to us is the values that the equity fluctuated in between since closing the last position.
I'm not sure that sentence makes syntactical sense, could you clarify?
I use Print() every time a position is opened or closed. During the backtesting, positions open and close. But near the end, positions open and the backtesting ends. So in the log, you'd see it ends with "positions opened" X amount of times instead of "positions closed." So programmatically speaking my code doesn't have the chance to close those positions.
Hi Nmaxcom, Panagiotis is correct, you still have position(s) open when the backtest period ends. You should be able to see the unclosed position(s) in the events tab...
In your example above, find the date (time) that the 22 position closes (or anyother number that closes on /above the balance line) and end the backtest on that date. You should see either positive equity or a lot less DD. Cheers
@Symposium
nmaxcom
30 May 2019, 00:31
Hi both,
It is seems there is a position open when the backtesting is completed.
you still have position(s) open when the backtest period ends.
You don't say? You are not telling me anything I don't know. That's exactly what I said in OP:
Every time I backtest my code, the equity chart always ends with a considerable equity drawdown. I speculate it is because when the simulation ends, whatever open positions existed at that moment were just cut off
So, backtesting stops whenever it's set to stop, but when it happens with open positions, the graph shows an equity drawdown that never happened.
@nmaxcom
PanagiotisCharalampous
30 May 2019, 09:32
Hi nmaxcom,
Can you post the cBot code and explain your calim that "an equity drawdown that never happened"?
Best Regards,
Panagiotis
@PanagiotisCharalampous
PanagiotisCharalampous
20 May 2019, 10:29
Hi nmaxcom,
There is no issue here. No positions are cut off or lost on ending the backtesting. What you are showing to us is the values that the equity fluctuated in between since closing the last position. To see the equity of the account when backtesting stopped, please check the Trade Statistics tab.
Best Regards,
Panagiotis
@PanagiotisCharalampous