Forcing the price that backtrader uses for trades
I would like to write a strategy that trades options using only the underlying for its price signals.
Rather than giving backtrader a data feed for every option strike and expiration over my time period I figured it would be easier to write a strategy that uses the underlying, fetches the option I want to trade on a buy/sell signal, and force the broker to fill a trade at that option's price. I know this will horribly miscalculate portfolio value any time I'm in a position but I'm okay with that for now.
So: can I force the broker to fill an order at a price I define? I notice that the buy/sell functions have a
priceparameter but the docs indicate that's for setting stop/limit order execution prices. From poking around in the code it seems like
exectype = Order.Historicalmight be what I want, but I figured I should check first. Is this doable without too much pain?
Alternatively: can I build my own price feed every tick in strategy
next()and have the broker's fill and portfolio value calculators use that data line instead? Thanks!
@floomi orders are issued for certain data feed. you can easily get signals on one data feed and issue buy/sell orders on another. data feeds are added to
cerebrobefore the strategy is backtested, therefore you can not create a data feed inside the strategy.