Hi there,
I am working on some custom moving average indicator and encountered an issue when setting up automatic warm-up. The script is saying that I am giving three arguments to the Update method, but I am only passing on two arguments, a date and a value. Please see below for the error description and the code:
During the algorithm initialization, the following exception has occurred: Update() takes 2 positional arguments but 3 were given
at Initialize
self.hyg_ief_ma.Update(hyg_ief_history.loc[self.hyg].index[i] in main.py: line 53
Update() takes 2 positional arguments but 3 were given
# region imports
from AlgorithmImports import *
from collections import *
# endregion
class CustomSimpleMovingAverage(PythonIndicator):
def __init__(self, name, period):
self.Name = name
self.WarmUpPeriod = period
self.Time = datetime.min
self.Value = 0
self.queue = deque(maxlen=period)
def Update(self, input: BaseData) -> bool:
self.queue.appendleft(input.Value)
count = len(self.queue)
self.Time = input.Time
self.Value = sum(self.queue) / count
return count == self.queue.maxlen
class UglyFluorescentOrangeParrot(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2021, 8, 2) # Set Start Date
self.SetCash(100000) # Set Strategy Cash
self.ma_dict = {}
self.ma_period = 100
# Add sector ETFs
self.sector_etfs = ['FDN','IBB','IEZ','IGV','IHE','IHF','IHI','ITA','ITB','IYJ','IYT','IYW','IYZ','KBE','KCE','KIE','PBJ','PBS','SMH','VNQ','XLB','XLP','XLU','XOP','XRT']
for x in self.sector_etfs:
self.AddEquity(x,Resolution.Daily)
self.Securities[x].FeeModel = ConstantFeeModel(0)
# Add asset class ETFs
self.asset_etfs = ['IWM','EFA','EEM','DBC','GLD','VNQ','TLT','SHY']
for x in self.asset_etfs:
self.AddEquity(x,Resolution.Daily)
self.Securities[x].FeeModel = ConstantFeeModel(0)
# Initialize ratio moving average indicators
self.spy_bnch_ma = CustomSimpleMovingAverage("SPY BNCH MA", 100)
self.hyg_ief_ma = CustomSimpleMovingAverage("HYG IEF MA", 100)
self.hyg = self.AddEquity('HYG',Resolution.Daily).Symbol
self.ief = self.AddEquity('IEF',Resolution.Daily).Symbol
hyg_ief_history = self.History([self.hyg, self.ief], 100, Resolution.Daily)
for i in range(len(hyg_ief_history.loc[self.hyg])):
self.Log(hyg_ief_history.loc[self.hyg].index[i])
self.Log(hyg_ief_history.loc[self.hyg]['close'][i]/hyg_ief_history.loc[self.ief]['close'][i])
self.hyg_ief_ma.Update(hyg_ief_history.loc[self.hyg].index[i], hyg_ief_history.loc[self.hyg]['close'][i]/hyg_ief_history.loc[self.ief]['close'][i])
def OnData(self, data: Slice):
Yuri Lopukhov
there is a self argument here, which is filled with instance of the class automatically. And input parameter is neither date nor value.
Try overriding this method in your indicator instead:
it will accept time as first argument and value as second.
Tarquinius Superbus
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!