diff options
| author | Guillaume Horel <guillaume.horel@gmail.com> | 2017-02-27 16:53:22 -0500 |
|---|---|---|
| committer | Guillaume Horel <guillaume.horel@gmail.com> | 2017-02-27 16:53:22 -0500 |
| commit | c2e4e417950ab3334c6bf5c8c78e9073f5b8fea5 (patch) | |
| tree | 654f63d38e1d42fddbff23b84262be63333a1109 | |
| parent | ed550ff89a0dae0e771dfa773e828bc36aa600f8 (diff) | |
| download | pyisda-c2e4e417950ab3334c6bf5c8c78e9073f5b8fea5.tar.gz | |
add weights, we might need them later on
| -rw-r--r-- | pyisda/credit_index.pxd | 1 | ||||
| -rw-r--r-- | pyisda/credit_index.pyx | 13 |
2 files changed, 10 insertions, 4 deletions
diff --git a/pyisda/credit_index.pxd b/pyisda/credit_index.pxd index ed0d0b1..787cd15 100644 --- a/pyisda/credit_index.pxd +++ b/pyisda/credit_index.pxd @@ -6,6 +6,7 @@ from libcpp.vector cimport vector cdef class CurveList: cdef TDate _base_date cdef vector[shared_ptr[TCurve]] _curves + cdef vector[double] _weights cdef vector[double] _T cdef list _tickers cdef dict _tickersdict diff --git a/pyisda/credit_index.pyx b/pyisda/credit_index.pyx index c37c214..f65bedb 100644 --- a/pyisda/credit_index.pyx +++ b/pyisda/credit_index.pyx @@ -13,7 +13,8 @@ np.import_array() import pandas as pd cdef class CurveList: - def __init__(self, curves, tickers=None): + @cython.cdivision(True) + def __init__(self, curves, tickers=None, double[:] weights=None): cdef SpreadCurve sc if isinstance(curves[0], tuple): sc = <SpreadCurve?>(curves[0][1]) @@ -45,6 +46,11 @@ cdef class CurveList: else: self._tickers = tickers self._tickersdict = {t: i for i, t in enumerate(tickers)} + if weights is not None: + for i in range(weights.shape[0]): + self._weights.push_back(weights[i]) + else: + self._weights = vector[double](self._curves.size(), 1./self._curves.size()) def __getitem__(self, str ticker): cdef SpreadCurve sc @@ -90,8 +96,8 @@ cdef class CurveList: self._curves[i] = (<SpreadCurve?>c)._thisptr cdef class CreditIndex(CurveList): - def __init__(self, start_date, maturities, curves): - CurveList.__init__(self, curves) + def __init__(self, start_date, maturities, curves, double[:] weights=None): + CurveList.__init__(self, curves, weights) cdef TDate start_date_c = pydate_to_TDate(start_date) for d in maturities: self._maturities.push_back(pydate_to_TDate(d)) @@ -172,7 +178,6 @@ cdef class CreditIndex(CurveList): index=self._tickers)}) @cython.boundscheck(False) - @cython.cdivision(True) def pv(self, step_in_date, value_date, maturity, YieldCurve yc not None, double recovery_rate, double fixed_rate, double epsilon=0.): |
