Setting Custom Market Order Fill Model for Options

I am trying to do some options backtesting.  I am finding that the MarketOrder fills for the options is very erratic.  Most likely it comes down to the low volume trading that occurs on the options.  Anyways, something I ususally do is just assume to lose the spread on every trade execution.  For example, when selling an option, you always assume you sell on the bid, and buying you always assume that you buy on the ask.  At QuantConnect we have bid/ask data so that seems possible, although I can't quite figure out how I would do the code.  From the docs we have this simple example:

# Set the fill models in initialize:

# Custom fill model implementation stub
class PartialFillModel(ImmediateFillModel):
def MarketFill(self, asset, order):
# Override order event handler and return partial order fills

So how would I create a default fill model for all options to say that MarketOrders are filled in the way I described above ( selling on bids and buying on asks ) ?  The documentation doesn't really explain what we need to return from this function.  Would something like this work?

# Custom fill model implementation stub
class MyCustomFillModel(ImmediateFillModel):
def MarketFill(self, asset, order):
if order.isSell:
order.fillPrice = asset.BidPrice
order.fillPrice = asset.AskPrice
return order

I know that attributes of the order object are wrong but I can't find any documentation explaining the order object and which attributes we are supposed to override in the fill model.  Please help.



Update Backtest

Update Backtest


The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


This discussion is closed