Hello everyone.
I have a simple strategy using the Algorithm Framework, Universe to scan for symbols with average 30 days volume > 1M, 2$ < price < 500$, also sorting based on ROC values.
SPY is added to my universe, since it is the main part of the strategy.
Later on in the Alpha, I am using History to get SPY history data, to manually update my EMA indicator.
The strategy is based on a regime filter, if SPY closed > 50 dEMA the filter is off, and its ON when SPY closed < 50 dEMA.
Alpha will generate an Insight based on the regime filter i've described.
Running a backtest from 20/1/2021 or any other different date, will produce different results than expected.
Not sure if I can link to another trading platform to see their chart, but SPY is not below its 50 dEMA on 29/1/2021, as the close is 370.07 and 50 daily EMA is 369.90.
Something is very odd about my EMA values, they are completly off, not matching a straight forward QC algorithm that uses self.SetWarmUp(), nor TradingView's SPY chart.
And the wierdest thing is that when running from 25/1/2021 to 1/2/2021 the regime filter is OFF (spy > 50 dEMA) and 50 dEMA value is 369.89. (even if decreasing the lookup window from 500 to 490 to compensate for those 5 days difference to see if its the lookup request's fault)
(I am using 2 methods of defining EMA's and using history that produce the same result.)
I also believe that my Universe has the same issue so I'm not really getting symbols that have avg vol(30) > 1M.
Please help me understand what is going on.. I can't build upon my strategy any further with wrong indicator values..
Best,
Ido Elmaleh.
Ido Elmaliah
I just wanted to state again that the ONLY way I managed to get the exact indicator values is when using a strategy WITHOUT a Universe and Alpha, adding symbols in the Initialize step, using AddEquity(symbol), and then warming up any indicator using the algorithms built in warmup function SetWarmUp(period).
Vladimir
Ido Elmaliah,
The Exponential Moving Average (EMA) from Digital Signal Processing view is
an Infinite Impulse Response (IIR) filter.
The latter value of IIR filter substentialy depends on the initial value of the time series.
To reduce the dependence on the initial value, I would recommend increasing the size of the rolling
window of WarmUp to 5-6 times of the EMA period for it to mature
or use a Finite Impulse Response (FIR) filter - Simple Moving Average (SMA).
Ido Elmaliah
Yeah I agree with you, Vladimir.
But, even using a 1000 history lookup or using 1500 does not change the value output even
the slightest.
Ido Elmaliah
I have found that when changing the Universe to a Manual Universe or a Scheduled Universe will produce correct indicator results..
What is going on?
Is there something wrong with FundementalUniverseSelection???
Derek Melchin
Hi Ido,
The discrepancy in the indicator values is a result of a duplicate bar that appears at the end of the warm-up period and the first bar after warming up.
See the attached backtest 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.
Vladimir
Ido Elmaliah,
Same test as Derek's, but with increased WarmUp window size to 6x the EMA period as I mentioned above.
2019-11-09 00:00:00 : Starting values: 364.25088746233087 364.25088746233087
2020-01-14 00:00:00 : Ending values: 320.865568153777 320.865568153777
2020-01-15 00:00:00 : Ending values: 320.84723102264843 320.84723102264843
2020-01-16 00:00:00 : Ending values: 320.8580076304662 320.8580076304662
2020-01-17 00:00:00 : Ending values: 320.97311480950674 320.97311480950674
Vladimir
And here is the same without updating self.ema
2019-11-09 00:00:00 : Starting values: 0.0 364.25088746233087
2021-01-27 00:00:00 : Ending values: 367.57468561000223 367.57500423939223
2021-01-28 00:00:00 : Ending values: 367.79481267470806 367.79511880882785
2021-01-29 00:00:00 : Ending values: 368.1321696553077 368.1324637841679
2021-01-30 00:00:00 : Ending values: 368.1607940421584 368.1610766365535
2021-02-02 00:00:00 : Ending values: 368.4290760514855 368.42934756374746
Ido Elmaliah
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!