Created
July 15, 2017 00:39
-
-
Save anaved/0268ea0a49fe0e53bc482d0ae645f49d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Thirty360DayCountCalculator( DayCountCalculator ): | |
""" | |
A month is considered of 30 days and a year is of 360 days. | |
ISDA recommended method for day count is | |
360(y2-y1)+30(m2-m1-1)+max(0,30-d1)+min(30,d2) | |
* Take year diff | |
* Take month diff + 1 month to be adjusted by date | |
* Since every month is 30 and reduce d1 from it, and take | |
max with 0 in case result is negative ( days to 30 ) | |
* days in d2, min if more than 30 | |
""" | |
@property | |
def numerator(self): | |
return 30 | |
@property | |
def denominator(self): | |
return 360 | |
def day_count(self, start, end): | |
if end <= start: | |
return 0 | |
return 360*(end.year - start.year)\ | |
+ 30*(end.month - start.month -1)\ | |
+ max(0, 30 - start.day)\ | |
+ min(30, end.day) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment