Hi Guys,
I use the VIXContango Dataset. The code is working:
class CalculatingSkyBlue123(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2012, 1, 1)
self.SetEndDate(2021, 7, 13)
self.SetCash(10000)
self.ratio = 0
contango = self.AddData(VIXCentralContango, "VX", Resolution.Daily)
long_asset = self.AddEquity("SPY", Resolution.Daily)
short_asset = self.AddEquity("SH", Resolution.Daily)
#hedge_asset = self.AddEquity("AGG", Resolution.Daily)
self.contango = contango.Symbol
self.long_asset = long_asset.Symbol
self.short_asset = short_asset.Symbol
#self.hedge_asset = hedge_asset.Symbol
def OnData(self, data):
self.ratio = 0
contangoData = ""
contangoData = data.Get(VIXCentralContango, self.contango)
self.ratio = contangoData.Contango_F2_Minus_F1 if contangoData else 0
But if I uncomment the third asset (hedge_asset) I get an error:
Runtime Error: KeyNotFoundException : 'VX.VIXCentralContango' wasn't found in the DataDictionary<VIXCentralContango> object, likely because there was no-data at this moment in time and it wasn't possible to fillforward historical data. Please check the data exists before accessing it with data.ContainsKey("VX.VIXCentralContango")
at QuantConnect.Data.Market.DataDictionary`1.get_Item(Symbol symbol) in /LeanCloud/CI.Builder/bin/Debug/src/QuantConnect/Lean/Common/Data/Market/DataDictionary.cs:line 227
at QuantConnect.Python.PythonSlice.Get(PyObject type, Symbol symbol) in /LeanCloud/CI.Builder/bin/Debug/src/QuantConnect/Lean/Common/Python/PythonSlice.cs:line 69
at OnData
contangoData = data.Get(VIXCentralContango in main.py: line 24
(Open Stacktrace)
I don't understand why I get an error regarding the "DataDictionary<VIXCentralContango> object" if I subscribe an additionally asset which has no relation to “VIXCentralContango”
Louis Szeto
Hi Gleb
Although they're not related and trading at the same time, there could be additional slices from out-of-ordinary trading hours received, for example paying dividends. So in this slice, there won't be VX data. We suggest checking if the data slice contains that.
Best
Louis Szeto
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.
Gleb Kintop
Hi Louis,
Your workaround is working really well. Thank you so much for your feedback!
Gleb Kintop
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!