Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Can anyone help me translate my idea?

I have only just started to learn basic coding so this might take me a while....

Id like to split S&P 500 into different sectors and then calculate the most undervalued sector according to group mean or median ev/ebitda
Then out of the bottom 5 sectors (excluding worst performing) I would like to buy 5 stocks out of each.

I have had a look at scripts made by others but have not been able to find anything like this.

3 responses

@Ciaran Y., A method that you might employ that would simplify your processing is to use the X__ ETFs as proxies to your S&P500 sectors. Follow those and then when the time is ripe, according to your algorithm, sample out of the components of those ETFs a set of securities you'd like to trade.

The primary limitation to this, and to your strategy in general, is that you have a limited number of securities you can work with, 200 in fact. There are ways around this that may or may not work but in general, you may want to just stick with that number to start. So, your first step would be to select N number of components from each ETF from this list: "XLB","XLE","XLF","XLI","XLK","XLP","XLU","XLV","XLY".

There are other sector based ETFs but those are common and proven. Research each one selecting say, 20, securities from each. (For the remaining 20 (9 x 20 = 180) of the maximum 200 you could select a list of treasury and or commodity type ETFs, i.e. GLD, SLV,TLT,AGG...) Setup an array for each sector ETF and add symbols(...) to each.

Now you have your super groups based on the ETFs which you can use as your primary logic drivers. And you have the sub groups, the securities within each ETF, you can use as your trading vehicles.

No doubt there are holes in this blanket strategy, legs come and go within ETFs; a biased 20 picked from each sector, 200 is not 500, etc. But, given the restrictions imposed here by the Q's platform, I'd posit that this proposed technique would get you ~75% of the way there.

@Ciaran,

For completeness, it is discouraged by Q support, but there is a trick to get 500+ stocks into an algo universe, at up to 200 per day. So, after 3 trading days, you'd have 600 securities to play around with, at the risk of your algo bogging down and crashing.

The research platform is another option, which should scale better with the number of securities. If you submit an algo to the contest, I think you get automatic access.

I'd start with Market Tech's sector idea, but down the road, keep in mind that there are other options.

--Grant

Thanks guys

Ill have a look at the ETF route - sounds similar to a momentum based allocation strategy which should make reverse engineering easier for me.