Python: Calculating the growth rate over a year when the dates aren't the same

1.8k views Asked by At

I'm using python and Scrapy

What I am trying to do is calculate the growth rate of a stock (or rate of return) over a year, using monthly, weekly or daily data. Let's take this CAT data for example.

First on the list, is to calculate the rate of return at June 8, 2015. To do this, we use the formula (new - old)/old, or (June 8 2015 - June 8 2014)/June 8 2014. This would work fine, however there is no June 8, 2014 data! The closest is June 9th, or June 2nd.

Anyone have any ideas on how to tackle this accurately?

1

There are 1 answers

0
Alexander McFarlane On BEST ANSWER

I did a long internship as a quant in a London IB and calculation of dates was not a trivial task and totally depending on the business application. You have all sorts of calendars, public holidays and other such things to take into account.

It really depends on what calendar you wish to reflect for example:

  • Business Days = following US
  • Business Days = preceding Hong Kong, US & London

For your programming task:

  1. See this SO post on how to add (or subtract) business days from a calendar period.
  2. Parse the data from Yahoo! through directly and just use available dates assuming that they are the given calendar and that each trading event is 1 b.d. apart
  3. I would suggest using pandas for this