Hi, I was wondering if someone could help me fix and understand why there is no data and why my algo is messed up. The backtest isnt working, so i have attached the code below.
class VirtualRedDogfish(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2010, 1, 1)
self.SetCash(100000)
self.AddEquity("TQQQ", Resolution.Daily)
self.AddEquity("TMF", Resolution.Daily)
self.AddEquity("UVXY", Resolution.Daily)
self.AddEquity("SPY", Resolution.Hour)
self.vix = 'CBOE/VIX'
self.vxv = 'CBOE/VXV'
self.AddData(QuandlVix, self.vix, Resolution.Daily)
self.AddData(Quandl, self.vxv, Resolution.Daily)
self.SetWarmUp(200)
self.vix_sma = self.SMA(self.vix, 1, Resolution.Daily)
self.vxv_sma = self.SMA(self.vxv, 1, Resolution.Daily)
self.ratio = IndicatorExtensions.Over(self.vxv_sma, self.vix_sma)
self.spySMA = self.SMA("SPY", 100, Resolution.Hour)
def OnData(self, data):
if not (self.vix_sma.IsReady and self.vxv_sma.IsReady and self.ratio.IsReady):
return
if self.spySMA.IsReady:
self.Debug("Ready!")
if self.spySMA is None or not self.spySMA.IsReady:
return
if self.spySMA.Current.Value < data["SPY"].Close:
if self.ratio.Current.Value < .923:
self.SetHoldings("UVXY", .6)
self.Liquidate("TMF")
self.Liquidate("TQQQ")
self.SetHoldings("SPY", .4)
else:
self.Liquidate("TQQQ")
self.Liquidate("TMF")
self.SetHoldings("TQQQ", .8)
self.SetHoldings("SPY", .2)
else:
if self.ratio.Current.Value < .923:
self.SetHoldings("UVXY", .6)
self.SetHoldings("TMF", .4)
self.Liquidate("TQQQ")
self.SetHoldings("SPY", 0)
else:
self.SetHoldings("TMF", .2)
self.SetHoldings("TQQQ", .4)
self.SetHoldings("SPY", .4)
self.Liquidate("UVXY")
class QuandlVix(PythonQuandl):
def __init__(self):
self.ValueColumnName = "Close"
Vladimir
Aditya Holla
Try this with some changes and bug fixes.
Varad Kabade
Hi Aditya & Vladimir,
Thank you, Vladimir, for your response. Moving forward, we recommend that the resolution of the indicator should be equal to or lower than the resolution of your security.
Best,
Varad Kabade
Vladimir
Varad kabade,
Could you please explain in detail what is behind your recommendation?
Varad Kabade
Hi Vladimir,
Suppose we have security that is subscribed to daily resolution in the algorithm, and we create an indicator on the same with Minute or Hour resolution. We get an ArgumentException because when we initialize a indicator with the shortcut method (self.SMA()), the algorithm creates a consolidator for the assigned resolution using the subscribed security data and the consolidators require higher resolution data to produce lower-resolution data; thus, it is not possible to update the indicators.
Best,
Varad Kabade
Vladimir
Varad kabade,
In this case, CBOE/VXV Quandl data is EOD data.
We cannot get a "lower" resolution and consolidate it.
Why can't we trade them at 9:31 a.m. using a "lower resolution" "minute" for tradable instruments?
By the way, the meaning of "resolution" in optics, where it is mainly used, is the opposite.
Varad Kabade
Hi Vladimir,
The above recommendation was regarding Aditya's algo where he was using indicator with resolution of Hour when the resolution of security was Daily
If we place an order at 9:31 with daily data, the order will be "filled at stale prices," which is a sign that the algorithm will have different behavior in live mode. On the other hand, CBOE/VXV is not tradable, so it's fine to use it as a daily indicator.
Best,
Varad Kabade
Vladimir
Varad kabade,
Is there any problem in my code?
How can I apply your recommendation there?
Varad Kabade
Hi Vladimir,
The algo attached by you incorporates the best practices. The recommendation does not apply to it because all the indicators are updated daily, and all the securities have data subscriptions with higher frequency.
Best,
Varad
Aditya Holla
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!