Back

Error Back-testing Strategy from Strategy Libray

# 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

Update Backtest







0

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.


Hi Redpoint,

We are sorry that the code for this strategy example has an error. We will update it.

FineFundamental doesn't have a 'MarketCap' API. To see the detailed API information for FineFundamental, please take a look at here. For the correction of the code, please check out the similar question that has been answered here.

Thanks!

0

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.


Update Backtest





0

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.


Loading...

This discussion is closed