Is there any explanation for when we can use indicators with long names (StandardDeviation) and where we should use indicators with short names (self.STD), and where we may use python native std().
Why StandardDeviation equal 0 all the time in my backtest?
Jared Broad
Yes it's covered here
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
Jared Broad,
Thanks for the quick response.
It really helped me understand what they are, but not when and where can we use them,
and why is the StandardDeviation always 0 in my backtest?
AK M
Vladimir,
Indicators initialized in that manner must be manually updated like so:
self.std.Update(self.Time, self.Securities[self.spy].Close)
Â
Vladimir
AK M,
Thanks for the tip.
Now the StandardDeviation changes over time, but its value from 1-1-2020 to 5-1-2020
differ significantly from the other two.
Does it use another formula?
Jared Broad
Interesting test! I wouldn't say "significantly" as the error is less than 0.5%, but it could be different formula or a missing data point. Can confirm by seeing the data the history call is returning. The streaming version is using a modified "sample-set" standard deviation vs I guess np is using the population version of the formula.Â
One way to make the NP version streaming is using a rolling window instead of a history request -- that way the data is still gathered "on the fly" but you can use the batch version of the formula in the calculations and it'll be reasonably cheap.
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
Jared Broad,
You are correct by default np is using the "population" version of the formula (ddof=0),
but it allows to set ddof=1 and get the "sample" version.
std = sqrt(mean(x)), where x = abs(a - a.mean())**2
The average squared deviation is typically calculated as
x.sum() / N, where N = len(x) --> "population" version.
If, however, ddof is specified,
The average squared deviation is calculated as Â
x.sum() / (N - ddof), where N = len(x), ddof=1 --> "sample" version.
STD is more likely "population" version.
What about long named StandardDeviation?
Derek Melchin
Hi Vladimir,
The discrepancy is a result of a duplicate bar that appears at the end of the warm-up period and the first bar after warming up.
Nevertheless, we have an open GitHub pull request to address the discrepancy in indicator values, because it can happen under other conditions (e.g. fill forwarded bars). Subscribe to our progress here.
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
Derek Melchin,
-> The discrepancy is a result of a duplicate bar that appears at the end of the warm-up period
and the first bar after warming up.
Does this affect other indicators using StandardDeviation such as BollingerBands?
Jared Broad
It impacted any algorithm using warm-up. A couple of fixes have been proposed then the STD and StandardDeviation (long and short) are identical. The only difference is then the NumPy vs lean-indicator methods of calculating the values.Â
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
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!