For a group of M related stocks that I specify, I would like to backtest the strategy of buying at the close, each day, equal dollar amounts of the N stocks that are most oversold, defined as being the most below (on a percentage basis) their P-day moving averages. (For example, I could own the 5 stocks out 50 that are most below their 21-day MA, in which case M = 50, N = 5, and P = 21.)
I would like to be able to test two versions — on which assumes you can use the closing price to…