Hello Quants,
I was wondering if someone could give me a little help on line 50 of this algo so that I can bring sector exposure down.
The algo filters out stocks below $1, market cap below $100m and requires a dollar volume traded per day proportional to the portfolio value. After this, in "Before trading start" it ranks the average of 2 different fundamental parameters for value and cuts this to the best 1000 stocks available. From these 1000 stocks it sorts them by highest 252 day momentum.
It is at this point I need help, to cycle through the list of stocks with momentum and pick the stock with the highest momentum, then the next highest from a different sector, then the next highest from a different sector. Once 1 stock is picked from each of the 11 sectors, I'd like it to cycle to the 2nd best momentum form 1 sector, the next best momentum from a different sector and so on. Is this even possible? I tried adding the optimize, but I can't get that to work with the sorting features I have in the before_trading_start. Any suggestions for code that could accomplish this would be much appreciated.