Back

How fix the error in accessing symbol in the coarse list under CoarseSelection function

Hello!

I encountered the ff error in my program:

Runtime Error: Exception : Please register to receive data for symbol 'A RPTMYV3VC57P' using the AddSecurity() function...at CoarseSelectionFunction in main.py:line 113

CoarseSelectionFunction (lines 83 - 118):

def CoarseSelectionFunction(self, coarse):
        
        Initial_Universe = [x for x in coarse if x.HasFundamentalData]
        Filtered_Universe = []

       for x in Initial_Universe:
            ticker_symbol = x.Symbol
            #security_key = x.key
        
            #We only want equities that satisfy the following screening criteria
                #US stocks, min volume of last 50 trading days above 500K shares
                #Min price of $1 per share 
                #Min dollar volume of $2.5M over same 50 day time period

if x.DollarVolume > 2500000 and x.Price > self.value_MinStockPrice and x.Volume > 500000:    
                Filtered_Universe.append(x)
      
        #For every stock that satisfy the screening criteria, compute the RSI
        for x in Filtered_Universe:
            x.RS_Index = self.RSI(x.Symbol, self.value_RSIDays, Resolution.Daily)
        
        #Then, sort the stocks according to the highest RSI:
        Filtered_Universe.sort(key=lambda x: x.RS_Index, reverse=True)      

        return [i.Symbol for i in Filtered_Universe]

To fix the error, I put the ff. code in main.py under the initialize function:

self.AddSecurity(SecurityType.Equity,'A RPTMYV3VC57P', Resolution.Daily)

However, I still get the following error:

Runtime Error: Exception : Please register to receive data for symbol 'AA WF7IHVI76I5H' using the AddSecurity() function...at CoarseSelectionFunction in main.py:line 113

What is the best way to fix the error? 

Appreciate the response! 

Update Backtest







I got that error when I had not registered the security up in Initialize():

def Initialize(self):

self.SetStartDate(2018,5,25) #Set Start Date
self.SetEndDate(2018,5,29) #Set End Date
self.SetCash(20000) #Set Strategy Cash
self.AddEquity("SPY", Resolution.Second)
0

Hi Myrich,

"self.RSI()" is not available to use in coarse universe selection as only symbols data being returned by CoarseSelectionFunction are subscribed. You should use the indicator constructor "self.RSI= self.RelativeStrengthIndex(period)" and update the indicator manually using "self.RSI.Update(time, value)". Please see this algorithm on Github. It is similar to the ExponentialMovingAverage() in this example (you can't use EMA() here as the symbol data in CoarseSelectionFunction are not subscribed).

https://github.com/QuantConnect/Lean/blob/master/Algorithm.Python/EmaCrossUniverseSelectionAlgorithm.py
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.


Thanks Jing a lot for commenting. 

0

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