From e2dab76d3519d3de7f22ca8eeb93e8184431593e Mon Sep 17 00:00:00 2001 From: Guillaume Horel Date: Fri, 22 Feb 2019 11:02:14 -0500 Subject: switch to level 3 --- pyisda/cdsone.pxd | 4 ++-- pyisda/cdsone.pyx | 8 ++++---- pyisda/credit_index.pxd | 6 +++--- pyisda/credit_index.pyx | 19 +++++++++---------- pyisda/curve.pxd | 4 ++-- pyisda/curve.pyx | 19 +++++++++++-------- pyisda/date.pyx | 2 +- pyisda/legs.pxd | 6 +++--- pyisda/legs.pyx | 8 ++++---- pyisda/optim.pyx | 10 +++++----- setup.py | 2 +- 11 files changed, 45 insertions(+), 43 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/credit_index.pxd b/pyisda/credit_index.pxd index aa77883..4895ecf 100644 --- a/pyisda/credit_index.pxd +++ b/pyisda/credit_index.pxd @@ -1,6 +1,6 @@ -from legs cimport TContingentLeg, TFeeLeg -from date cimport TDate -from curve cimport TCurve, TRatePt, shared_ptr +from .legs cimport TContingentLeg, TFeeLeg +from .date cimport TDate +from .curve cimport TCurve, shared_ptr from libcpp.vector cimport vector from libcpp.map cimport map from libcpp.string cimport string diff --git a/pyisda/credit_index.pyx b/pyisda/credit_index.pyx index 5d8ee65..bec58e2 100644 --- a/pyisda/credit_index.pyx +++ b/pyisda/credit_index.pyx @@ -9,15 +9,14 @@ from cpython cimport PyObject, Py_INCREF from cython.parallel cimport prange, parallel cimport cython -from legs cimport (JpmcdsCdsContingentLegMake, JpmcdsCdsFeeLegMake, +from .legs cimport (JpmcdsCdsContingentLegMake, JpmcdsCdsFeeLegMake, JpmcdsContingentLegPV, JpmcdsFeeLegPV, FeeLegAI, JpmcdsFeeLegFree) -from curve cimport (SpreadCurve, JpmcdsCopyCurve, tweak_curve, YieldCurve, - JpmcdsFreeTCurve, survival_prob, Hash64WithSeed, - Hash64, uint64_t, TCurve_size, serialize) -from date cimport (pydate_to_TDate, TDate_to_pydate, ACT_365F, JpmcdsDtFwdAny, +from .curve cimport (SpreadCurve, JpmcdsCopyCurve, tweak_curve, YieldCurve, + JpmcdsFreeTCurve, Hash64WithSeed, Hash64, uint64_t, serialize, TRatePt, TCurve_size, survival_prob) +from .date cimport (pydate_to_TDate, TDate_to_pydate, ACT_365F, JpmcdsDtFwdAny, TDateInterval, JpmcdsMakeDateInterval) -from cdsone cimport JpmcdsStringToStubMethod, TStubMethod -from date cimport ACT_365F +from .cdsone cimport JpmcdsStringToStubMethod, TStubMethod +from .date cimport ACT_365F cimport numpy as np np.import_array() import pandas as pd @@ -402,7 +401,7 @@ cdef class CreditIndex(CurveList): int i double carry if theta_date is None: - JpmcdsMakeDateInterval(-1, "Y", &ivl) + JpmcdsMakeDateInterval(-1, b"Y", &ivl) JpmcdsDtFwdAny(maturity_c, &ivl, &temp) carry = fixed_rate * 365 / 360 else: @@ -467,7 +466,7 @@ cdef class CreditIndex(CurveList): 1., 1.0, 3, # ACT_360 - 'M', # MODIFIED + b'M', # MODIFIED b'NONE', True) else: @@ -596,7 +595,7 @@ cdef pair[TContingentLeg_ptr, TFeeLeg_ptr] get_legs(TDate maturity, 1., 1.0, 3, # ACT_360 - 'M', # MODIFIED + b'M', # MODIFIED b'NONE', True) return r diff --git a/pyisda/curve.pxd b/pyisda/curve.pxd index 16eab8a..cbf826a 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 4dddb14..1f76c69 100644 --- a/pyisda/curve.pyx +++ b/pyisda/curve.pyx @@ -1,12 +1,14 @@ +# cython: c_string_type=unicode, c_string_encoding=ascii +from cython.operator cimport dereference as deref 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 cimport _previous_twentieth, _roll_date +from .cdsone cimport JpmcdsStringToStubMethod, TStubMethod +from .legs cimport (JpmcdsCdsContingentLegMake, JpmcdsCdsFeeLegMake, JpmcdsContingentLegPV, JpmcdsFeeLegPV, FeeLegAI, JpmcdsFeeLegFree) cimport cython @@ -477,7 +479,7 @@ cdef class SpreadCurve(Curve): cash_settle_date, end_dates, double[:] coupon_rates, double[:] upfront_rates, double[:] recovery_rates, bint pay_accrued_on_default=True, - str ticker=None, bint fill_curve=True): + str ticker="", bint fill_curve=True): cdef TDate today_c = pydate_to_TDate(today) cdef TDate step_in_date_c @@ -557,7 +559,7 @@ cdef class SpreadCurve(Curve): NULL, ACT_360, &stub_type, - 'M', + b'M', b'NONE') if curve is NULL: if freeup: @@ -666,7 +668,8 @@ cdef class SpreadCurve(Curve): @classmethod def from_flat_hazard(cls, base_date, double rate, Basis basis=CONTINUOUS, - str day_count_conv='Actual/365F'): + str day_count_conv='Actual/365F', double recovery=0.4, + str ticker=""): """ Alternative constructor for flat hazard rate Curve. @@ -760,7 +763,7 @@ cdef class SpreadCurve(Curve): NULL, &stub_type, ACT_360, - 'M', + 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 fa82629..b5bf312 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 cimport pydate_to_TDate, TDate_to_pydate, dcc from date import dcc_tostring -from cdsone cimport JpmcdsStringToStubMethod, TStubMethod -from curve cimport YieldCurve, SpreadCurve +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), - 'M', + b'M', b'NONE', protect_start) if self._thisptr is NULL: diff --git a/pyisda/optim.pyx b/pyisda/optim.pyx index 540a10b..a3a4143 100644 --- a/pyisda/optim.pyx +++ b/pyisda/optim.pyx @@ -2,11 +2,11 @@ from libc.stdlib cimport abort from libc.stdlib cimport free, malloc from libc.stdio cimport printf from libc.math cimport exp, sqrt -from cdsone cimport JpmcdsStringToStubMethod, TStubMethod -from curve cimport (TCurve, YieldCurve, JpmcdsFreeTCurve, JpmcdsNewTCurve, +from .cdsone cimport JpmcdsStringToStubMethod, TStubMethod +from .curve cimport (TCurve, YieldCurve, JpmcdsFreeTCurve, JpmcdsNewTCurve, CONTINUOUS) -from date cimport TDate, pydate_to_TDate, ACT_360, ACT_365F -from legs cimport (JpmcdsCdsContingentLegMake, JpmcdsCdsFeeLegMake, +from .date cimport TDate, pydate_to_TDate, ACT_360, ACT_365F +from .legs cimport (JpmcdsCdsContingentLegMake, JpmcdsCdsFeeLegMake, TContingentLeg, JpmcdsFeeLegPV, JpmcdsFeeLegFree, TFeeLeg) cimport cython @@ -88,7 +88,7 @@ def init_context(YieldCurve yc not None, trade_date, value_date, start_date, 1., # notional 1., # coupon_rate ACT_360, # JPMCDS_ACT_360 - 'M', + b'M', b'NONE', 1) # protect_start = True params.stepinDate = step_in_date_c diff --git a/setup.py b/setup.py index 68e589c..35005d8 100644 --- a/setup.py +++ b/setup.py @@ -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"}, ) -- cgit v1.2.3-70-g09d2