diff options
| author | Guillaume Horel <guillaume.horel@gmail.com> | 2018-06-20 13:54:02 -0400 |
|---|---|---|
| committer | Guillaume Horel <guillaume.horel@gmail.com> | 2018-06-20 13:54:02 -0400 |
| commit | a4cedd890512000eebe789b5aba18455c3eacdc0 (patch) | |
| tree | 1088b6274098ac0c28a16d230678b882748203d3 | |
| parent | a95a5d8335a2d33094e002bce57cd52ef7fe8a01 (diff) | |
| download | pyisda-a4cedd890512000eebe789b5aba18455c3eacdc0.tar.gz | |
use recovery curves
| -rw-r--r-- | pyisda/credit_index.pyx | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/pyisda/credit_index.pyx b/pyisda/credit_index.pyx index 89d8802..c20ab84 100644 --- a/pyisda/credit_index.pyx +++ b/pyisda/credit_index.pyx @@ -297,10 +297,10 @@ cdef class CreditIndex(CurveList): return h #@cython.initializedcheck(False) - def pv_vec(self, step_in_date, cash_settle_date, YieldCurve yc, double recovery_rate): + def pv_vec(self, step_in_date, cash_settle_date, YieldCurve yc): cdef: TDate step_in_date_c = pydate_to_TDate(step_in_date) - TDate cash_settle_date_c = pydate_to_TDate(cash_settle_date) + TDate cash_settle_date_c = pydate_to_TDate(cash_settle_date) np.npy_intp[2] n n[0] = self._curves.size() n[1] = self._maturities.size() @@ -313,6 +313,7 @@ cdef class CreditIndex(CurveList): TDate maturity TCurve* sc pair[string, size_t] p + double recovery_rate for maturity in self._maturities: d[j] = maturity - 134774 @@ -322,6 +323,9 @@ cdef class CreditIndex(CurveList): for p in self.tickers: sc = self._curves[p.second].get() tickers.append(p.first) + # TODO: pick the actual recovery on the curve + # this only works for flat recovery curve + recovery_rate = self.recovery_rates[p.second].get()[0] for j in range(self._maturities.size()): JpmcdsContingentLegPV(self.contingent_legs[j], sc.fBaseDate, @@ -355,7 +359,7 @@ cdef class CreditIndex(CurveList): return accrued def pv(self, step_in_date, cash_settle_date, maturity, YieldCurve yc not None, - double recovery_rate, double fixed_rate, double epsilon=0.): + double fixed_rate, double epsilon=0.): cdef: TDate step_in_date_c = pydate_to_TDate(step_in_date) @@ -379,7 +383,7 @@ cdef class CreditIndex(CurveList): h = vector[double](self.T.size()) with nogil: r = pv(self._curves, self.base_date, step_in_date_c, cash_settle_date_c, - yc._thisptr.get(), legs, recovery_rate, fixed_rate, + yc._thisptr.get(), legs, self.recovery_rates, fixed_rate, self._weights, epsilon, h, self.T, mask) if i == -1: free(legs.first) @@ -387,8 +391,7 @@ cdef class CreditIndex(CurveList): return r def theta(self, step_in_date, cash_settle_date, maturity, YieldCurve yc not None, - double recovery_rate, double fixed_rate, double old_pv=nan(""), - theta_date=None): + double fixed_rate, double old_pv=nan(""), theta_date=None): """ computes the theta (carry net of roll down) if theta_date is None, this is 1 year theta, otherwise theta to that date""" cdef: @@ -422,7 +425,7 @@ cdef class CreditIndex(CurveList): legs.second = self.fee_legs[i] old_pv = pv(self._curves, self.base_date, step_in_date_c, cash_settle_date_c, yc._thisptr.get(), legs, - recovery_rate, fixed_rate, self._weights, + self.recovery_rates, fixed_rate, self._weights, 0., h, self.T, 0) if i == -1: free(legs.first) @@ -438,7 +441,7 @@ cdef class CreditIndex(CurveList): cdef r = old_pv - pv(self._curves, self.base_date, step_in_date_c, cash_settle_date_c, - yc._thisptr.get(), legs, recovery_rate, fixed_rate, + yc._thisptr.get(), legs, self.recovery_rates, fixed_rate, self._weights, 0., h, self.T, 0) + carry if i == -1: free(legs.first) @@ -597,7 +600,7 @@ cdef double pv(vector[shared_ptr[TCurve]]& curves, TDate cash_settle_date, TCurve* yc, pair[TContingentLeg_ptr, TFeeLeg_ptr]& legs, - double recovery_rate, + const vector[shared_ptr[double]] &recovery_rates, double fixed_rate, vector[double]& weights, double epsilon, @@ -609,6 +612,7 @@ cdef double pv(vector[shared_ptr[TCurve]]& curves, TCurve* tweaked_curve shared_ptr[TCurve] c size_t i = 0 + double recovery_rate if epsilon != 0.: tweaked_curve = JpmcdsCopyCurve(curves[0].get()) @@ -618,6 +622,9 @@ cdef double pv(vector[shared_ptr[TCurve]]& curves, tweak_curve(c.get(), tweaked_curve, epsilon, h, T, mask) else: tweaked_curve = c.get() + # TODO: pick the actual recovery on the curve + # this only works for flat recovery curve + recovery_rate = recovery_rates[i].get()[0] JpmcdsContingentLegPV(legs.first, base_date, cash_settle_date, |
