I am new to using Python and really only have a little programming experience (with VB). I really appreciate the example code as that got me a lot further than I would be otherwise. My goal at the moment with this algorithm is to find the best and worst performers over the previous year in the S&P 500. I have the following questions:
Is there a better way to write the custom factor for percent change? Maybe one that allows the window to be changed.
When I ran the backtest there appeared to be some inconsistencies on some of the stocks and using close price vs. adjusted close price. For example, in the list of worst performers, ITUB showed a 1-year change of -94%. I added the current and past close prices so I could see what was going on. When I compared it with yahoo finance adjusted close price I noticed that it didn't follow the adjusted close price, but did follow the close price. Most of the others did follow the adjusted close price. Is this a problem with the data? Is there a better parameter to use than close?
Is there a better way to get the S&P 500? Currently the screen of top 500 by market cap gives me some non-US equities. Maybe there is a way to screen by US equities?
I really appreciate any help. Once I get this working I will look at different ways of adjusting the portfolio.