Hi All,
I'm having trouble updating the bolinger band indicator I'm using is this universe selection mode. I've following along with the EMA Cross Model, but it doesn't seem to work when substituting indicators with multiple values, such as the bolinger bands and keltner channels. The error I'm given is:
ArgumentException : Object of type 'System.RuntimeType' cannot be converted to type 'QuantConnect.Data.IBaseData'. at System.RuntimeType.TryChangeType(Object value, Binder binder, CultureInfo culture, Boolean needsSpecialCast) at System.Reflection.MethodBase.CheckArguments(Object[] parameters, Binder binder, BindingFlags invokeAttr, CultureInfo culture, Signature sig) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at Python.Runtime.MethodBinder.Invoke(IntPtr inst, IntPtr args, IntPtr kw, MethodBase info, MethodInfo[] methodinfo) at Update return self.BollingerBands.Update(time in Universe.py: line 77
Can anyone demonstrate how to update bolinger bands in universe selection? Code is as follows:
from Selection.FundamentalUniverseSelectionModel import FundamentalUniverseSelectionModel
class KeltnerBollingerSelectionModel(FundamentalUniverseSelectionModel):
'''Implements a universe of stocks based on the bollinger bands being completed encased
by the keltner channels'''
def __init__(self, period = 20, bollingerKFactor = 2, keltnerKFactor = 1.5, movingAverageType = MovingAverageType.Simple, universeSettings = None):
'''Intializes a new instance of the KeltnerBollingerSelectionModel class
Args:
period: Keltner and Bollinger period
bollingerKFactor: bollinger standard deviation
keltnerKFactor: keltner ATR multiplier
universeSettings: The settings used when adding symbols to the algorithm, specify null to use algorithm.UniverseSettings'''
super().__init__(False, universeSettings)
self.period = period
self.bollingerKFactor = bollingerKFactor
self.keltnerKFactor = keltnerKFactor
self.movingAverageType = movingAverageType
#holds the coarse fundamental indicators by symbol
self.data = {}
def SelectCoarse(self, algorithm, coarse):
'''Defines the coarse fundamental selection function.
Args:
algorithm: The algorithm instance
coarse: The coarse fundamental data used to perform filtering</param>
Returns:
An enumerable of symbols passing the filter'''
filtered = []
for cf in coarse:
if cf.Symbol not in self.data:
self.data[cf.Symbol] = self.SelectionData(cf.Symbol, self.period, self.bollingerKFactor, self.keltnerKFactor, self.movingAverageType)
#grab the selection data instance for this symbol
data = self.data.get(cf.Symbol)
if data.Update(cf.Endtime, cf.Value) and data.IsIn:
filtered.append(data)
return [x.Symbol for x in filtered]
class SelectionData:
def __init__(self, symbol, period, bollingerKFactor, keltnerKFactor, movingAverageType):
self.Symbol = symbol
self.BollingerBands = BollingerBands(period, bollingerKFactor, movingAverageType)
self.KeltnerChannels = KeltnerChannels(period, keltnerKFactor, movingAverageType)
@property
def BollingerUpper(self):
return float(self.BollingerBands.UpperBand.Current.Value)
@property
def BollingerLower(self):
return float(self.BollingerBands.LowerBand.Current.Value)
@property
def KeltnerUpper(self):
return float(self.KeltnerChannels.UpperBand.Current.Value)
@property
def KeltnerLower(self):
return float(self.KeltnerChannels.LowerBand.Current.Value)
#computes when the bollinger bands are inside the keltner channels, returning true
@property
def IsIn(self):
return (self.BollingerUpper < KeltnerUpper) and (BollingerLower > KeltnerLower)
#updates the keltner channels and bollinger bands, returning true when they're both ready
def Update(self, time, value):
return self.BollingerBands.Update(time, value) and self.KeltnerChannels.Update(TradeBar)
Louis Szeto
Hi Nicholas
The problem comes from the last line self.KeltnerChannels.Update(TradeBar) when the method has not received any argument as TradeBar. To solve it, please make sure the input argument is a Trade bar:
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.
Nicholas Fitzgerald
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!