summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuillaume Horel <guillaume.horel@gmail.com>2017-05-05 15:21:35 -0400
committerGuillaume Horel <guillaume.horel@gmail.com>2017-05-05 15:21:35 -0400
commit3269416a5058ee5c9215b9d3178146ddba6c1416 (patch)
tree402099adf7ed6d671dcab94307dd6fb7f8a5db48
parentfa975c9194a8444ff817ef9d56fe53235c984f60 (diff)
downloadpyisda-3269416a5058ee5c9215b9d3178146ddba6c1416.tar.gz
new function
-rw-r--r--pyisda/curve.pyx26
1 files changed, 25 insertions, 1 deletions
diff --git a/pyisda/curve.pyx b/pyisda/curve.pyx
index c188b1a..6039616 100644
--- a/pyisda/curve.pyx
+++ b/pyisda/curve.pyx
@@ -1,6 +1,6 @@
from libc.stdlib cimport malloc, free, calloc
from libc.string cimport memcpy
-from libc.math cimport log1p
+from libc.math cimport log1p, log
from libcpp.vector cimport vector
from date cimport (JpmcdsStringToDateInterval, pydate_to_TDate, dcc,
@@ -539,3 +539,27 @@ cdef class SpreadCurve(Curve):
r.append(par_spreads[i])
free(par_spreads)
return r
+
+def fill_curve(SpreadCurve sc, list end_dates):
+ cdef int n_dates = len(end_dates)
+ cdef TDate* end_dates_c = <TDate*>malloc(n_dates * sizeof(TDate))
+ cdef double* rates = <double*>malloc(n_dates * sizeof(TDate))
+
+ cdef size_t i
+ cdef TDate base_date = sc._thisptr.get().fBaseDate
+
+ for i, d in enumerate(end_dates):
+ end_dates_c[i] = pydate_to_TDate(d)
+ t = (end_dates_c[i] - base_date)/365.
+ rates[i] = -log(JpmcdsForwardZeroPrice(sc._thisptr.get(), base_date,
+ end_dates_c[i])) / t
+
+ cdef TCurve* curve = JpmcdsMakeTCurve(sc._thisptr.get().fBaseDate,
+ end_dates_c,
+ rates,
+ n_dates,
+ 5000.,
+ 2)
+ cdef SpreadCurve sc_new = SpreadCurve.__new__(SpreadCurve)
+ sc_new._thisptr = make_shared(curve)
+ return sc_new