summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuillaume Horel <guillaume.horel@serenitascapital.com>2016-10-26 10:37:53 -0400
committerGuillaume Horel <guillaume.horel@serenitascapital.com>2016-10-26 10:37:53 -0400
commit0f30291808b616925a37ea618495cf2519407753 (patch)
tree61c820ebbb23495bb0eed71382c176901ddfe19f
parent3e994c495065c371c4ee136146bb5dbb6512fa63 (diff)
downloadpyisda-0f30291808b616925a37ea618495cf2519407753.tar.gz
Add survival_probability
discount_factor and survival_probability are now defined in terms of forwardZeroPrice.
-rw-r--r--pyisda/curve.pxd5
-rw-r--r--pyisda/curve.pyx71
2 files changed, 43 insertions, 33 deletions
diff --git a/pyisda/curve.pxd b/pyisda/curve.pxd
index 29dabf4..52cfbed 100644
--- a/pyisda/curve.pxd
+++ b/pyisda/curve.pxd
@@ -82,16 +82,17 @@ cdef extern from "isda/tcurve.h":
double *rates,
int numPts,
double basis,
- long dayCountConv);
+ long dayCountConv)
cdef extern from "isda/cxzerocurve.h":
double JpmcdsZeroPrice(TCurve* curve, TDate date)
+ double JpmcdsForwardZeroPrice(TCurve* curve, TDate startDate, TDate maturityDate)
cdef extern from "isda/cfinanci.h":
int JpmcdsDiscountToRateYearFrac(double discount, # (I) Discount factor
double yearFraction, # (I) See JpmcdsDayCountFraction
double basis, # (I) Basis for the rate
- double *rate);
+ double *rate)
cdef enum Basis:
CONTINUOUS = 5000
DISCOUNT_RATE = 512
diff --git a/pyisda/curve.pyx b/pyisda/curve.pyx
index 9e2f2e9..ec75cf6 100644
--- a/pyisda/curve.pyx
+++ b/pyisda/curve.pyx
@@ -14,27 +14,48 @@ cpdef public enum BadDay:
MODIFIED = <long>'M'
cdef class Curve:
- def __dealloc__(self):
- if self._thisptr is not NULL:
- JpmcdsFreeTCurve(self._thisptr)
+ def __dealloc__(self):
+ if self._thisptr is not NULL:
+ JpmcdsFreeTCurve(self._thisptr)
- def inspect(self):
- """ method to inspect the content of the C struct
+ def inspect(self):
+ """ method to inspect the content of the C struct
- Returns
- -------
- dict
+ Returns
+ -------
+ dict
contains `base_date`, `basis`, `day_count_counvention` and `data`
- """
+ """
- return {'base_date': TDate_to_pydate(self._thisptr.fBaseDate),
- 'basis': self._thisptr.fBasis,
- 'day_count_convention': dcc_tostring(self._thisptr.fDayCountConv),
- 'data': fArray_to_list(self._thisptr.fArray, self._thisptr.fNumItems)}
- @property
- def base_date(self):
- return TDate_to_pydate(self._thisptr.fBaseDate)
+ return {'base_date': TDate_to_pydate(self._thisptr.fBaseDate),
+ 'basis': self._thisptr.fBasis,
+ 'day_count_convention': dcc_tostring(self._thisptr.fDayCountConv),
+ 'data': fArray_to_list(self._thisptr.fArray, self._thisptr.fNumItems)}
+ @property
+ def base_date(self):
+ return TDate_to_pydate(self._thisptr.fBaseDate)
+ def __forward_zero_price(self, d2, d1 = None):
+ """ computes the forward zero price at a given date.
+
+ Parameters
+ ----------
+ date : :class:`datetime.date`
+
+ Returns
+ -------
+ float
+ """
+ if self._thisptr is NULL:
+ raise ValueError('curve is empty')
+ cdef TDate start_date
+ if d1 is None:
+ start_date = self._thisptr.fBaseDate
+ else:
+ start_date = pydate_to_TDate(d1)
+ return JpmcdsForwardZeroPrice(self._thisptr,
+ start_date,
+ pydate_to_TDate(d2))
cdef fArray_to_list(TRatePt* fArray, int fNumItems):
cdef size_t i
@@ -147,21 +168,7 @@ cdef class YieldCurve(Curve):
<double>1, dcc(day_count_conv))
return yc
- def discount_factor(self, date):
- """ computes the discount factor at a given date.
-
- Parameters
- ----------
- date : :class:`datetime.date`
-
- Returns
- -------
- float
- """
- if self._thisptr is NULL:
- raise ValueError('curve is empty')
- cdef TDate discount_date = pydate_to_TDate(date)
- return JpmcdsZeroPrice(self._thisptr, discount_date)
+ discount_factor = Curve.__forward_zero_price
def list_dates(self):
""" returns the list of instrument dates
@@ -254,6 +261,8 @@ cdef class SpreadCurve(Curve):
if self._thisptr == NULL:
raise ValueError("something went wrong")
+ survival_probability = Curve.__forward_zero_price
+
@classmethod
def from_flat_hazard(cls, base_date, double rate, Basis basis = CONTINUOUS,
str day_count_conv = 'Actual/365F'):