Hi,
Occasionally, we get the following error in the algorithm even though we're not using any custom data: "asset price is $0. If using custom data make sure you've set the 'Value' property". Any thoughts or ideas of where to start exploring the issue?
Thanks.
Jing Wu
Could you attach the algorithm which has such error?
Jared Broad
It is normally when you place a trade before there is data for the asset. This generally open happens at the very start of the algorithm.
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.
Quantithmar
Problem is that the assets are loaded dynamically every day. I guess I can introduce a delay until the price is available.
Nicolas Ferrari
Hello Quantithmar, how did you solve this issue?
Thanks,
Nicolas
Andrew Chan
also running into this issue when using LEAN with custom data. Has anybody made any progress on this? or is there a way to delay/pause/delay an order until the data is loaded?
Jared Broad
If you dont set a value for the custom data it'll always be 0. I think you're referring to a different thing?
The OP was saying that when adding securities dynamically there can be a few minutes at the start before they have data. You need to wait for the first tick to have the price set accurately.
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.
Andrew Chan
Thanks for the reply Jared! I'm dynamically loading options. Trying to migrate to OptionChainProvider to speed up things but it seems that the data doesn't load right away. Is there a way to 'wait'? I tried to force it so that the data is loaded and doesn't have a 0 value (setting bidPrice of Option to 0) before placing a MarketOrder, but it doesn't work. Â
any suggestions would be great.
code snippet below:
Â
def OptionsFilter(self,slice):
    self.underlyingPrice = self.Securities[self.equity_symbol].Price
    contracts = self.OptionChainProvider.GetOptionContractList(self.equity_symbol, slice.Time) Â
     puts = [i for i in contracts if i.ID.OptionRight == OptionRight.Put andÂ
                       i.ID.StrikePrice - self.underlyingPrice >= 0 andÂ
                       30 < (i.ID.Date - slice.Time).days < 60]
     return puts[0]
Â
def OnData(self, slice):
   contract=self.OptionsFilter(slice)
   if contract:
        for chain in slice.OptionChains.Values:
          for c in chain:
            if c.Symbol==atm_put:
              bid=c.BidPrice
              if bid!=0:
                atm_strike = float(contract.ID.StrikePrice)
                amount = -int((float(self.Portfolio.TotalPortfolioValue/atm_strike)/self.multiplier))
                self.MarketOrder(contractt,amount)
   Â
Alexandre Catarino
Hi Andrew Chan ,
In the code snippet, there is no AddOptionContract call.
Could you please share a backtest that reproduces the issue?
A common mistake is adding a contract with AddOptionContract method and placing an order at the same time iteration. In other words, if the algorithm adds a contract in OnData, it will need to until the next time OnData is triggered to place an order.
You can set a security initializer that will fetch the last know price and warm up the security:
self.SetSecurityInitializer(lambda x: x.SetMarketPrice(self.GetLastKnownPrice(x)))
Please note that it can get the closing price of the previous trading session depending on the time AddOptionContract was called and the liquidity of the contract.
P.S.: Since GetLastKnowPrice makes a history request, it may slow the algorithm down.
Brad Hearne
I'm having a similar issue. However, I'm trying to run/call the options functions outside of OnData. I tried to use theÂ
self.SetSecurityInitializer(lambda x: x.SetMarketPrice(self.GetLastKnownPrice(x)))
but it said that it couldn't be used beyond the initialize portion of the Algorithm and threw errors when I moved it there too. Is this able to be modified to be able to use it in a spot application?
Alexandre Catarino
Hi Brad Hearne ,
SetSecurityInitializer must be called in Initialize.
Could you please share the code that we can use to reproduce the errors when you move it there?
Andrew Chan
Alexandre thanks for replying, I found that using AddOptionContract skips to the next step and can't wait. whereas AddOption pre-loads so it doesn't skip. would love to know if there is a way to ressolve this.Â
Â
for contract in contractList:
                    if contract not in self.contractsAdded:
                        self.contractsAdded.add(contract)
                        self.AddOptionContract(contract, Resolution.Minute)
                        self.Securities[contract].SetFillModel(CustomFillMarketMid(self))
Â
#### want it to wait here - but it doesn't wait, it goes to the next step                   for chain in slice.OptionChains.Values:
                    for c in chain:
                        if c.Symbol in contractList:
                            bid=c.BidPrice
                            if bid!=0:
                                self.MarketOrder(c.Symbol,amount)
                                self.monthStartEOD=False
                            else:
                                self.Log(str(self.Time.date())+"bid is 0:"+str(bid))
Alexandre Catarino
Hi Andrew Chan ,
The newly added option contract will only be added to the Slice.OptionChains the next time iteration. However, if the algorithm implements
self.SetSecurityInitializer(lambda x: x.SetMarketPrice(self.GetLastKnownPrice(x)))
all the price information (not the Greeks and Implied Volatility) will be present. Instead of iterate the OptionChains, why not iterate contractList instead?
Andrew Chan
great thanks this solved my issue of Asset price is $0.
Andrew Chan
the problem with iterating through the contractList is that no prices are available yet, so sending a MarketOrder gives the AssetPrice is 0 error. So I iterated through the OptionChains to see when the data would be avaible so sending a MarketOrder won't give that error. However this isn't ideal, as it will only be able to send a MarketOrder on the next iteration and not the current
Quantithmar
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.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!