How to append symbols to the fine selection universe?

Back

If I have a list of symbols that I always want included in my universe, how can I append them to the end of the fine universe selection to ensure that they're included in my universe? I've tried appending the symbols themselves to the list that I return to the fine universe selection function but receive an error since it looks like the fine selection filter has it's own identifier for stocks and doesn't recognize a normal stock symbol. For exmple, the identifier for TLT is 'TLT: some type of box 135.4'. Is there a place where I can find the universe identifiers to append to my universe? Or is there a better way of going about this? 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.


Nathan,

I was looking for something similar check out this thread it says removing but there is a piece of code that appends symbols at the end of the fine filter is that what you tried?

 

https://www.quantconnect.com/forum/discussion/4278/removing-tickers-from-manual-universe/p1

Frank

0

Do the symbols have to be added directly to the fine universe? In order of your universe they are passed like this: Coarse -> Fine -> OnSecuritiesChanged -> OnData/Sceduled event.  Is it a list of symbols you just want to be available for trading along with those selected by the FineSelectionFunction?

0

Frank Giardina - Thanks for the link. I've gone through and retried this with success! The difference that solved it for me was using 

self.spy = Symbol.Create('SPY', SecurityType.Equity, Market.USA) 

rather than the usual 

self.spy = self.AddEquity("SPY", Resolution.Minute)

For anyone coming across this post in the future, here is a more complete example of a solution to refer to than the one in the thread linked above:

class MomentumEffAlgorithm(QCAlgorithm):

def Initialize(self):

self.SetStartDate(2020, 1, 1) # Set Start Date
self.SetEndDate(2020, 11, 1) # Set End Date
self.SetCash(100000) # Set Strategy Cash

# Create your symbols here
self.agg = Symbol.Create('AGG', SecurityType.Equity, Market.USA)
self.tlt = Symbol.Create('TLT', SecurityType.Equity, Market.USA)
self.ief = Symbol.Create('IEF', SecurityType.Equity, Market.USA)
self.iei = Symbol.Create('IEI', SecurityType.Equity, Market.USA)

# Add your symbols to a list
self.addedsymbols = [self.agg, self.tlt, self.ief, self.iei]

self.UniverseSettings.Resolution = Resolution.Daily
self.AddUniverse(self.CoarseSelectionFunction, self.FineSelectionFunction)

def CoarseSelectionFunction(self, coarse):

self.selected = sorted([x for x in coarse if x.HasFundamentalData and x.Price > 5],
key=lambda x: x.DollarVolume, reverse=True)

self.coarselist = [x.Symbol for x in self.selected[:100]]

for symbol in self.addedsymbols:
self.coarselist.append(symbol)

return self.coarselist

def FineSelectionFunction(self, fine):

fine = [f for f in fine if f.ValuationRatios.PERatio > 0
and f.EarningReports.BasicEPS.TwelveMonths > 0
and f.EarningReports.BasicAverageShares.ThreeMonths > 0
]

self.selectedfine = sorted(fine,
key=lambda f: f.ValuationRatios.PERatio *
f.EarningReports.BasicEPS.TwelveMonths *
f.EarningReports.BasicAverageShares.ThreeMonths,
reverse=True)

self.finesymbols = [x.Symbol for x in self.selectedfine[:50]]

for symbol in self.addedsymbols:
self.finesymbols.append(symbol)

return self.finesymbols

No updates to OnSecurities changed or OnData are necessary. The symbols are there!

*Note* - not sure why the formatting is screwed up, I'll repost it below with the correct indentation.

0

class MomentumEffAlgorithm(QCAlgorithm):

def Initialize(self):

self.SetStartDate(2020, 1, 1) # Set Start Date
self.SetEndDate(2020, 11, 1) # Set End Date
self.SetCash(100000) # Set Strategy Cash

# Create your symbols here
self.agg = Symbol.Create('AGG', SecurityType.Equity, Market.USA)
self.tlt = Symbol.Create('TLT', SecurityType.Equity, Market.USA)
self.ief = Symbol.Create('IEF', SecurityType.Equity, Market.USA)
self.iei = Symbol.Create('IEI', SecurityType.Equity, Market.USA)

# Add your symbols to a list
self.addedsymbols = [self.agg, self.tlt, self.ief, self.iei]

self.UniverseSettings.Resolution = Resolution.Daily
self.AddUniverse(self.CoarseSelectionFunction, self.FineSelectionFunction)

def CoarseSelectionFunction(self, coarse):

self.selected = sorted([x for x in coarse if x.HasFundamentalData and x.Price > 5],
key=lambda x: x.DollarVolume, reverse=True)

self.coarselist = [x.Symbol for x in self.selected[:100]]

for symbol in self.addedsymbols:
self.coarselist.append(symbol)

return self.coarselist

def FineSelectionFunction(self, fine):

fine = [f for f in fine if f.ValuationRatios.PERatio > 0
and f.EarningReports.BasicEPS.TwelveMonths > 0
and f.EarningReports.BasicAverageShares.ThreeMonths > 0
]

self.selectedfine = sorted(fine,
key=lambda f: f.ValuationRatios.PERatio *
f.EarningReports.BasicEPS.TwelveMonths *
f.EarningReports.BasicAverageShares.ThreeMonths,
reverse=True)

self.finesymbols = [x.Symbol for x in self.selectedfine[:50]]

for symbol in self.addedsymbols:
self.finesymbols.append(symbol)

return self.finesymbols

 

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...

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!