This is my first algorithm so please be kind. I am very rusty and I have not used python before.
I love "The Little Green Book that Beats the Market" from Joel Greenblatt. This is an homage to his style of investing - small number of high conviction stocks. I personally believe it is possible to beat the index with any combination of small number of stocks from the index itself (except for financials).
The details are in the code itself. I basically created an equally weighted portfolio and put aside cash reserves. If any SID is outperforming the group I re-balance the portfolio. If an SID is under-performing the group, I re-balance only if I have enough cash reserves. I buy more shares when I have excess cash beyond my initial cash reserve. Otherwise, I hoard the cash.
I used the top 9 stocks of the S&P index to begin with. Each stock got an initial investment of ~$100K and I set aside a cash reserve of ~$100K. You can try using other combinations of SIDs from the index.