Back to Community
How to use zipline or Quantopian packages to get 1 year and 3 month % change of stocks?

I have some experience with zipline from a course I took, but the course mostly coded all the zipline related stuff for us (whereas the stuff we were required to do was later). Thus, I'm not that familiar with how it works. What I have at the moment is a pandas dataframe with various information in it from numerous companies taken from 10-K filings. One of the columns in this dataframe contains the ticker of these companies, another column contains the date of the filing, and there are several other columns with various irrelevant pieces of information. What I would like to get is the percent change in prices of that company's stock (for each row) over a year and over 3 months following the date in the dates column. I would like to then put the percent change over a year into a new column in the dataframe, and over three months into a separate new column in the dataframe.

I know I need to use something like zipline's Returns class with a window_length equal to 252 for a year or 60 for three months but other than that I'm not sure where to begin. I have read the beginner's guide on the zipline website, but still a bit lost. I'm not looking to implement a trading strategy or anything, I just need the percent change to then use in a correlation analysis with another column in the dataframe later (to check if the values in that column have any correlation to the percent change in stock prices).

Some of the things I am wondering are: Do I need to create a pipeline to do this? How would I specify my universe of stocks in this case? How does the Returns class from zipline work, does it just calculate the percent change in the closing price between the start and end dates? If so, could I somehow just get the close price from the start date I have and the close price from a year later with Quantopian (and then use Python's pct_change() function, which might be much simpler)? The examples from the course I took all utilise zipline in portfolio creation/optimisation, so I'm not sure how to do just do something simpler like what I want.

Would someone be able to recommend a way to do this, or links to tutorials that might help? Thanks!