Hi~
I am working on a very simple SMA strategy, which requires 'SPY' :
1)when 5 mins bar SMA5>SMA30 and bar.close > SMA5, long 100 on market price
2)when 5 mins bar SMA5<SMA30 and bar.close < SMA5, short 100 on market price
3)maximumDrawdownPercent 5% , liquidate
I wrote in QCAlgorithm first and in Framework then. But there are two differences between the results of them.
1.The order submitted times of Framework version are all 1 min later than that of QCAlgorithm version.I think the result of QC is right,it supposed to submit order at the (hours : multiples of 5 : 00) , but I couldn't figure out where I'm doing wrong on Framework version.
2. For Framework version , the trade results before 2021.04.26 07:16:00 are wrong(inconsistent) compare with the real case. QC version's results are right. I think it may related with data warming up.
So I try history data to warm up refer to the answer to this question (https://www.quantconnect.com/forum/discussion/9627/how-can-consolidators-be-interfaced-with-the-framework/p1). But raise error "ArgumentOutOfRangeException : Rolling window is empty". How could I warm up both indicator and bar.close? Should I add the rolling window on update method?
Then I set self.SetWarmUp(30) on main function Initialize method, but make no difference.
Feng Li
QCAlgorithm code is here.
Derek Melchin
Hi Feng,
To get both versions of the algorithm to make the same trades, we need to make the following changes to the Framework version:
#1 Replace
if not symbolData.consolidated:
with
if symbolData.consolidated:
#2 Remove
self.SetSecurityInitializer(lambda x: x.SetDataNormalizationMode(DataNormalizationMode.Raw))
#3 Replace
if symbolData.Fast.IsReady and symbolData.Slow.IsReady
with
if symbolData.Fast.IsReady and symbolData.Slow.IsReady and symbolData.five_minutes_close.IsReady
#4 Warm up the indicators with
hist = algorithm.History(self.Symbol, 30, Resolution.Minute).loc[self.Symbol] if not hist.empty: for idx, row in hist.iterrows(): tradebar = TradeBar(idx, self.Symbol, row.open, row.high, row.low, row.close, row.volume) self.consolidator.Update(tradebar)
We also need to make the following changes to the Classic Algorithm version:
#1 Replace
self.quantity > 0
with
self.quantity >= 0
#2 Add
if not (self.sma_5min_5.IsReady and self.sma_5min_30.IsReady): return
above the line that reads
self.sma_5min_window.Add(self.sma_5min_5.Current.Value)
#3 Reduce the RollingWindow length of `sma_5min_window` and `sma_30min_window`
self.sma_5min_window = RollingWindow[float](1) self.sma_30min_window = RollingWindow[float](1)
See the attached Framework version for reference.
Best,
Derek Melchin
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.
Feng Li
Hi Derek,
Thanks for your detailed answer~ There is one point I want to get deep understanding, so I can use it more flexible in future.
For #4 Warm up the indicators with below code. You use history data to create bar and then update consolidator with bar, is there any detailed decumentation or Demonstration Algorithms for this knowledge ? I couldn't find it in ALGORITHM REFERENCE and ALGORITHM FRAMEWORK, maybe I didn't read ducumentation so carefully that I overlooked them :( .
hist = algorithm.History(self.Symbol, 30, Resolution.Minute).loc[self.Symbol] if not hist.empty: for idx, row in hist.iterrows(): tradebar = TradeBar(idx, self.Symbol, row.open, row.high, row.low, row.close, row.volume) self.consolidator.Update(tradebar)
Best,
Feng Li
Derek Melchin
Hi Feng,
This technique is not currently documented. We are in the process of updating our documentation and will be sure to include a demonstration of manually updating consolidators in the new version. Thanks for the feedback.
Best,
Derek Melchin
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.
Feng Li
Hi Derek,
I am looking forward to it. Thanks for your reply~
Best Wishes,
Feng Li
Feng Li
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!