diff options
Diffstat (limited to 'python/analytics/utils.py')
| -rw-r--r-- | python/analytics/utils.py | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/python/analytics/utils.py b/python/analytics/utils.py index 0cefaa9c..0341b7cc 100644 --- a/python/analytics/utils.py +++ b/python/analytics/utils.py @@ -1,10 +1,12 @@ import numpy as np import pandas as pd from scipy.special import h_roots -from dateutil.relativedelta import relativedelta +from dateutil.relativedelta import relativedelta, FR import datetime from pyisda.date import pydate_to_TDate from pandas.api.types import CategoricalDtype +from quantlib.time.date import nth_weekday, Wednesday, Date + tenor_t = CategoricalDtype(['3yr', '5yr', '7yr', '10yr'], ordered=True) def GHquad(n): @@ -30,6 +32,19 @@ def next_twentieth(d): r += relativedelta(months=3 - mod) return r +def third_wednesday(d): + if isinstance(d, datetime.date): + return d + relativedelta(day=1, weekday=FR(3)) + elif isinstance(d, Date): + return nth_weekday(3, Wednesday, d.month, d.year) + +def next_third_wed(d): + y = third_wednesday(d) + if y < d: + return third_wednesday(d + relativedelta(months=1)) + else: + return y + def roll_date(d, tenor, nd_array=False): """ roll date d to the next CDS maturity""" cutoff = pd.Timestamp('2015-09-20') |
