Back

Option examples from tutorials fail

Hi,

I've just noticed that all options algos from tutorials that use OptionChainProvider fail to enter options positions with this error in the console:

Backtest Handled Error: IBM 110122C00120000: asset price is $0. If using custom data make sure you've set the 'Value' property.

I tried at least 3 algos: Iron Condor, Protective Collar and Bull Call spread. Just cloning the algo and run it produces above error and no option trades.

Any idea what could be the reason?

Update Backtest








Hi Ed,

There are two methods for options trading in LEAN. One is SetFilter(). With this method, the data of option contracts meet the filter condition will be automatically subscribed with SetFilter(). Another method is OptionChainProvider. We select contracts manually by using "self.OptionChainProvider.GetOptionContractList()" and it just returns a list of contract symbol. Then we should use self.AddOptionContract(symbol) to subscribe the data for symbol being selected. If placing orders after self.AddOptionContract(symbol) instantly, that contract was just being subscribed the price is still zero. That's the error you see in the Log. To correct this algorithm, you should wait until next time step to trade the contract which was added in the last time step. Please see the attached algorithm

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 Jing,

Thank you for the explanations!

However, when I cloned your algo and run it I've got exactly the same error: 

Backtest Handled Error: GOOG 170428C00857500: asset price is $0. If using custom data make sure you've set the 'Value' property.

Looking at your code I don't see how your suggestion "wait until next time step to trade the contract which was added in the last time step" is coded. I still see that the option contracts are traded right after they're added:

        self.AddOptionContract(self.otm_call, Resolution.Minute)
        self.AddOptionContract(self.otm_put, Resolution.Minute)
        
        self.Sell(self.otm_call, 1) # sell the OTM call 
        self.Buy(self.otm_put, 1) # buy the OTM put

Am I missing something?

0

This error happens the first time I add the contract and trade it. Now if you check the trade, options are invested because of these statements

option_invested = [x.Key for x in self.Portfolio if x.Value.Invested and x.Value.Type==SecurityType.Option]
if len(option_invested) == 0:
self.TradeOptions(slice)
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 Jing,

The error happens 3 times when I run your code. Here is the console log:

3 | 18:01:37: Build Request Successful for Project ID: 1428845 CompileID: af61fa775252f68962672007b0384c50-1ea36b288afbac619605bdc4147fb918 Lean Version: 2.4.0.0.3808

4 | 18:01:40:Backtesting Project ID: 1428845

5 | 18:01:44:Successfully sent backtest request for 'Retrospective Light Brown Armadillo', (Compile Id: af61fa775252f68962672007b0384c50-1ea36b288afbac619605bdc4147fb918)

6 | 18:01:57:Algorithm-Id: 58c0ce7e53cc96d5993bc1c598ef8d91 successfully sent to cloud.

7 | 18:01:58:Launching analysis for 58c0ce7e53cc96d5993bc1c598ef8d91 with LEAN Engine v2.4.0.0.3808

8 | 18:01:58:Warning: The GOOG equity security was set the raw price normalization mode to work with options.

9 | 18:01:58:Backtest Handled Error: GOOG 170428C00857500: asset price is $0. If using custom data make sure you've set the 'Value' property.

10 | 18:01:58:Your algorithm messaging has been rate limited to prevent browser flooding.

11 | 18:02:00:Backtest deployed in 16.412 seconds

12 | 18:02:05:Backtest Handled Error: GOOG 170526C00927500: asset price is $0. If using custom data make sure you've set the 'Value' property.

13 | 18:02:05:Your algorithm messaging has been rate limited to prevent browser flooding.

14 | 18:02:06:Backtest Handled Error: GOOG 170623C00995000: asset price is $0. If using custom data make sure you've set the 'Value' property.

15 | 18:02:07:Algorithm Id:(58c0ce7e53cc96d5993bc1c598ef8d91) completed in 9.07 seconds at 16k data points per second. Processing total of 143,891 data points.

Any ideas why?

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