From c59f0796f75f825eb272ab3fce8649e0dd42deb6 Mon Sep 17 00:00:00 2001 From: Guillaume Horel Date: Fri, 21 Feb 2020 16:36:32 -0500 Subject: keep map order --- pyisda/credit_index.pyx | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/pyisda/credit_index.pyx b/pyisda/credit_index.pyx index 1071e80..4a83090 100644 --- a/pyisda/credit_index.pyx +++ b/pyisda/credit_index.pyx @@ -145,11 +145,15 @@ cdef class CurveList: @property def tickers(self): - cdef np.npy_intp shape = self.names.size() - cdef pair[CurveName, size_t] p - cdef np.ndarray out = np.PyArray_EMPTY(1, &shape, np.NPY_OBJECT, 1) + cdef: + np.npy_intp shape = self.names.size() + pair[CurveName, size_t] p + np.ndarray out = np.PyArray_EMPTY(1, &shape, np.NPY_OBJECT, 1) + int j = 0 + for p in self.names: - out[p.second] = p.first.ticker + out[j] = p.first.ticker + j += 1 return out @property @@ -627,7 +631,7 @@ cdef class CreditIndex(CurveList): pair[CurveName, size_t] p np.npy_intp[2] n const TDate* schedule_ptr - size_t i + size_t i, j = 0 if schedule is None: schedule_ptr = self._maturities.const_data() @@ -648,7 +652,8 @@ cdef class CreditIndex(CurveList): for p in self.names: if self.defaulted[p.second] != -1: for i in range(n[1]): - spreads_view[p.second, i] = nan("") + spreads_view[j, i] = nan("") + j += 1 continue sc = self._curves[p.second] JpmcdsCdsParSpreads( @@ -697,12 +702,11 @@ cdef class CreditIndex(CurveList): JpmcdsStringToStubMethod(b"f/s", &stub_type) with nogil: - - for p in self.names: - if self.defaulted[p.second] != -1: + for j in range(self._curves.size()): + if self.defaulted[j] != -1: continue - sc = self._curves[p.second] - w = self._weights[p.second] + sc = self._curves[j] + w = self._weights[j] JpmcdsCdsParSpreads( self.base_date, self.base_date + 1, @@ -717,7 +721,7 @@ cdef class CreditIndex(CurveList): b'NONE', get_TCurve(yc), sc.get(), - self.recovery_rates[p.second].get(), + self.recovery_rates[j].get(), spreads) if first_time: -- cgit v1.2.3-70-g09d2