aboutsummaryrefslogtreecommitdiffstats
path: root/python/dates.py
diff options
context:
space:
mode:
Diffstat (limited to 'python/dates.py')
-rw-r--r--python/dates.py16
1 files changed, 12 insertions, 4 deletions
diff --git a/python/dates.py b/python/dates.py
index 5d5470a5..fbdc7d98 100644
--- a/python/dates.py
+++ b/python/dates.py
@@ -1,11 +1,10 @@
import datetime
import pandas as pd
+import unittest
+
+from dateutil.relativedelta import relativedelta
from pandas.tseries.offsets import CustomBusinessDay, Day, QuarterBegin
from pandas.tseries.holiday import get_calendar, HolidayCalendarFactory, GoodFriday
-import sys
-sys.path.append('analytics')
-from utils import previous_twentieth
-import unittest
fed_cal = get_calendar('USFederalHolidayCalendar')
bond_cal = HolidayCalendarFactory('BondCalendar', fed_cal, GoodFriday)
@@ -19,6 +18,15 @@ def imm_dates(start_date, end_date):
shift(19, freq='D').
shift(0, bus_day))
+def previous_twentieth(d):
+ r = datetime.date(d.year, d.month, 20)
+ if r > d:
+ r -= relativedelta(months=1)
+ mod = r.month % 3
+ if mod != 0:
+ r -= relativedelta(months = mod)
+ return r
+
def days_accrued(tradedate):
tradedate = pd.Timestamp(tradedate)
start_protection = tradedate + Day()