Back

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:
self.Securities["IBM"].SetFillModel(PartialFillModel())

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

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
else:
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.

 

Thanks.

Update Backtest








0

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.


Hi Tim

Did you ever get an answer to this? I'm finding that the bid ask spread returned in the data is WAAAY wider than reality. This causes some unusual behavior. In my case I ran a strategy that sells ATM calls/put over 1 year on SPY. . That loses about 5.2%. So you would assume that if you went long the same strikes for the same period, it should be profitable give or take a little due to fees and slippage. Nope. it loses about the same percentage. When looking at a few random data points, I found that the bid ask spreads on SPY averaged about 10%, whereas in reality these average around 2 to 3 percent. Obviously this complicates any trading strategy trying to eke out a profit. 

I thought a work around would be to use the worst price (ask or bid and add 3pct). So I'm curious how you worked this out. 

0

Update Backtest





0

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.


Loading...

This discussion is closed