Hello!
I computed Relative Strength Index and Minimum Volume for Coarse Selection Function by defining a SymbolData inheritance:
class SymbolData(object):
def __init__(self, symbol, Volume, DollarVolume):
self.Symbol = Symbol
self.Volume = Volume
self.DollarVolume = DollarVolume
self.RS_Index = self.RelativeStrengthIndex(3)
self.MinVolume = self.Minimum(50)
self.MinDollarVolume = self.Minimum(50)
self.Volume_Tradable = False
def update(self, time, value, Volume, DollarVolume):
if self.RS_Index.Update(time, value) and self.MinVolume.Update(time, Volume) and self.MinDollarVolume.Update(time, DollarVolume):
Min_Volume_Share = self.MinVolume.Current.Value
Min_Volume_Dollar = self.MinDollarVolume.Current.Value
self.Volume_Tradable = Min_Volume_Share > 500000 and Min_Volume_Dollar > 2500000
To use my computation of Relative Strength Index and Minimum Volume in Coarse Selection Function, I wrote the ff code:
def CoarseSelectionFunction(self, coarse):
Filtered_Universe = [x for x in coarse if x.Volume_Tradable and x.Price > self.value_MinStockPrice]
#Then, sort the stocks according to the highest RSI:
Filtered_Universe.sort(key=lambda x: x.RS_Index, reverse=True)
return [i.Symbol for i in Filtered_Universe]
However, I got the following error:
Runtime Error: AttributeError : 'CoarseFundamental' object has no attribute 'Volume_Tradable'
at CoarseSelectionFunction in main.py:line 85
at <listcomp> in main.py:line 85
AttributeError : 'CoarseFundamental' object has no attribute 'Volume_Tradable' (Open Stacktrace)
So, can I fix this by inheriting the class CoarseFundamental for SymbolData?
Thanks a lot!