Hello! I need help with this!
I'm trying to compute the standard deviation of daily (simple) returns of the last 90 days using the in-built STD indicator and a custom indicator `PriceReturn`. I keep getting this error code :
[ERROR] FATAL UNHANDLED EXCEPTION:Engine.Run(): During the algorithm initialization, the following exception has occurred: Trying to dynamically access a method that does not exist throws a TypeError exception. To prevent the exception, ensure each parameter type matches those required by the 'int'>) method. Please checkout the API documentation., at Initialize, self.dev = IndicatorExtensions.Of(self.STD(90) in main.py: line 8, No method matches given arguments for STD: (),ApiConnection.TryRequest(backtest/status/update): Error: The operation has timed out.
Here is the code of the script:
class ThisCode(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2007, 7, 24)
self.SetEndDate(2012, 2, 20)
self.SetCash(100000)
self.symbol = self.AddForex("GBPUSD", Resolution.Hour, Market.Oanda).Symbol
self.returns = PriceReturn("GBPUSD", Resolution.Daily)
self.dev = IndicatorExtensions.Of(self.STD(90), self.returns)
self.RegisterIndicator("GBPUSD", self.returns, Resolution.Daily)
self.SetWarmUp(90, Resolution.Daily)
def OnData(self, data):
pass
# Create a Custom Indicator that calculates the simple returns of daily close prices
class PriceReturn(PythonIndicator):
def __init__(self, symbol, resolution):
super().__init__()
self.returns = 0
self.Symbol = symbol
self.Resolution = resolution
self.Name = f"PriceReturn_{symbol}"
def Update(self, input):
self.price = input.Close
self.returns = (self.price - self.price.Shift(1)) / self.price.Shift(1)
self.returns.Name = self.Name
Surely, I'm missing something. Kindly help, thanks!
Non Compete
Hi Olawale I think you are missing the symbol arg to STD
Â
Â
Olawale
The STD indicator is meant to calculate the standard deviation of the simple returns not of the prices, so why do I need a symbol arg?
Non Compete
The above definition is the only one i see in the code, but maybe I missed something. It internally used the StandardDeviation class . You might be able to do something likeÂ
but i'm not sure if that will work, or how to define SimpleReturns. I'm getting that from this which uses ROC:
https://github.com/QuantConnect/Lean/blob/master/Algorithm.CSharp/PortfolioOptimizationNumericsAlgorithm.cs
Non Compete
Maybe this thread can help, just saw it:Â
https://www.quantconnect.com/forum/discussion/8474/calculate-standard-deviation-of-an-indicator/p1/comment-23520
Louis Szeto
Hi Olawale & Non Compete
Thank you Non Compete, your solution is correct. Note that STD is an automatic indicator helper method, so it is not intended to use in this way as it will update by every data slice of the referenced symbol. Normally, for standard deviation of daily return, we will use the below implementation:
Best
Louis
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.
Olawale
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!