Interesting, thanks for sharing. The way I do this is have offsets like Rob has in pysystem trade, then use those in combination with dates for which prices exist (I use this to eliminate weekends and holidays) to generate a list of roll dates. Then using that, and the actual prices, I generate adjusted prices. This works really well, unless in situations where data is wrong (wrong is worse than missing), like is the case with Platinum right now.In my system I pre-generated roll dates (historical and future ~ 100 years total) simply using the rules described in the contract specs on CME web-site or other corresponding exchanges, like "every third Friday before the last Monday prior to the next Tuesday", I used an open-source library that knows all historical public holidays to adjust for them.
Out of curiosity, how long does this take to run a backtest?I'm using it exactly the same way as it would've been used in reality, so I'm pumping historical EOD prices as if they were real-time, and the system stitches them internally as in normally would
I store adjusted prices, and at the beginning of the backtest I precompute and cache some stats, like all moving averages, all breakouts, risk etc. Then backtest just feeds in the current caapital and current price. For 12 instruments and 20 years this takes about 25 min, on a modern CPU. Granted, it's in Python and I haven't bothered to optimize so it only runs on a single core.
, I used an open-source library that knows all historical public holidays to adjust for them.
