It has come up a few times here that the backtester does not automatically manage securities that expire, within the dates of the backtest. Recent experience in dealing with larger universes of securities and expansion of the tradeable universe suggests that this issue will become more prevalent.
The problem is that if a position is held in a security beyond its expiration date, the position cannot be closed (and its value in the portfolio becomes increasingly murky). There are some work-arounds, but it seems that an option should be available within the backtester to manage such securities. Kinda messy (which is probably why there is no built-in backtester code):
- Do nothing (user will manage via custom code).
- Exclude all securities that will expire within backtest
dates (look-ahead bias, right?). - Automatically close positions upon expiration (biased?).
- Automatically close positions N minutes/days prior to expiration (potentially biased?).
- More complicated logic, based on price, volume, etc. and expiration date, in an attempt to match exchange rules for dropping securities.
"Automatically close" means override the backtester, use the last known price, and close out, as if there had been a trade event (i.e. force an order, even though the volume is zero).
Also, shouldn't there be a warning at the end of a backtest, "Backtest may be invalid, due to expired securities." It would also be handy to add a field that flags securities within the portfolio that have expired (and have that field available in the Quantopian research platform, via get_backtest()).
Is there a standard way to handle expirations in the world of backtesting?
When trading with real money at IB, and a security expires that is held in a Q portfolio, what happens?
Is this on the Q to-do list? If so, what is the priority? When might it be addressed (days/weeks/months/years/never)?