For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/

Adding datafeeds mid-simulation for OTC trading



  • I'm interested in running a simulation for an OTC options strategy, but I don't know ahead of time which days my strategy/indicator will decide to trade on, or which strikes/maturities it will want to trade.

    Rather than pre-creating a price datafeed every possible option that might be traded, is there a way to add datafeeds on-the-fly as the strategy decides to trade something?

    So the strategy would say 'buy this datafeed that doesn't exist yet', and I'd override the buy method to first create a price datafeed for the entire backtesting period using external market data if it doesn't exist yet, then register this with cerebro, then pass back to the parent buy method to trade it.


  • administrators

    @jackg101 said in Adding datafeeds mid-simulation for OTC trading:

    is there a way to add datafeeds on-the-fly as the strategy decides to trade something?

    No it doesn't. This is something which has been even discussed privately with option traders, but it's not something in the core of backtrader



  • How hard would it be for me to implement this?

    I assume the major difficulty is that introducing new price feeds after cerebro has initialized could potentially introduce new trade times that cerebro doesn't currently know about, which would put the various linebuffers out-of-sync?


  • administrators

    @jackg101 said in Adding datafeeds mid-simulation for OTC trading:

    I assume the major difficulty is that introducing new price feeds after cerebro has initialized could potentially introduce new trade times that cerebro doesn't

    The assumption is wrong. It is explained above. Each element in the system has a different notion of what data feeds it has available, notion which is created when the element is instantiated. That's how it is possible to make a moving average on top of a moving average.

    @jackg101 said in Adding datafeeds mid-simulation for OTC trading:

    How hard would it be for me to implement this?

    You'd be better off writing your own engine.