From 6bb86980f7b924b322c8a38b60ecdf44e9b6f1af Mon Sep 17 00:00:00 2001 From: Guillaume Horel Date: Wed, 25 Jan 2023 23:31:21 -0500 Subject: make cal_file a C++ string --- pyisda/credit_index.pxd | 2 +- pyisda/credit_index.pyx | 16 ++++++++-------- pyisda/legs.pxd | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/pyisda/credit_index.pxd b/pyisda/credit_index.pxd index 1a07a6f..e355eb8 100644 --- a/pyisda/credit_index.pxd +++ b/pyisda/credit_index.pxd @@ -20,7 +20,7 @@ cdef class CreditIndex(CurveList): cdef vector[TDate] _maturities cdef TContingentLeg** contingent_legs cdef TFeeLeg** fee_legs - cdef readonly char[30] cal_file + cdef readonly string cal_file cdef copy(CurveList orig, CurveList copy) diff --git a/pyisda/credit_index.pyx b/pyisda/credit_index.pyx index 57cd48c..861a103 100644 --- a/pyisda/credit_index.pyx +++ b/pyisda/credit_index.pyx @@ -257,7 +257,7 @@ cdef class CreditIndex(CurveList): cdef size_t i cdef pair[TContingentLeg_ptr, TFeeLeg_ptr] r for i in range(self._maturities.size()): - r = get_legs(self._maturities[i], self._start_date, self.cal_file) + r = get_legs(self._maturities[i], self._start_date, self.cal_file.c_str()) self.contingent_legs[i] = r.first self.fee_legs[i] = r.second @@ -300,14 +300,14 @@ cdef class CreditIndex(CurveList): copy.fee_legs[i] = malloc(sizeof(TFeeLeg)) fee_leg_copy(fl, copy.fee_legs[i]) - strcpy(copy.cal_file, self.cal_file) + copy.cal_file = self.cal_file memo[id(self)] = copy return copy def __reduce__(self): return (self.__class__, (self.start_date, self.maturities, self.curves, - TDate_to_pydate(self.base_date), self.cal_file)) + TDate_to_pydate(self.base_date), self.cal_file.c_str())) def __hash__(self): cdef: @@ -402,7 +402,7 @@ cdef class CreditIndex(CurveList): int i = get_maturity_index(maturity_c, self._maturities) if i == -1: - legs = get_legs(maturity_c, self._start_date, self.cal_file) + legs = get_legs(maturity_c, self._start_date, self.cal_file.c_str()) else: legs.first = self.contingent_legs[i] legs.second = self.fee_legs[i] @@ -448,7 +448,7 @@ cdef class CreditIndex(CurveList): i = get_maturity_index(maturity_c, self._maturities) if i == -1: legs = get_legs(maturity_c, - self._start_date, self.cal_file) + self._start_date, self.cal_file.c_str()) else: legs.first = self.contingent_legs[i] legs.second = self.fee_legs[i] @@ -463,7 +463,7 @@ cdef class CreditIndex(CurveList): i = get_maturity_index(maturity_c, self._maturities) if i == -1: legs = get_legs(maturity_c, - self._start_date, self.cal_file) + self._start_date, self.cal_file.c_str()) else: legs.first = self.contingent_legs[i] legs.second = self.fee_legs[i] @@ -581,7 +581,7 @@ cdef class CreditIndex(CurveList): self._maturities[i] = pydate_to_TDate(val[i]) free(self.contingent_legs[i]) JpmcdsFeeLegFree(self.fee_legs[i]) - r = get_legs(self._maturities[i], self._start_date, self.cal_file) + r = get_legs(self._maturities[i], self._start_date, self.cal_file.c_str()) self.contingent_legs[i] = r.first self.fee_legs[i] = r.second @@ -844,7 +844,7 @@ cdef inline int get_maturity_index(TDate maturity, const vector[TDate]& maturiti return i cdef pair[TContingentLeg_ptr, TFeeLeg_ptr] get_legs(TDate maturity, - TDate start_date, char* cal) nogil: + TDate start_date, const char* cal) nogil: cdef: pair[TContingentLeg_ptr, TFeeLeg_ptr] r TStubMethod stub_type diff --git a/pyisda/legs.pxd b/pyisda/legs.pxd index bd35530..6a31c17 100644 --- a/pyisda/legs.pxd +++ b/pyisda/legs.pxd @@ -70,7 +70,7 @@ cdef extern from "isda/cds.h" nogil: long badDayConv, # Calendar used when adjusting coupon dates. Can be NULL which equals # a calendar with no holidays and including weekends. - char *calendar, + const char *calendar, # Should protection include the start date */ TBoolean protectStart) -- cgit v1.2.3-70-g09d2