Hi All! I am trying to use QC universe selection to get a list of delisted stocks (filtering out everything EXCEPT for the stock symbols that have been delisted), however it seems that no matter what I change it never works. I have copied the code I have right know, but I have changed it a ton of times. Any help would be greatly appreciated!
class test(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2020, 1, 1) # Set Start Date
self.SetEndDate(2020, 1, 15) # Set Start Date
# In Initialize:
self.AddUniverse(self.CoarseSelectionFunction, self.FineSelectionFunction)
def CoarseSelectionFunction(self, coarse):
#sortedByDollarVolume = sorted(coarse, key=lambda x: x.DollarVolume, reverse=True)
filtered = [ x.Symbol for x in coarse if x.HasFundamentalData]
#self.Log(filtered)
return filtered
def FineSelectionFunction(self, fine):
test = [x.Symbol for x in fine if x.SecurityReference.DelistingDate == self.Time]
#for x in fine:
#self.Debug(x.SecurityReference.ShareClassStatus)
#self.Debug(self.Time)
#for x in fine:
# self.Debug(x.SecurityReference.DelistingDate)
self.Log(test)
#self.Debug(test)
return test[:10]
Karthik Kailash
Your code is only running over a 2 week window - how many delistings are you expecting to find during that time? One thing you could try is to loosen your comparison by checking if x.SecurityReference.DelistingDate.date() == self.Time.date(). Or just check if DelistingDate is set, which would presumably give you all stocks delisted before the current simulation time. An entirely different approach would be to subscribe to a broad universe and act if you receive Delisting events in OnData(). This way you get a warning delisting event that happens before the delisting itself so you can do trades, since I don't know if the platform lets you do trades on delisted securities.
Cole Kuster
Thanks! The reasont that I have a shorter time period is so that the backtest runs quicker as I tweak it. Even though there are many delisted stocks in the period, I know there are some because I have check and tested to make sure they have fundamental data in the research environment. I will try using the second method you suggested and see if I get any better results. I am not trying to trade the delisted stocks at this time, im just trying to get a list of all delisted stocks in QC that also have fundamental data. Is there a way I can store that list somewhere so I can access it after I have run my code?
Karthik Kailash
Yeah, you can put it in a public file in Box/Dropbox, . Or you can use QC's ObjectStore
Jared Broad
> am not trying to trade the delisted stocks at this time, I'm just trying to get a list of all delisted stocks in QC that also have fundamental data
Hi Cole, why is this? You don't need to do this - it's handled for you by universe selection.
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.
Cole Kuster
Hi Jared, I am doing this so that I look at different graphs/statistics of fundamental data in the research environment for delisted stocks. I am trying to find some trends that may indiciate why a stock is going to be delisted and see if I can semi predict that behavior.
Cole Kuster
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!