# https://quantpedia.com/Screener/Details/25

class SmallCapInvestmentAlgorithm(QCAlgorithm):

def Initialize(self):

self.SetStartDate(2016, 1, 1)
self.SetEndDate(2019, 7, 1)
self.SetCash(100000)

self.UniverseSettings.Resolution = Resolution.Daily
self.count = 10

self.year = -1
self.symbols = []
self.AddUniverse(self.CoarseSelectionFunction, self.FineSelectionFunction)


def CoarseSelectionFunction(self, coarse):
''' Drop stocks which have no fundamental data or have low price '''

if self.year == self.Time.year:
return self.symbols

return [x.Symbol for x in coarse if x.HasFundamentalData and x.Price > 5]


def FineSelectionFunction(self, fine):
''' Selects the stocks by lowest market cap '''

if self.year == self.Time.year:
return self.symbols

# Calculate the market cap and add the "MarketCap" property to fine universe object
for i in fine:
i.MarketCap = (i.EarningReports.BasicAverageShares.ThreeMonths *
i.EarningReports.BasicEPS.TwelveMonths *
i.ValuationRatios.PERatio)

sorted_market_cap = sorted([x for x in fine if x.MarketCap > 0], key=lambda x: x.MarketCap)

self.symbols = [i.Symbol for i in sorted_market_cap[:self.count]]
return self.symbols


def OnData(self, data):

if self.year == self.Time.year:
return

self.year = self.Time.year

for symbol in self.symbols:
self.SetHoldings(symbol, 1.0/self.count)


def OnSecuritiesChanged(self, changes):
''' Liquidate the securities that were removed from the universe '''

for security in changes.RemovedSecurities:
symbol = security.Symbol
if self.Portfolio[symbol].Invested:
self.Liquidate(symbol)



11 | 15:40:40:
Runtime Error: AttributeError : 'FineFundamental' object has no attribute 'MarketCap'
at FineSelectionFunction in main.py:line 40
at <listcomp> in main.py:line 40
AttributeError : 'FineFundamental' object has no attribute 'MarketCap' (Open Stacktrace)

I was wondering if anyone could help me with this error, seems an error is thrown when we add the 'MarketCap' property to the fine universe object.

 

Thanks