Back

Problems to get options data using self.OptionChainProvider.GetOptionContractList

Hello, Im running a backtesting of a VIX SPY ETF algo that also buy options when VIX price is higher than a threshold. Im using the self.OptionChainProvider.GetOptionContractList function to filter my symbol and get the list of  contracts. Then I filtered this list using the self.InitialFilter function that I want, based on conditions related to the underlying price and the strike price and the expiration date.

However Im receiving the following error, at the moment the algo try to buy the contract option:

Backtest Handled Error: The security with symbol 'SPY 151219C00203000' is marked as non-tradable.

 

I attached the algo below, some help on this?

Thanks,

Nicolás

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 Nicolas.

Add options to the security universe in the method Initialize() instead of adding options in the method OnData() and loop through the option chain in OnData():

def OnData(self, slice):
optionchain = slice.OptionChains
for i in slice.OptionChains:
if i.Key != self.symbol: continue

# Return if holding option contracts
if self.Portfolio.Invested: return

# Buy OTM call option if the VIX is between 35 and 42
if self.Securities[self.vix].Price > 35 and self.Securities[self.vix].Price < 42:
option_contract = self.BuyCall(optionchain)
self.Buy(option_contract, 2)

I've attached a backtest where I've simplified your code to demonstrate one case on how to buy Out-Of-The-Money (OTM) call options using VIX as a trigger. The algorithm buys call options when the value of the VIX is between 35 and 42.

Check out the QuantConnect Options API for further information.

0


Hello Halldor, thanks for your response. I would work based on your example, but I have one doubt. My algo buy options when VIX is very large, but there times that the algo buy SPY ETF. So, when I add the conditions to buy SPY only under the Ondata(self,slice), the algo start to run in one minute mode. 

This is undesirable as the VIX data is daily.

Below I attached a backtest with this issue.

0


Hi Nicolas.

The data resolution will be minute when you add options to the security universe. However, the daily value of the VIX converts to minute basis, so you could still use your logic within that timeframe.

If you want higher resolution data, then use consolidators to combine smaller data points into larger bars. Check out this API Tutorial on Consolidating Data to Build Bars for more information.

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