diff options
| author | Guillaume Horel <guillaume.horel@gmail.com> | 2018-11-30 13:23:41 -0500 |
|---|---|---|
| committer | Guillaume Horel <guillaume.horel@gmail.com> | 2018-11-30 13:23:41 -0500 |
| commit | 382b21a9f1b0654f838645e0e9748385116b44bf (patch) | |
| tree | 7f1b2d93179bf4e2c6cde6c27b692d370dda0a0f | |
| parent | 5e016a8d71bddf68be521fbfc51ce468ef679a79 (diff) | |
| download | pyisda-382b21a9f1b0654f838645e0e9748385116b44bf.tar.gz | |
turn on level 3
| -rw-r--r-- | pyisda/cdsone.pxd | 4 | ||||
| -rw-r--r-- | pyisda/cdsone.pyx | 8 | ||||
| -rw-r--r-- | pyisda/curve.pxd | 4 | ||||
| -rw-r--r-- | pyisda/curve.pyx | 14 | ||||
| -rw-r--r-- | pyisda/date.pyx | 2 | ||||
| -rw-r--r-- | pyisda/legs.pxd | 6 | ||||
| -rw-r--r-- | pyisda/legs.pyx | 10 | ||||
| -rw-r--r-- | pyisda/optim_api.h | 86 | ||||
| -rw-r--r-- | setup.py | 2 |
9 files changed, 111 insertions, 25 deletions
diff --git a/pyisda/cdsone.pxd b/pyisda/cdsone.pxd index 0f446ba..d40a7f2 100644 --- a/pyisda/cdsone.pxd +++ b/pyisda/cdsone.pxd @@ -1,5 +1,5 @@ -from date cimport TDateInterval -from curve cimport TCurve +from .date cimport TDateInterval +from .curve cimport TCurve cdef extern from "isda/stub.h" nogil: ctypedef struct TStubMethod: diff --git a/pyisda/cdsone.pyx b/pyisda/cdsone.pyx index e2f78a0..5dd8040 100644 --- a/pyisda/cdsone.pyx +++ b/pyisda/cdsone.pyx @@ -1,5 +1,5 @@ -from curve cimport YieldCurve -from date cimport JpmcdsMakeDateInterval, pydate_to_TDate, dcc +from .curve cimport YieldCurve +from .date cimport JpmcdsMakeDateInterval, pydate_to_TDate, dcc cdef int SUCCESS = 0 @@ -55,7 +55,7 @@ def upfront_charge(date, value_date, benchmark_start_date, stepin_date, if JpmcdsStringToStubMethod(b"f/s", &stub) != SUCCESS: raise ValueError("can't convert stub") - if JpmcdsMakeDateInterval(3, "M", &ivl) != SUCCESS: + if JpmcdsMakeDateInterval(3, b"M", &ivl) != SUCCESS: raise ValueError("can't convert to date interval") if JpmcdsCdsoneUpfrontCharge(today, value_date_c, benchmark_start_date_c, stepin_date_c, start_date_c, end_date_c, coupon_rate, pay_accrued_on_default, @@ -116,7 +116,7 @@ def spread_from_upfront(date, value_date, benchmark_start_date, stepin_date, if JpmcdsStringToStubMethod(b"f/s", &stub) != SUCCESS: raise ValueError("can't convert stub") - if JpmcdsMakeDateInterval(3, "M", &ivl) != SUCCESS: + if JpmcdsMakeDateInterval(3, b"M", &ivl) != SUCCESS: raise ValueError("can't convert to date interval") if JpmcdsCdsoneSpread(today, value_date_c, benchmark_start_date_c, stepin_date_c, start_date_c, end_date_c, coupon_rate, pay_accrued_on_default, diff --git a/pyisda/curve.pxd b/pyisda/curve.pxd index e0bb094..d996a68 100644 --- a/pyisda/curve.pxd +++ b/pyisda/curve.pxd @@ -1,5 +1,5 @@ -from cdsone cimport TStubMethod -from legs cimport TContingentLeg, TFeeLeg +from .cdsone cimport TStubMethod +from .legs cimport TContingentLeg, TFeeLeg from libcpp.vector cimport vector from libcpp cimport bool from libcpp.string cimport string diff --git a/pyisda/curve.pyx b/pyisda/curve.pyx index 6aa54a7..b9cb886 100644 --- a/pyisda/curve.pyx +++ b/pyisda/curve.pyx @@ -1,12 +1,12 @@ from libc.math cimport log1p, log, exp, isnan -from date cimport (JpmcdsStringToDateInterval, pydate_to_TDate, dcc, TMonthDayYear, +from .date cimport (JpmcdsStringToDateInterval, pydate_to_TDate, dcc, TMonthDayYear, JpmcdsDateIntervalToFreq, JpmcdsDateFwdThenAdjust, TDate_to_pydate, JpmcdsDateFromBusDaysOffset, JpmcdsStringToDayCountConv, ACT_360, BadDay, FOLLOW, MODIFIED, NONE) -from date import dcc_tostring -from date cimport _previous_twentieth, _roll_date -from cdsone cimport JpmcdsStringToStubMethod, TStubMethod -from legs cimport (JpmcdsCdsContingentLegMake, JpmcdsCdsFeeLegMake, +from .date import dcc_tostring +from .date cimport _previous_twentieth, _roll_date +from .cdsone cimport JpmcdsStringToStubMethod +from .legs cimport (JpmcdsCdsContingentLegMake, JpmcdsCdsFeeLegMake, JpmcdsContingentLegPV, JpmcdsFeeLegPV, FeeLegAI, JpmcdsFeeLegFree) cimport cython @@ -588,7 +588,7 @@ cdef class SpreadCurve(Curve): NULL, ACT_360, &stub_type, - <long>'M', + <long>b'M', b'NONE') else: rates = vector[double](n_dates, JPMCDS_MAX_RATE) @@ -826,7 +826,7 @@ cdef class SpreadCurve(Curve): NULL, &stub_type, ACT_360, - <long>'M', + <long>b'M', b'NONE', yc._thisptr.get(), self._thisptr.get(), diff --git a/pyisda/date.pyx b/pyisda/date.pyx index 6bd30de..fba523e 100644 --- a/pyisda/date.pyx +++ b/pyisda/date.pyx @@ -178,7 +178,7 @@ def default_accrual(trade_date, edd, start_date, end_date, double notional, if JpmcdsStringToStubMethod(b"f/s", &stub) != SUCCESS: raise ValueError("can't convert stub") - if JpmcdsMakeDateInterval(3, "M", &ivl) != SUCCESS: + if JpmcdsMakeDateInterval(3, b"M", &ivl) != SUCCESS: raise ValueError("can't convert to date interval") if JpmcdsDefaultAccrual(trade_date_c, diff --git a/pyisda/legs.pxd b/pyisda/legs.pxd index 0dd0e0e..77b4230 100644 --- a/pyisda/legs.pxd +++ b/pyisda/legs.pxd @@ -1,6 +1,6 @@ -from date cimport TDateInterval -from cdsone cimport TStubMethod -from curve cimport TCurve +from .date cimport TDateInterval +from .cdsone cimport TStubMethod +from .curve cimport TCurve ctypedef int TBoolean ctypedef long TDate diff --git a/pyisda/legs.pyx b/pyisda/legs.pyx index 9f51d77..8a6d1e7 100644 --- a/pyisda/legs.pyx +++ b/pyisda/legs.pyx @@ -1,8 +1,8 @@ from libc.stdlib cimport free -from date cimport pydate_to_TDate, TDate_to_pydate, dcc -from date import dcc_tostring -from cdsone cimport JpmcdsStringToStubMethod, TStubMethod -from curve cimport YieldCurve, SpreadCurve +from .date cimport pydate_to_TDate, TDate_to_pydate, dcc +from .date import dcc_tostring +from .cdsone cimport JpmcdsStringToStubMethod, TStubMethod +from .curve cimport YieldCurve, SpreadCurve cdef class ContingentLeg: """ @@ -113,7 +113,7 @@ cdef class FeeLeg: notional, coupon_rate, dcc(payment_dcc), - <long>'M', + <long>b'M', b'NONE', protect_start) if self._thisptr is NULL: diff --git a/pyisda/optim_api.h b/pyisda/optim_api.h new file mode 100644 index 0000000..9a7d8c3 --- /dev/null +++ b/pyisda/optim_api.h @@ -0,0 +1,86 @@ +/* Generated by Cython 0.29.1 */ + +#ifndef __PYX_HAVE_API__pyisda__optim +#define __PYX_HAVE_API__pyisda__optim +#ifdef __MINGW64__ +#define MS_WIN64 +#endif +#include "Python.h" + +static double (*__pyx_api_f_6pyisda_5optim_pv)(double, void *) = 0; +#define pv __pyx_api_f_6pyisda_5optim_pv +#if !defined(__Pyx_PyIdentifier_FromString) +#if PY_MAJOR_VERSION < 3 + #define __Pyx_PyIdentifier_FromString(s) PyString_FromString(s) +#else + #define __Pyx_PyIdentifier_FromString(s) PyUnicode_FromString(s) +#endif +#endif + +#ifndef __PYX_HAVE_RT_ImportFunction +#define __PYX_HAVE_RT_ImportFunction +static int __Pyx_ImportFunction(PyObject *module, const char *funcname, void (**f)(void), const char *sig) { + PyObject *d = 0; + PyObject *cobj = 0; + union { + void (*fp)(void); + void *p; + } tmp; + d = PyObject_GetAttrString(module, (char *)"__pyx_capi__"); + if (!d) + goto bad; + cobj = PyDict_GetItemString(d, funcname); + if (!cobj) { + PyErr_Format(PyExc_ImportError, + "%.200s does not export expected C function %.200s", + PyModule_GetName(module), funcname); + goto bad; + } +#if PY_VERSION_HEX >= 0x02070000 + if (!PyCapsule_IsValid(cobj, sig)) { + PyErr_Format(PyExc_TypeError, + "C function %.200s.%.200s has wrong signature (expected %.500s, got %.500s)", + PyModule_GetName(module), funcname, sig, PyCapsule_GetName(cobj)); + goto bad; + } + tmp.p = PyCapsule_GetPointer(cobj, sig); +#else + {const char *desc, *s1, *s2; + desc = (const char *)PyCObject_GetDesc(cobj); + if (!desc) + goto bad; + s1 = desc; s2 = sig; + while (*s1 != '\0' && *s1 == *s2) { s1++; s2++; } + if (*s1 != *s2) { + PyErr_Format(PyExc_TypeError, + "C function %.200s.%.200s has wrong signature (expected %.500s, got %.500s)", + PyModule_GetName(module), funcname, sig, desc); + goto bad; + } + tmp.p = PyCObject_AsVoidPtr(cobj);} +#endif + *f = tmp.fp; + if (!(*f)) + goto bad; + Py_DECREF(d); + return 0; +bad: + Py_XDECREF(d); + return -1; +} +#endif + + +static int import_pyisda__optim(void) { + PyObject *module = 0; + module = PyImport_ImportModule("pyisda.optim"); + if (!module) goto bad; + if (__Pyx_ImportFunction(module, "pv", (void (**)(void))&__pyx_api_f_6pyisda_5optim_pv, "double (double, void *)") < 0) goto bad; + Py_DECREF(module); module = 0; + return 0; + bad: + Py_XDECREF(module); + return -1; +} + +#endif /* !__PYX_HAVE_API__pyisda__optim */ @@ -25,7 +25,7 @@ all_extensions = cythonize( [c_extension, all_extensions], nthreads=4, compiler_directives={"embedsignature": True, - "language_level": 2, + "language_level": 3, "c_string_type": "unicode", "c_string_encoding": "ascii"}, ) |
