summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuillaume Horel <guillaume.horel@gmail.com>2017-02-07 17:57:38 -0500
committerGuillaume Horel <guillaume.horel@gmail.com>2017-02-07 17:57:38 -0500
commit6e275360fd0e59880b69d72f4b9b5fef8893230e (patch)
treefa2b7dac52b5fbff6683c1b2942261db03591a7b
parentfeaf5cf91a15bbf94d037c68faa870363929c465 (diff)
downloadpyisda-6e275360fd0e59880b69d72f4b9b5fef8893230e.tar.gz
try to release the gil
-rw-r--r--pyisda/curve.pyx44
-rw-r--r--pyisda/date.pxd2
2 files changed, 25 insertions, 21 deletions
diff --git a/pyisda/curve.pyx b/pyisda/curve.pyx
index 4c0a1d3..de64437 100644
--- a/pyisda/curve.pyx
+++ b/pyisda/curve.pyx
@@ -2,9 +2,10 @@ from libc.stdlib cimport malloc, free
from libc.string cimport memcpy
from date cimport (JpmcdsStringToDateInterval, pydate_to_TDate, dcc,
JpmcdsDateIntervalToFreq, JpmcdsDateFwdThenAdjust, TDate_to_pydate,
- JpmcdsDateFromBusDaysOffset)
+ JpmcdsDateFromBusDaysOffset, JpmcdsStringToDayCountConv)
from date import dcc_tostring
from cdsone cimport JpmcdsStringToStubMethod, TStubMethod
+cimport cython
cdef int SUCCESS = 0
@@ -261,7 +262,8 @@ cdef class SpreadCurve(Curve):
cdef TDate step_in_date_c = pydate_to_TDate(step_in_date)
cdef TDate cash_settle_date_c = pydate_to_TDate(cash_settle_date)
cdef TDate start_date_c = pydate_to_TDate(start_date)
- cdef TDate* end_dates_c = <TDate*>malloc(len(end_dates) * sizeof(TDate))
+ cdef int n_dates = len(end_dates)
+ cdef TDate* end_dates_c = <TDate*>malloc(n_dates * sizeof(TDate))
self._thisptr = NULL
cdef size_t i
if cash_settle_date < yc.inspect()['base_date']:
@@ -273,24 +275,26 @@ cdef class SpreadCurve(Curve):
cdef TStubMethod stub_type
if JpmcdsStringToStubMethod(b"f/s", &stub_type) != 0:
raise ValueError("can't convert stub")
-
- self._thisptr = JpmcdsCleanSpreadCurve(today_c,
- yc._thisptr,
- start_date_c,
- step_in_date_c,
- cash_settle_date_c,
- len(end_dates),
- end_dates_c,
- &coupon_rates[0],
- &upfront_rates[0],
- NULL,
- &recovery_rates[0],
- pay_accrued_on_default,
- NULL,
- dcc('ACT/360'),
- &stub_type,
- <long>'M',
- b'NONE')
+ cdef long dc
+ JpmcdsStringToDayCountConv('ACT/360', &dc)
+ with nogil, cython.boundscheck(False):
+ self._thisptr = JpmcdsCleanSpreadCurve(today_c,
+ yc._thisptr,
+ start_date_c,
+ step_in_date_c,
+ cash_settle_date_c,
+ n_dates,
+ end_dates_c,
+ &coupon_rates[0],
+ &upfront_rates[0],
+ NULL,
+ &recovery_rates[0],
+ pay_accrued_on_default,
+ NULL,
+ dc,
+ &stub_type,
+ <long>'M',
+ b'NONE')
if self._thisptr == NULL:
raise ValueError("something went wrong")
diff --git a/pyisda/date.pxd b/pyisda/date.pxd
index 755467f..0ba719a 100644
--- a/pyisda/date.pxd
+++ b/pyisda/date.pxd
@@ -1,6 +1,6 @@
from cpython cimport datetime as c_datetime
-cdef extern from "isda/yearfrac.h":
+cdef extern from "isda/yearfrac.h" nogil:
int JpmcdsStringToDayCountConv(char* day_count, long* type)
char* JpmcdsFormatDayCountConv(long dayCountConv)