Are all backtest results potentially flawed?

Posted By: pcz

Are all backtest results potentially flawed? - 11/21/16 12:22

I haven't received an answer for reported problems with slippage in another thread yet so I'll try to reformulate the issue and also provide a code to reproduce the whole thing.

It seems that when you set slippage greater than zero, the results might be optimistically biased. The effects can be quite profound even with values around 5, which is the default in new Zorro. It can effectively ruin your account. You can try for yourself with this simple mean reversion strategy:

Code:
//Asset settings in AssetFix.csv: 
// EUR/USD,1.12000,0.00005,-0.418,0.0560,0.0001,10.00,2236,0,100000,0,

function run()
{
	Asset = "EUR/USD";
	StartDate = 20140101;
	EndDate = 20141231;
	if(IBS() < 0.2 && NumOpenLong == 0)
		enterLong();
	if(IBS() > 0.8 && NumOpenShort == 0)
		enterShort();
}



In Zorro 1.51 it gives me AR 50% and SR 1.15 - not that bad, right? Now lets add line Slippage = 0;

With zero slippage AR is 0% and SR 0.01. Isn't that weird? Lets try larger value, for example one minute (i.e. 60). Now the AR is 1293% and SR is 11.12. The number of trades and entry / exit times are the same as with slippage set to 0, yet the results are very different. This is for example the first trade for both extreme cases (i.e. Slippage = 0 and Slippage = 60 in the second line):

Code:
Osc_spread,Long,EUR/USD,8201,1,2014-01-07 19:00,2014-01-08 02:00,1.3617,1.3628,108.00,0.00,Reverse
Osc_spread,Long,EUR/USD,8201,1,2014-01-07 19:00,2014-01-08 02:00,1.3613,1.3630,163.99,0.00,Reverse



Exported price data for the asset (around open / exit time):
Code:
07/01/14 19:00, 1.36175, 1.36184, 1.36163, 1.36163
07/01/14 19:01, 1.36163, 1.36163, 1.36154, 1.36157
...
08/01/14 02:00, 1.36283, 1.36290, 1.36283, 1.36289
08/01/14 02:01, 1.36289, 1.36290, 1.36274, 1.36275



As you can see with slippage the entry and exit prices are way out of line.

Sphin noted that in the new beta version there should be a fix for some slippage issues but I tried it and the results are the same so I assume it was a different problem than this one I described.

Also - I asked for this months ago: it would be really useful to increase the precision of price representation in log files. With only four decimal places it's really hard to debug the fine details.
Posted By: Finstratech

Re: Are all backtest results potentially flawed? - 11/21/16 13:45

I noticed that some systems behave very differently with and without the TICKS flag. Try setting it and the EXTRADATA flag. I haven't played with the slippage yet though. Will try.
Posted By: pcz

Re: Are all backtest results potentially flawed? - 11/21/16 15:07

Originally Posted By: Finstratech
I noticed that some systems behave very differently with and without the TICKS flag. Try setting it and the EXTRADATA flag. I haven't played with the slippage yet though. Will try.


TICKS + EXTRADATA (especially the second flag) change the results somewhat but there's still a huge difference even between 0 and 5 sec slippage backtest. You can try it for yourself with the code provided above.
Posted By: Sphin

Re: Are all backtest results potentially flawed? - 11/21/16 15:51

I noted that What's New page promotes a slippage bug to be solved in 1.52.0 but this version seems to be not available yet because the actual beta on the download page is 1.51.9. Did you already get 1.52.0 there?
Posted By: pcz

Re: Are all backtest results potentially flawed? - 11/21/16 16:18

Originally Posted By: Sphin
I noted that What's New page promotes a slippage bug to be solved in 1.52.0 but this version seems to be not available yet because the actual beta on the download page is 1.51.9. Did you already get 1.52.0 there?


Sorry, I misunderstood your last post. I thought that it's fixed in 1.51.9. So we'll see if it is fixed in the next version.

Nevertheless it's worth noting that all previous backtests should be done again as Slippage > 0 has been default.
Posted By: MattY

Re: Are all backtest results potentially flawed? - 11/21/16 19:03

Hey, test with this, so you are always on the pessimistic and more real side:

Quote:
Setting Slippage to a negative amount simulates asymmetric slippage that is always in adverse direction of the trade. Asymmetric slippage is illegal, but some trading platforms allow the broker to automatically apply asymmetric slippage for reducing the trader's profit.


I trade with FXCM and the slippage seems to be much greater on the negative side (hope they don't do this on purpose....).
Posted By: DavidC911

Re: Are all backtest results potentially flawed? - 11/21/16 21:15

Does it mean that all Z system's results are rather optimistic?

If so, how can we deal with that issue since we can't modify the Slippage or Fill parameter of the Z system?(or can we?)
Posted By: pcz

Re: Are all backtest results potentially flawed? - 11/22/16 08:40

Originally Posted By: DavidC911
Does it mean that all Z system's results are rather optimistic?

If so, how can we deal with that issue since we can't modify the Slippage or Fill parameter of the Z system?(or can we?)


Not necessarily. I've tried the same for my other strategy and greater values of slippage had actually decreased its performance. But I have no clue which strategies might be affected.
Posted By: DavidC911

Re: Are all backtest results potentially flawed? - 11/22/16 13:01

Originally Posted By: pcz
Not necessarily. I've tried the same for my other strategy and greater values of slippage had actually decreased its performance. But I have no clue which strategies might be affected.

Thanks for your info, pcz. I'll keep this potential flaw in mind.
Posted By: Finstratech

Re: Are all backtest results potentially flawed? - 11/22/16 14:07

I tried my own systems and slippage works as expected - decreasing results when slippage increased.
Posted By: pcz

Re: Are all backtest results potentially flawed? - 12/02/16 10:50

It seems that in the new Zorro beta release (1.52) the issue is indeed fixed which is great. However it would be nice to know whether this bug had affected the backtest results of Z strategies.

I also think that it's worth considering whether to send an e-mail to registered users to let them know about this bug. For myself I can say that I've been running a losing strategy for 6 months because of this bug. People who don't read the forum and / or release notes that diligently might not notice and lose lot of money.

Another thing I noticed is that it makes no difference in the old version if you test with ".t1" data and TICKS flag set. And my question is: shouldn't Zorro in this particular case compute the slippage from real prices? (i.e. single ticks)
Posted By: jcl

Re: Are all backtest results potentially flawed? - 12/02/16 14:50

The Z strategies have not been affected. Using single ticks for determining the order fill is something different to slippage; it can be determined with the Fill mode. Slippage always picks a random price from the given range, regardless whether the simulation runs in ticks mode or not.
Posted By: pcz

Re: Are all backtest results potentially flawed? - 12/03/16 14:41

Originally Posted By: jcl
Using single ticks for determining the order fill is something different to slippage; it can be determined with the Fill mode. Slippage always picks a random price from the given range, regardless whether the simulation runs in ticks mode or not.


So if I run a simulation with BarPeriod 100 ms and set Slippage to 5, it will choose one of the following 50 bars and pick a price from the estimated price curve (which in this particular case would be probably the same as OHLC of the bar). Is that correct?
Posted By: jcl

Re: Are all backtest results potentially flawed? - 12/05/16 08:27

Almost. It will not pick one of the next 50 bars, but use only the next bar for determining its volatility and direction. It then picks a price that fulfils those parameters, assuming that volatility increases with the square root of time.
© 2024 lite-C Forums