I'm trying to access a property of MorningStar in my Universe Selection.
However, I get the following error:
Runtime Error: TypeError : Cannot get managed object
at
x.FinancialStatements.BalanceSheet.OrdinarySharesNumber >= MIN_SHARE_COUNT
File "main.py" in main.py:line 39
TypeError : Cannot get managed object
The entire code is as follows:
from Selection.FundamentalUniverseSelectionModel import FundamentalUniverseSelectionModel
class RedGhhost(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2021, 1, 29)
self.SetCash(100000)
self.AddUniverseSelection(UniverseModule())
self.UniverseSettings.Resolution = Resolution.Daily
class UniverseModule(FundamentalUniverseSelectionModel):
def __init__(self, filterFineData = True, universeSettings = None):
super().__init__(filterFineData, universeSettings)
self.averages = {}
'''
Filter by price
'''
def SelectCoarse(self, algorithm, coarse):
return [
x.Symbol for x in coarse if (
x.Price > 10
and x.HasFundamentalData
)
]
'''
Filter by min market cap and share count
'''
def SelectFine(self, algorithm, fine):
MIN_MKT_CAP = 1 * 10 ^ 9
MIN_SHARE_COUNT = 1 * 10 ^ 9
MAX_BARS_BACK = 200
initialFilter = [
x.Symbol for x in fine if (
x.FinancialStatements.BalanceSheet.OrdinarySharesNumber >= MIN_SHARE_COUNT
and x.MarketCap >= MIN_MKT_CAP
)
]
for x in initialFilter:
history = algorithm.History(x, MAX_BARS_BACK, Resolution.Daily)
if x not in self.averages:
self.averages[x] = SymbolData(x, history)
avg = self.averages[cf.Symbol]
avg.update(cf.EndTime, cf.AdjustedPrice)
upTrending = list(filter(lambda x: x.isUptrend, self.averages.values()))
finalSymbols = [x.symbol for x in upTrending]
return finalSymbols
class SymbolData(object):
def __init__(self, symbol, history):
self.symbol = symbol
self.longTerm = ExponentialMovingAverage(200)
self.mediumTerm = ExponentialMovingAverage(100)
self.isUptrend = False
for time, row in history.iterrows():
self.longTerm.Update(time, row.close)
self.mediumTerm.Update(time, row.close)
def update(self, time, value):
self.longTerm.Update(time, value)
self.mediumTerm.Update(time, value)
longTerm = self.longTerm.Current.Value
mediumTerm = self.mediumTerm.Current.Value
self.isUptrend = (
mediumTerm > longTerm
)
I don't see any actual example in the Documentation on how exactly one can access MorningStar fundamentals; clearly I'm doing it the wrong way.
Please help.
Vladimir
Nikhil Bhaskar,To avoid error on line 39 you can try
Red Ghost
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!