summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuillaume Horel <guillaume.horel@gmail.com>2018-03-05 16:33:35 -0500
committerGuillaume Horel <guillaume.horel@gmail.com>2018-03-05 16:33:35 -0500
commit41c8ef50fcc810e029be41b89b5af982aa487704 (patch)
tree5f1ebbda52cadb93c053c9d41fa0f295684dc91b
parent94d164973708051270527355b62d242698640873 (diff)
downloadpyisda-41c8ef50fcc810e029be41b89b5af982aa487704.tar.gz
do not bomb when passing None curve
-rw-r--r--pyisda/credit_index.pyx27
1 files changed, 17 insertions, 10 deletions
diff --git a/pyisda/credit_index.pyx b/pyisda/credit_index.pyx
index 6731ca9..2f156a8 100644
--- a/pyisda/credit_index.pyx
+++ b/pyisda/credit_index.pyx
@@ -20,6 +20,7 @@ cimport numpy as np
np.import_array()
import numpy as np
import pandas as pd
+import warnings
cdef inline shared_ptr[TCurve] make_shared(TCurve* ptr) nogil:
return shared_ptr[TCurve](ptr, JpmcdsFreeTCurve)
@@ -66,20 +67,20 @@ cdef class CurveList:
self.T[i] = (sc._thisptr.get().fArray[i].fDate - self.base_date) / 365.
i = 0
+ cdef int n_skipped = 0
for sc in curves:
- it = self.tickers.find(sc.ticker)
- if it == self.tickers.end():
- self.tickers[sc.ticker] = i
- if sc is not None:
+ if sc is not None:
+ it = self.tickers.find(sc.ticker)
+ if it == self.tickers.end():
+ self.tickers[sc.ticker] = i
self._curves.push_back(sc._thisptr)
self.recovery_rates.push_back(sc.recovery_rates)
+ self._weights.push_back(1.)
+ i += 1
else:
- self._curves.push_back(shared_ptr[TCurve]())
- self.recovery_rates.push_back(shared_ptr[double]())
- self._weights.push_back(1.)
- i += 1
+ self._weights[deref(it).second] += 1
else:
- self._weights[deref(it).second] += 1
+ n_skipped += 1
if weights is not None:
for i in range(weights.shape[0]):
@@ -88,6 +89,9 @@ cdef class CurveList:
for i in range(self._curves.size()):
self._weights[i] /= n
+ if n_skipped > 0:
+ warnings.warn(f"skipped {n_skipped} empty curves")
+
def __getitem__(self, str ticker):
cdef:
string ticker_cpp = ticker.encode()
@@ -325,7 +329,10 @@ cdef class CreditIndex(CurveList):
cdef:
TDate step_in_date_c = pydate_to_TDate(step_in_date)
TDate value_date_c = pydate_to_TDate(value_date)
- np.npy_intp[2] n = [self._curves.size(), self._maturities.size()]
+ np.npy_intp[2] n
+ n[0] = self._curves.size()
+ n[1] = self._maturities.size()
+ cdef:
size_t i = 0, j = 0
np.ndarray[np.float64_t,ndim=2] cl_pv = np.PyArray_EMPTY(2, n, np.NPY_DOUBLE, 0)
np.ndarray[np.float64_t,ndim=2] fl_pv = np.PyArray_EMPTY(2, n, np.NPY_DOUBLE, 0)