I'm just learning python and cannot get this code to run properly.
Can anyone identify what I am doing incorrectly in the code
Heres what I am trying to do
- take the daily log returns of XLF and XLU
- subtract XLU daily log return from XLF log return. (how much more XLF has returned each day)
- take the cumulative sum
- get the 200 day moving average of the cumulative sum
- if the cumulative sum is greater than its 200 day moving average then buy XLF otherwise buy XLU
edit: fyi, the problem in the attached algorithm is that it doesn't rotate between ETFs. I think something is wrong with the IF statement, I cant figure out what I need to do to fix the code though