Back

How To Register A Custom Indicator With A Coarse Universe Selection?

I am trying to register my custom indicator in the initialize function with a coarse universe selection but currently am only able to register it using just one defined equity i.e. self.RegisterIndicator("TWTR", self.cv, Resolution.Daily). When I try to reference anything other than just a single equity ("TWTR" in this case) in the first part of self.RegisterIndicator(), I am given an error stating that it is unusable. Instead of only applying my custom indicator to a single equity, how do I register my indicator using a coarse universe selection of let's say 500 equities?

Here's where I'm at currently. Just need to figure out what to put in the first part of self.RegisterIndicator() to apply it to my coarse universe selection unless there's a better way of going about it:

def Initialize(self):
self.SetStartDate(2000,10,1)
self.SetEndDate(2019,1,1)
self.SetCash(100000)
self.UniverseSettings.Resolution = Resolution.Daily
self.AddUniverse(self.MyCoarseFilterFunction)

self.cv = TripleBottomIndicator()
self.RegisterIndicator(???, self.cv, Resolution.Daily)

def MyCoarseFilterFunction(self, coarse):
sortedByDollarVolume = sorted(coarse, key=lambda x: x.DollarVolume, reverse=True)
filtered = [ x.Symbol for x in sortedByDollarVolume
if x.Price > 5 and x.DollarVolume > 400000000 ]
return filtered[:500]

Thanks for the help!

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 Nathan,

We can't automatically create indicators for multiple securities with a simple method. Instead, we need to create an indicator for each security. Using the SimpleMovingAverage as an example, we need to specify parameters and setup a dictionary in Initialize

self.indicators_by_symbol = {}
self.sma_period = 10

Then in OnSecuritiesChanged, for each new securities added to the universe, we create the indicator, manually warm it up, and register it for new data. For each security removed from our universe, we simply remove the indicator for that security.

def OnSecuritiesChanged(self, changes):
for added in changes.AddedSecurities:
self.indicators_by_symbol[added.Symbol] = SimpleMovingAverage(added.Symbol, self.sma_period)

# Warm up indicator
history = self.History(added.Symbol, self.sma_period, Resolution.Daily).loc[added.Symbol]
for idx, row in history.iterrows():
self.indicators_by_symbol[added.Symbol].Update(idx, row['close'])

# Register indicator for new data
self.RegisterIndicator(added.Symbol, self.indicators_by_symbol[added.Symbol], Resolution.Daily)

for removed in changes.RemovedSecurities:
self.indicators_by_symbol.pop(removed.Symbol, None)

See the attached algorithm for reference.

Best,
Derek Melchin

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