I have an options strategy that generates signals purely based on underlying. When the signal is generated, it picks close strike of puts/calls in the close expiration and executes trades against those options.
The only way I could simulate it in Backtrader so far is to add all possibly needed calls/puts/expirations as separate data feeds and then based on the signals, search appropriate feed in the
self.datasbased on the
_namepattern. It kinda works but with the amount of data - it takes really long to run because I add so many feeds to cerebro. Those options feeds are purely for orders execution - no indicators or analysis is done on them.
For a week, I may get 20-40 option feeds for a volatile underlying. I run it for few weeks and it takes quite long and for couple years - it's going to be eternity if it runs at all. That's just for a single symbol.
Also, for all options feeds, I had to add a first dummy bar with the start timestamp of the underlying, otherwise, the
next()is only called when all feeds had some data (and I feed/need only two weeks before expiration).
Anyway, it's really clunky. I think there is probably a way to extend Backtrader to accommodate such requirements and I'm looking for recommendations.
Thanks for reading this long questions. :)
run-out last edited by
@alexgorbachev Options is not a use case for Backtrader. You should consider alternatives.
@alexgorbachev I've been sketching out a related idea where certain underlyers meeting specific criteria would drive the selection of options to trade. My plan (although not implemented yet), was to just create a search function, completely separate from BT, where I could give it an underlyer symbol, price and date and it would return the near-term part of the chain with current option prices. So instead of loading all possible option data feeds into the strategy, I'd just lookup the data as needed on demand.
If I can fit it all in memory, my plan is to just read in a big Pandas DataFrame and select out the data I need. If that is too large, then I'll just load it from files or put it in SQLite. I have no idea how this would compare performance-wise with what you are doing, though.
run-out last edited by
@davidavr You can definitely load data in that way. The performance of course will depend on many factors. Let us know how goes.