0

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?

Alasdair
  • 298,606
  • 55
  • 578
  • 516
Alex McLean
  • 2,524
  • 5
  • 30
  • 53
  • 1
    "Accurate" is going to depend on business rules more than programming. – Mark Ransom Jun 09 '15 at 21:54
  • when you do full year to year calcs, you always use the first trading day of the year, so I would say you should use the first trading day after the day in question if the day in question has no data. – Christopher Pearson Jun 09 '15 at 22:14

1 Answers1

3

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
Community
  • 1
  • 1
Alexander McFarlane
  • 10,643
  • 9
  • 59
  • 100