I am recieving the follwing error Runtime Error: In Scheduled Event 'SPY: MonthStart: SPY: 0 min after MarketOpen', AttributeError : 'EquityHolding' object has no attribute 'historicalPERatio' AttributeError : 'EquityHolding' object has no attribute 'historicalPERatio' (Open Stacktrace)I cannnot seem to figure out why I am getting the error. The following is some of my code#All appropriate variables are imported before this line
# Demonstration of using coarse and fine universe selection together to filter down a smaller universe of stocks.
class FrameworkAlgorithm(QCAlgorithm):

def Initialize(self):
'''Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.'''
self.SetStartDate(2014,1,1) #Set Start Date
self.SetEndDate(2015,1,1) #Set End Date
self.SetCash(50000) #Set Strategy Cash
self.UniverseSettings.Resolution = Resolution.Daily

self.AddUniverse(self.CoarseSelectionFunction, self.FineSelectionFunction)
self.AddEquity("SPY", Resolution.Daily)
self.SetBenchmark("SPY")

self.__numberOfSymbols = 100
self.__numberOfSymbolsFine = 30

self._changes = None

self.Schedule.On(self.DateRules.MonthStart("SPY"), self.TimeRules.AfterMarketOpen("SPY"), Action(self.Rebalancing))

self.historicalPERatio = {}
self.Y = {}

self.rollingWindowSize = 20;

self.averages = { };

def CoarseSelectionFunction(self, coarse):
x = list(coarse)
CoarseWithFundamental = [x for x in coarse if (x.HasFundamentalData) and (float(x.Price) > 5)]
#in between above and Return statement is the rest of the function
return top

def FineSelectionFunction(self, fine):


self.r = [x for x in fine if x.ValuationRatios.PERatio]

for x in self.r:
if x.Symbol not in self.historicalPERatio.keys():
# Set up rolling window for new ticker
self.historicalPERatio[x.Symbol] = RollingWindow[Decimal](self.rollingWindowSize)
self.historicalPERatio[x.Symbol].Add(x.ValuationRatios.PERatio) #your job is to find the decimal current version for all the following variables
#self.prices_y[x.Symbol] = list(history.loc[x.Value]['close'])[1:]

self.r = [x for x in fine if PredictionEngine(x.historicalPERatio, x.Y ).predictionScore() > float(x.Price) or PredictionEngine(x.historicalPERatio , x.Y ).predictionScore() < float(x.Price)]
r = self.r
topFine = sorted(self.r, key=lambda x: x.ValuationRatios.PERatio, reverse = False)
self.topFine = [x.Symbol for x in topFine]


self.symbols = [i.Symbol for i in topFine]
self.y = self.History(self.symbols, self.rollingWindowSize, Resolution.Daily)
for i in self.symbols:
self.Debug(i.Symbol)

return self.symbols

def OnData(self, data):

symbols = self.symbols
for x in symbols:
if PredictionEngine(x.historicalPERatio,x.y).predictionScore() > float(x.Price):


self.SetHoldings(security, 0.1)
print("Security")
self.Debug(security)
self._changes = None
# if we have no changes, do nothing
def Rebalancing(self):
print("b")
for security in self.Portfolio.Values:
if PredictionEngine(security.historicalPERatio,security.y).predictionScore() < float(security.Price)*1.08 and security.Invested:
self.Liquidate(security.Symbol)

class PredictionEngine(object):
def __init__(self,historicalPERatio):
self.historicalPERatio = historicalPERatio
self.y = Y
def predictionScore(self):
scalar = StandardScaler()

pe = pd.DataFrame(self.historicalPERatio)

#after this line is where I do all the magical things needed to predict prices

return predictions