I'm trying to set up a survivorship bias free database for the stocks of the S&P500 index (using AmiQuote and Yahoo quotes). WikipediaWikipedia comprises a table with not only the present constituents but also with the changes since 1999. This can be imported into Excel and, using the procedure set out in "Import ASCII" Import ASCII, this can easily be put in the field “Delisting date” of the stock. That works like a charm!
However I'm stumbling over two problems:
- I think that the “Delisting date” is provided for the reason I’m using it for, i.e. to eliminate a survivor ship bias. However, there is no corresponding "First listing date" field and stocks will be backtested before they were part of the index. How can there be survivorship bias free database without such a field? Am I missing something?
I thought about just manually deleting the quotes before the date the stock was listed in the S&P 500. However then no indicator using quotes from before the listing day would work.
- I tried using the proposed code
exitLastBar = datetime() >= GetFnData("DelistingDate");(see Closing trades) for selling delisted stocks. However, this condition doesn’t work; “exitLastBar” is always true if the stock hasn’t been delisted ("DelistingDate" is empty, i.e. has the value zero, and “datetime()” is always larger). It’s easy to work around this problem. However, everything in the Amibroker environment is so perfectly thought through and it seems a bit odd that this code is proposed. I’m probably missing something.
Now my question: Has anybody found and is willing to share a solution to exclude stocks from backtesting before they were listed in the S&P 500?