forked from llazzaro/pyquant
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdaycounter.py
56 lines (39 loc) · 1.93 KB
/
daycounter.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#DayCounter class
class DayCounter(object):
""""How many days are there between two dates"""
def __init__(self, startdate, enddate):
self.name = "Simple Daycounter"
self.yearfraction = __calcyearfraction(startdate, enddate)
def __calcyearfraction (self, startdate, enddate):
return enddate - startdate / 360.0
class Actual360(DayCounter):
"""Actual/360 day count convention
Actual/360 day count convention, also known as "Act/360", or "A/360"."""
def __init__(self, startdate, enddate):
self.name = "Actual/360"
self.yearfraction = __calcyearfraction(startdate, enddate)
def __calcyearfraction (self, startdate, enddate):
return enddate - startdate / 360.0
class Thirty360(DayCounter):
"""30/360 day counters"""
def __init__(self, startdate, enddate):
self.name = "30/360"
self.yearfraction = __calcyearfraction(startdate, enddate)
def __calcyearfraction (self, startdate, enddate):
return enddate - startdate / 360.0
class ActualActual(DayCounter):
"""Actual/Actual day count
The day count can be calculated according to:
- the ISDA convention, also known as "Actual/Actual (Historical)",
"Actual/Actual", "Act/Act", and according to ISDA also "Actual/365",
"Act/365", and "A/365";
- the ISMA and US Treasury convention, also known as
"Actual/Actual (Bond)";
- the AFB convention, also known as "Actual/Actual (Euro)".
For more details, refer to
http://www.isda.org/publications/pdf/Day-Count-Fracation1999.pdf"""
def __init__(self, startdate, enddate):
self.name = "Actual/Actual"
self.yearfraction = __calcyearfraction(startdate, enddate)
def __calcyearfraction (self, startdate, enddate):
return enddate - startdate / 360.0