summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--pyisda/credit_index.pyx18
1 files changed, 11 insertions, 7 deletions
diff --git a/pyisda/credit_index.pyx b/pyisda/credit_index.pyx
index bde51d1..83c377e 100644
--- a/pyisda/credit_index.pyx
+++ b/pyisda/credit_index.pyx
@@ -89,6 +89,7 @@ cdef class CurveList:
for i in range(self._weights.size()):
self._weights[i] /= total_weight
+
def __getitem__(self, tuple name not None):
if len(name) != 3:
raise TypeError("`name` needs to be a string, Seniority, DocClause triplet")
@@ -126,11 +127,14 @@ cdef class CurveList:
@property
def weights(self):
- cdef np.npy_intp shape = self._weights.size()
- cdef np.ndarray[np.float64_t, ndim=1] out = \
- np.PyArray_SimpleNewFromData(1, &shape, np.NPY_DOUBLE, self._weights.data())
- out.base = <PyObject*>self
- Py_INCREF(self)
+ cdef:
+ np.npy_intp shape = self._weights.size()
+ pair[CurveName, size_t] p
+ np.ndarray out = np.PyArray_EMPTY(1, &shape, np.NPY_DOUBLE, 1)
+ int j = 0
+ for p in self.names:
+ out[j] = self._weights[p.second]
+ j += 1
return out
@weights.setter
@@ -638,7 +642,7 @@ cdef class CreditIndex(CurveList):
n[1] = self._maturities.size()
if self._maturities.back() < self.base_date:
raise ValueError("matured index")
- while deref(schedule_ptr) < self.base_date:
+ while deref(schedule_ptr) <= self.base_date:
preinc(schedule_ptr)
n[1] -=1
else:
@@ -695,7 +699,7 @@ cdef class CreditIndex(CurveList):
schedule_ptr = &schedule[0]
n = schedule.shape[0]
orig_size = n
- while deref(schedule_ptr) < self.base_date:
+ while deref(schedule_ptr) <= self.base_date:
preinc(schedule_ptr)
n -= 1