summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--pyisda/curve.pxd35
-rw-r--r--pyisda/curve.pyx20
2 files changed, 23 insertions, 32 deletions
diff --git a/pyisda/curve.pxd b/pyisda/curve.pxd
index 8226fe9..577961a 100644
--- a/pyisda/curve.pxd
+++ b/pyisda/curve.pxd
@@ -6,7 +6,7 @@ from libcpp cimport bool
from libcpp.string cimport string
from libc.string cimport memcpy, memmove
from libc.stdlib cimport malloc, realloc, free
-from libc.stdint cimport uint64_t, uint16_t
+from libc.stdint cimport uint64_t, uint16_t, uint8_t
cdef extern from "isda/zerocurve.h" nogil:
ctypedef int TBoolean
@@ -182,18 +182,20 @@ cdef extern from "<string_view>" namespace "std" nogil:
string.iterator begin()
string.iterator end()
-cdef extern from "survival_curve.hpp" nogil:
- cdef cppclass CurveName:
- enum Seniority:
- Senior
- Subordinated
+cdef extern from "survival_curve.hpp" namespace "CurveName" nogil:
+ cpdef enum class DocClause(uint8_t):
+ XR14
+ MR14
+ MM14
+ CR14
- enum DocClause:
- XR14
- MR14
- MM14
- CR14
+ cpdef enum class Seniority(uint8_t):
+ Senior
+ Subordinated
+ SLA
+cdef extern from "survival_curve.hpp" nogil:
+ cdef cppclass CurveName:
string_view ticker
Seniority seniority
DocClause doc_clause
@@ -204,17 +206,6 @@ cdef extern from "survival_curve.hpp" nogil:
string full_ticker()
size_t size()
-cpdef enum DocClause:
- XR14
- MR14
- MM14
- CR14
-
-cpdef enum Seniority:
- Senior
- Subordinated
- SLA
-
cdef inline const TCurve* get_TCurve(Curve c) nogil:
return <TCurve*>c.buf.get()
diff --git a/pyisda/curve.pyx b/pyisda/curve.pyx
index 9b42ba2..b5c2d5d 100644
--- a/pyisda/curve.pyx
+++ b/pyisda/curve.pyx
@@ -416,7 +416,7 @@ cdef class YieldCurve(Curve):
@classmethod
- def from_discount_factors(cls, base_date, list dates, double[:] dfs, str day_count_conv, Basis basis=CONTINUOUS):
+ def from_discount_factors(cls, base_date, list dates, double[:] dfs, str day_count_conv, Basis basis=Basis.CONTINUOUS):
""" build a yield curve from a list of discount factors """
cdef YieldCurve yc = YieldCurve.__new__(YieldCurve)
yc.buf_size = sizeof(TCurve) + len(dates) * sizeof(TRatePt)
@@ -436,7 +436,7 @@ cdef class YieldCurve(Curve):
return yc
@classmethod
- def from_zero_rates(cls, base_date, list dates, double[:] rates, str day_count_conv, Basis basis=CONTINUOUS):
+ def from_zero_rates(cls, base_date, list dates, double[:] rates, str day_count_conv, Basis basis=Basis.CONTINUOUS):
""" build a yield curve from a list of discount factors """
cdef YieldCurve yc = YieldCurve.__new__(YieldCurve)
yc.buf_size = sizeof(TCurve) + len(dates) * sizeof(TRatePt)
@@ -568,9 +568,9 @@ cdef void tweak_curve(const TCurve* sc, TCurve* sc_tweaked, double epsilon,
t1 = t2
cdef size_t buf_size(int n, int ticker_len) nogil:
- return sizeof(TCurve) + n * sizeof(TRatePt) + n * sizeof(double) + sizeof(TDate) + sizeof(CurveName.DocClause) + sizeof(CurveName.Seniority) + ticker_len + 1
+ return sizeof(TCurve) + n * sizeof(TRatePt) + n * sizeof(double) + sizeof(TDate) + sizeof(DocClause) + sizeof(Seniority) + ticker_len + 1
-cdef uint16_t name_offset_from_buf(char* buf) nogil:
+cdef uint16_t name_offset_from_buf(const char* buf) nogil:
cdef TCurve* curve = <TCurve*>buf
cdef int n = curve.fNumItems
return sizeof(TCurve) + n * (sizeof(TRatePt) + sizeof(double)) + sizeof(TDate)
@@ -606,8 +606,8 @@ cdef class SpreadCurve(Curve):
cash_settle_date, end_dates,
const double[:] coupon_rates, const double[:] upfront_rates,
const double[:] recovery_rates, bint pay_accrued_on_default=True,
- str ticker="", Seniority seniority=Senior,
- DocClause doc_clause=XR14,
+ str ticker="", Seniority seniority=Seniority.Senior,
+ DocClause doc_clause=DocClause.XR14,
bint fill_curve=True, defaulted=None,
str calendar="NONE"):
@@ -729,7 +729,7 @@ cdef class SpreadCurve(Curve):
curve = <TCurve*>buf
curve.fNumItems = n_dates
curve.fBaseDate = today_c
- curve.fBasis = <double>CONTINUOUS
+ curve.fBasis = <double>Basis.CONTINUOUS
curve.fDayCountConv = ACT_360
ptr = curve.fArray
for i in range(n_dates):
@@ -1000,11 +1000,11 @@ cdef class SpreadCurve(Curve):
@property
def seniority(self):
- return Seniority(<int>self.name()[0])
+ return <Seniority>self.name()[0]
@property
def doc_clause(self):
- return DocClause(<int>self.name()[1])
+ return <DocClause>self.name()[1]
@cython.cdivision(True)
@@ -1017,7 +1017,7 @@ cdef void _fill_curve(const TCurve* sc, const TDate* end_dates, int n_dates, cha
TCurve* curve = <TCurve*>buf
curve.fNumItems = n_dates
curve.fBaseDate = base_date
- curve.fBasis = <double>CONTINUOUS
+ curve.fBasis = <double>Basis.CONTINUOUS
curve.fDayCountConv = ACT_365F
cdef TRatePt* it = curve.fArray