I already know that a moderator disagrees with me on this topic, so I expect a dissenting answer but I am posting this for transparency's sake anyway.
For questions like Analyze Stock Market Bottom Timing without Looping over Data Frame Rows - it was built specifically around an API (in this case Yahoo Finance) that has been removed from the internet. Never again will this code be able to run. On its own this is only about half the problem; the other half is that OP did not include example API responses in the question. We should be careful not to conflate this with something like Python 2, where it's old and inadvisable but still accessible.
I consider it justifiable to close the question, because the point of StackExchange is not only to answer someone's specific question for their own sake (something that in this case, five years later, is doubtful to be of value for the OP); but also to act as a reference for other readers - the reason that we in general endeavour to zombie-hunt. I can't see the question having much referential value. Any answers it might attract could only at this point be superficial in nature. Here is a list of questions I would need answered for me to feel confident in reviewing the use of Pandas in the question:
- What is the typical range of values in
SP500? - What are all of the columns in
gspc? How many rows are there? To_Equityis being (effectively) rolled. What is the first value?
and so on. A sample excerpt of data would be enough. Without it, none of these questions are answerable.

Comments
Nothing yet. Say the first thing.
Sign in to join the conversation.