I am trying to annualize standarddeviation and simplemovingaverage in class SymbolData. But sofar I get errors like 'unsupported operand type(s) for *: 'float' and 'StandardDeviation'' and 'TypeError : unsupported operand type(s) for +: 'int' and 'SimpleMovingAverage'' Below is my code within class SymbolData(object): with commented out the part that is not working (I tried this part also via OnRoc_stddevUpDated and OnRoc_smaUpdated functions, but that does not seem to work either).
self.roc = algorithm.ROC(symbol, 1, Resolution.Daily)
self.roc_values = []
self.roc_stddev = StandardDeviation(765)
self.roc_sma = SimpleMovingAverage(765)
self.roc.Updated += self.OnRocUpdated
"""
self.roc_stddev_an = 100 * math.sqrt(252) * self.roc_stddev #annualize
self.roc_sma_an = 100 * ((1+self.roc_sma) ** 252 - 1) #annualize
self.sharpe = self.roc_stddev / self.roc_sma
"""
In OnData it is working fine like below, but I want to have it in SymbolData for using it in universe selection.
self.roc_stddev_an = 100 * math.sqrt(252) * SymbolData.roc_stddev.Current.Value #annualize
self.roc_sma_an = 100 * ((1+SymbolData.roc_sma.Current.Value) ** 252 - 1) #annualize
Can someone please give me a direction how this can be done? Thanks!!
Louis Szeto
Hi Abco
To access the current value of an indicator, we have to use .Current.Value attribute but not directly calling the indicator object itself. For example,
Then the operator + can be applied to pre- and post-fix float.
We would also recommend you to have a look at the Indicator Extension function.
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.
Abco Janssens
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!