summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuillaume Horel <guillaume.horel@gmail.com>2018-03-16 12:53:56 -0400
committerGuillaume Horel <guillaume.horel@gmail.com>2018-03-16 13:12:14 -0400
commitb996fa2b28c3740a48fc9f18f53d902d7e535b9c (patch)
tree8f82ed8fa1dd53598f02935b3946eaf438839ce4
parentf51c45dce707fc41f19804db28ffaed3e8bbe06f (diff)
downloadpyisda-b996fa2b28c3740a48fc9f18f53d902d7e535b9c.tar.gz
Use trade_date
compute the forward implied default probabilities. allow to roll the trade date
-rw-r--r--pyisda/credit_index.pyx24
1 files changed, 17 insertions, 7 deletions
diff --git a/pyisda/credit_index.pyx b/pyisda/credit_index.pyx
index 6e9664f..2f7a37b 100644
--- a/pyisda/credit_index.pyx
+++ b/pyisda/credit_index.pyx
@@ -45,7 +45,7 @@ cdef TContingentLeg* copyContingentLeg(TContingentLeg* leg) nogil:
cdef class CurveList:
@cython.initializedcheck(False)
- def __init__(self, list curves not None, double[:] weights=None):
+ def __init__(self, list curves not None, double[:] weights=None, trade_date=None):
cdef:
SpreadCurve sc
size_t i
@@ -58,7 +58,11 @@ cdef class CurveList:
raise TypeError("curves need to be a list of SpreadCurve")
self.T = vector[double](sc._thisptr.get().fNumItems)
- self.base_date = sc._thisptr.get().fBaseDate
+ if trade_date is not None:
+ self.base_date = pydate_to_TDate(trade_date)
+ else:
+ self.base_date = sc._thisptr.get().fBaseDate
+
for i in range(self.T.size()):
self.T[i] = (sc._thisptr.get().fArray[i].fDate - self.base_date) / 365.
@@ -135,6 +139,13 @@ cdef class CurveList:
out[p.second] = p.first.decode('utf-8')
return out
+ @property
+ def trade_date(self):
+ return TDate_to_pydate(self.base_date)
+
+ @trade_date.setter
+ def trade_date(self, d):
+ self.base_date = pydate_to_TDate(d)
@property
def curves(self):
@@ -188,8 +199,9 @@ cdef class CurveList:
@cython.auto_pickle(False)
cdef class CreditIndex(CurveList):
- def __init__(self, start_date, maturities, list curves, double[:] weights=None):
- CurveList.__init__(self, curves, weights)
+ def __init__(self, start_date, maturities, list curves, double[:] weights=None,
+ trade_date=None):
+ CurveList.__init__(self, curves, weights, trade_date)
self.start_date = pydate_to_TDate(start_date)
for d in maturities:
self._maturities.push_back(pydate_to_TDate(d))
@@ -467,7 +479,6 @@ cdef class CreditIndex(CurveList):
cdef:
shared_ptr[TCurve] sc
pair[string, size_t] p
- TDate start_date
size_t i
np.npy_intp[2] n
n[0] = self._curves.size()
@@ -479,9 +490,8 @@ cdef class CreditIndex(CurveList):
for p in self.tickers:
sc = self._curves[p.second]
tickers[p.second] = p.first.decode('utf-8')
- start_date = sc.get().fBaseDate
for i in range(n[1]):
- sp[p.second, i] = JpmcdsForwardZeroPrice(sc.get(), start_date, schedule[i])
+ sp[p.second, i] = JpmcdsForwardZeroPrice(sc.get(), self.base_date, schedule[i])
return sp, tickers
cdef unsigned long fill_mask(const TDate maturity, const vector[TDate]& maturities,