Australian (ASX) Stock Market Forum

Amibroker - Backtesting of delisted securities

Joined
8 November 2009
Posts
51
Reactions
0
Hi all,

For a while now I have been trying to figure out how to backtest delisted securities in amibroker. The problem being that the backtester won't close out your open positions when the stock is de-listed and eventually you just end up in de-listed securities with your equity going nowhere.
Anyways i've finally found a solution and though I'd post it here as I searched everywehere for it and could not find anything.

The solution is as follows:

Buy = ............
AND BarIndex() < (LastValue(BarIndex())-1);

Sell = .............
OR BarIndex() == (LastValue(BarIndex())-1);

Harro
 
Hi all,

The solution is as follows:

Buy = ............
AND BarIndex() < (LastValue(BarIndex())-1);

Sell = .............
OR BarIndex() == (LastValue(BarIndex())-1);

Harro
"It seems that the formula references FUTURE quotes.
If you backtest this system you may receive outstanding results
that CAN NOT be reproduced in real trading."
 
This formula is looking into the future but not at future price/volumes simply at the number of bars left.

Barindex() is simply the number of bars since quotation of the stock began

LastValue(BarIndex()) Is always equal to the barindex on the last day of quotation.

If you graph these it will make more sense.

So,

Sell = .........
OR BarIndex() == (LastValue(BarIndex())-1);

Simply generates a sell signal the day before the stocks last quote (When it is delisted), and with trade delay set to 1, sells on the last quote.

Buy = ..........
AND BarIndex() < (LastValue(BarIndex())-1);

Stops you from buying in the day before a stock is delisted or on the day it is delisted (As the sell signal would never be generated) , this only happens in a few corner cases.

Harro
 
And how do the listed stocks return with this future referencing code? Exceptional?
 
Just ran a quick test adding the code to my existing buy/sell signals on one of my systems and it had no affect on the end result so there are no forward looking issues with respect to existing buy/sell conditions ie. it doesn't change signals in the way zig/trough/peak etc. do. The code simply looks ahead to see if there is another bar as explained by Harro.
 
Thanks for sharing btw Harro, delisted stocks are often an issue with backtests going back a long period, will add your code to my library :)
 
Top