Sorry, my code was really bad. I've learned a lot since. For consolation, here is more efficient code. Believe it or not, it holds the same portfolio. Q has data starting 2002, so any code that looks back a year should start at 2003. If you start my new code and your code at 2003, they are equivalent.
Again, I apologize for my poor initial code. I have no doubt that I will regret publishing my newest code in the future as I learn more about Python and finance :P
I hope this algorithm was a useful learning experience for you though!