diff options
| author | Guillaume Horel <guillaume.horel@gmail.com> | 2019-03-07 12:45:08 -0500 |
|---|---|---|
| committer | Guillaume Horel <guillaume.horel@gmail.com> | 2019-03-07 12:45:08 -0500 |
| commit | b7ace562a9ed035e811e3c62bb0f55b002707277 (patch) | |
| tree | dc8d0932ee2fa1391c30406ec359ceffbce3a0eb | |
| parent | c54eeffc0813a2337db1901ffcb79ae97c491b42 (diff) | |
| download | pyisda-b7ace562a9ed035e811e3c62bb0f55b002707277.tar.gz | |
faster curve generation
| -rw-r--r-- | pyisda/curve.pyx | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/pyisda/curve.pyx b/pyisda/curve.pyx index 702e89e..f77ddfa 100644 --- a/pyisda/curve.pyx +++ b/pyisda/curve.pyx @@ -1,4 +1,4 @@ -from cython.operator import dereference as deref +from cython.operator import dereference as deref, preincrement as preinc from libc.math cimport log1p, log, exp, isnan from .date cimport (JpmcdsStringToDateInterval, pydate_to_TDate, dcc, TMonthDayYear, JpmcdsDateIntervalToFreq, JpmcdsDateFwdThenAdjust, TDate_to_pydate, @@ -494,6 +494,7 @@ cdef class SpreadCurve(Curve): cdef TDate cash_settle_date_c cdef TDate start_date_c cdef string ticker_cpp = ticker + cdef TRatePt* ptr = NULL if start_date is None: start_date_c = _previous_twentieth(today_c, True) @@ -515,7 +516,6 @@ cdef class SpreadCurve(Curve): cdef double* tenors_c = NULL cdef TCurve* curve = NULL cdef TCurve* new_curve = NULL - cdef vector[double] rates cdef unsigned int includes = 0 cdef size_t i cdef bint freeup = False @@ -564,7 +564,7 @@ cdef class SpreadCurve(Curve): with nogil: if self.defaulted == -1: curve = JpmcdsCleanSpreadCurve(today_c, - <TCurve*>get_TCurve(yc), + get_TCurve(yc), start_date_c, step_in_date_c, cash_settle_date_c, @@ -581,13 +581,18 @@ cdef class SpreadCurve(Curve): MODIFIED, b'NONE') else: - rates = vector[double](n_dates, JPMCDS_MAX_RATE) - curve = JpmcdsMakeTCurve(today_c, - end_dates_c, - rates.data(), - n_dates, - <double>CONTINUOUS, - ACT_360) + curve = <TCurve*>malloc(sizeof(TCurve)) + curve.fNumItems = n_dates + curve.fArray = <TRatePt*>malloc(n_dates * sizeof(TRatePt)) + curve.fBaseDate = today_c + curve.fBasis = <double>CONTINUOUS + curve.fDayCountConv = ACT_360 + ptr = curve.fArray + for i in range(n_dates): + ptr.fDate = end_dates_c[i] + ptr.fRate = JPMCDS_MAX_RATE + preinc(ptr) + if curve is not NULL: if fill_curve and curve.fNumItems != n_dates: new_curve = _fill_curve(curve, end_dates_c, n_dates) |
