Hi, it was saying that I needed to warmup the algo even after I already warmed it up. The code is attached below.
# Trading based on CBOE vix-vxv ratio
from QuantConnect.Data.Custom.CBOE import *
class VirtualRedDogfish(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2010, 1, 1)
self.SetCash(100000)
self.AddEquity("TQQQ", Resolution.Minute).Symbol
self.AddEquity("TMF", Resolution.Minute).Symbol
self.AddEquity("UVXY", Resolution.Minute).Symbol
self.AddEquity("SPY", Resolution.Minute).Symbol
self.vix = 'CBOE/VIX'
self.vxv = 'CBOE/VXV'
self.AddData(QuandlVix, self.vix, Resolution.Daily)
self.AddData(Quandl, self.vxv, Resolution.Daily)
self.SetWarmUp(300, Resolution.Daily)
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.Daily)
self.Schedule.On(self.DateRules.EveryDay("SPY"), self.TimeRules.AfterMarketOpen("SPY", 1),
self.Trade)
def Trade(self):
if not (self.vix_sma.IsReady or self.vxv_sma.IsReady or self.ratio.IsReady):
return
if self.spySMA is None or not self.spySMA.IsReady:
return
if self.spySMA.Current.Value < self.Securities["SPY"].Price:
if self.ratio.Current.Value < .923:
self.SetHoldings("UVXY", .6)
self.SetHoldings("TMF", 0)
self.SetHoldings("TQQQ", 0)
self.SetHoldings("SPY", .4)
else:
self.SetHoldings("UVXY", 0)
self.SetHoldings("TMF", 0)
self.SetHoldings("TQQQ", .8)
self.SetHoldings("SPY", .2)
else:
if self.ratio.Current.Value < .923:
self.SetHoldings("UVXY", .6)
self.SetHoldings("TMF", .4)
self.SetHoldings("TQQQ", 0)
self.SetHoldings("SPY", 0)
else:
self.SetHoldings("UVXY", 0)
self.SetHoldings("TMF", .2)
self.SetHoldings("TQQQ", .4)
self.portfolio["SPY"].Invested = closevalue
self.stopMarketTicket = self.StopMarketOrder("SPY", closevalue, 0.05 * self.Securities["SPY"].Close)
class QuandlVix(PythonQuandl):
def __init__(self):
self.ValueColumnName = "Close"
Vladimir
Aditya Holla,
If you comment out the two lines you added to the algorithm you cloned from here, it works.
Vladimir
Aditya Holla
I don't really understand what you are trying to achieve in these lines
self.portfolio["SPY"].Invested = closevalue
self.stopMarketTicket = self.StopMarketOrder("SPY", closevalue, 0.05 * self.Securities["SPY"].Close)
If you are trying to set a trailing stop, adding this to Initialize
self.SetRiskManagement(TrailingStopRiskManagementModel(0.20))
can help you.
Aditya Holla
I don't really know what I was trying to achieve either. But I was wondering if this would be the only line of code that I would have to use in order to set a trailing stop? Is it possible that I can set new allocations when the trailing stop is hit and how would I go about doing that?
Thanks for your help in advance,
Aditya
Louis Szeto
Hi Aditya
If your trailing stop loss is based on percentage point, the pre-coded TrailingStopRiskManagementModel is off-the-shelf and sufficient to deal with that. However, if your trailing stop loss is base on ATR, you will have to set up the indicator, place a stop market order, and update the stop price manually every day.
It is possible to set up new allocations when the stop loss is hit as it will only send a signal to set the current holding of the equity to 0, but not tempering new ordering signals.
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.
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!