Say I want to trade only the top 10 holdings of QQQ. Can this be done via a Coarse/Fine universal selection?
Anyone have an example of this?
I would be envisioning something like the following, but specific to an ETF rather than a sector.
def Coarse(self, coarse):
if self.Time.month == self.lastMonth:
return Universe.Unchanged
self.lastMonth = self.Time.month
allCoarse = [x for x in coarse if x.HasFundamentalData and x.Price > 1 and x.Volume > 1]
finalCoarse = sorted(allCoarse, key = lambda x: x.DollarVolume, reverse = True)
return [x.Symbol for x in finalCoarse][:1]
def Fine(self, fine):
filteredSymbols = []
sortedBySector = [x for x in fine]
for code, g in groupby(sortedBySector, lambda x: x.AssetClassification.MorningstarSectorCode):
for x in sorted(g, key = lambda x: x.ValuationRatios.PERatio, reverse = True)[:1]:
filteredSymbols.append(x.Symbol)
return filteredSymbols[:10]
Varad Kabade
Hi Axist,
QQQ, like other ETFs, has a proprietary universe definition which might be difficult to reproduce using Coarse and Fine Fundamental data. So, we recommend using Manual Universe Selection of the top 10 holdings for securities in QQQ. Refer to the following code snippet.
Alternatively, we can fetch the latest top10 QQQ data from website using download method
Best,
Varad Kabade
Axist
Thanks for the response Varad. The only issue I am seeing is that the download method wont allow for historical holdings of an ETF. For example, with QQQ, their site doesn't unfortunately have old fact sheets or a history of what the top 10 holdings of the QQQ was in Q1 of 2018 for example.
That being said, I take it my backtests will just take whatever the current top 10 holdings are, and run them against the time frame specified in back algorithm? Which seems unfortunate. This may be a question for Google, but you wouldn't happen to know of any data sources that might provide this kind of information?
Louis Szeto
Hi Axist
We would not recommend copying an ETF from an online source as its constituents are ever-changing. Your backtest or live trade is not able to renew in time. However, if you insist, Yahoo Finance shall do the magic. You can search an ETF symbol and check on the "Holdings" tab (e.g. SPY) for the top 10 holdings. Please bear in mind this is not guaranteed to be up-to-date. Then you could create a .csv file to store ETF's constituents and maintain/update yourself in the form of
for example. Now, you can create a custom universe based on the .csv's data:
You can study the details in this example.
Best
Louis Szeto
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.
Axist
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!