summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--docs/api.rst17
-rw-r--r--docs/conf.py5
-rw-r--r--pyisda/cdsone.pyx61
-rw-r--r--pyisda/curve.pyx23
-rw-r--r--setup.py3
5 files changed, 100 insertions, 9 deletions
diff --git a/docs/api.rst b/docs/api.rst
index e850f45..253ddd5 100644
--- a/docs/api.rst
+++ b/docs/api.rst
@@ -1,6 +1,23 @@
PyISDA
======
+:mod:`~pyisda.cdsone` contains the two work horse functions of the library,
+which allow to convert back and forth from upfront to spread
+
+.. autosummary::
+ pyisda.cdsone.upfront_charge
+ pyisda.cdsone.spread_from_upfront
+
+.. automodule:: pyisda.cdsone
+ :members:
+
+:mod:`~pyisda.curve` contains two types of curves:
+
+.. autosummary::
+ pyisda.curve.YieldCurve
+ pyisda.curve.SpreadCurve
+
+
.. automodule:: pyisda.curve
:members:
:undoc-members:
diff --git a/docs/conf.py b/docs/conf.py
index 855d662..5bdd422 100644
--- a/docs/conf.py
+++ b/docs/conf.py
@@ -34,7 +34,8 @@ extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.todo',
'sphinx.ext.imgmath',
- 'sphinx.ext.napoleon'
+ 'sphinx.ext.napoleon',
+ 'sphinx.ext.autosummary'
]
# Add any paths that contain templates here, relative to this directory.
@@ -125,7 +126,7 @@ todo_include_todos = True
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
-html_theme = 'alabaster'
+html_theme = 'sphinx_rtd_theme'
# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
diff --git a/pyisda/cdsone.pyx b/pyisda/cdsone.pyx
index 13c517e..6326183 100644
--- a/pyisda/cdsone.pyx
+++ b/pyisda/cdsone.pyx
@@ -1,5 +1,5 @@
from cdsone cimport (JpmcdsCdsoneUpfrontCharge,
- JpmcdsCdsoneSpread, JpmcdsStringToStubMethod)
+ JpmcdsCdsoneSpread, JpmcdsStringToStubMethod)
from curve cimport YieldCurve
from date cimport JpmcdsStringToDateInterval, pydate_to_TDate, dcc
@@ -12,7 +12,36 @@ def upfront_charge(date, value_date, benchmark_start_date, stepin_date,
double recovery_rate,
TBoolean pay_accrued_at_start = True,
TBoolean pay_accrued_on_default = True):
+ """
+ Computes the fair upfront payment for a cds based on the fair spread.
+ Parameters
+ ----------
+ date : :class:`datetime.date`
+ today's date
+ value_date : :class:`datetime.date`
+ the date when cash is assumed to change hands.
+ benchmark_start_date : :class:`datetime.date`
+ should be same as `start_date`, not sure why there are two parameters.
+ stepin_date : :class:`datetime.date`
+ effective start of protection, typically `date` + 1
+ start_date : :class:`datetime.date`
+ beginning of cds, typically most recent IMM date before `date`
+ end_date : :class:`datetime.date`
+ last date of the cds
+ coupon_rate : double
+ cds fixed coupon.
+ yc : :class:`~pyisda.cuve.YieldCurve`
+ Yield curve
+ spread : double
+ cds running spread
+ recovery_rate : double
+ assumed recovery rate
+ pay_accrued_at_start : bool, optional
+ do we pay accrued from `start_date` to `date`
+ pay_accrued_on_default : bool, optional
+ in case of default do we pay current accrued on default or at maturity.
+ """
cdef:
TDate today = pydate_to_TDate(date)
TDate value_date_c = pydate_to_TDate(value_date)
@@ -45,6 +74,36 @@ def spread_from_upfront(date, value_date, benchmark_start_date, stepin_date,
double recovery_rate,
TBoolean pay_accrued_at_start = True,
TBoolean pay_accrued_on_default = True):
+ """Computes the equivalent fair spread for a cds with upfront+running.
+
+ Parameters
+ ----------
+ date : :class:`datetime.date`
+ today's date
+ value_date : :class:`datetime.date`
+ the date when cash is assumed to change hands.
+ benchmark_start_date : :class:`datetime.date`
+ should be same as `start_date`, not sure why there are two parameters.
+ stepin_date : :class:`datetime.date`
+ effective start of protection, typically `date` + 1
+ start_date : :class:`datetime.date`
+ beginning of cds, typically most recent IMM date before `date`
+ end_date : :class:`datetime.date`
+ last date of the cds
+ coupon_rate : double
+ cds fixed coupon.
+ yc : :class:`~pyisda.cuve.YieldCurve`
+ Yield curve
+ upfront : double
+ cds upfront
+ recovery_rate : double
+ assumed recovery rate
+ pay_accrued_at_start : bool, optional
+ do we pay accrued from `start_date` to `date`
+ pay_accrued_on_default : bool, optional
+ in case of default do we pay current accrued on default or at maturity.
+
+ """
cdef:
TDate today = pydate_to_TDate(date)
TDate value_date_c = pydate_to_TDate(value_date)
diff --git a/pyisda/curve.pyx b/pyisda/curve.pyx
index 863ae0c..e7ce72d 100644
--- a/pyisda/curve.pyx
+++ b/pyisda/curve.pyx
@@ -67,6 +67,7 @@ cdef class YieldCurve(Curve):
bad_day_conv : int
Business day convention.
+
.. warning:: Instruments need to be sorted by tenor!
"""
@@ -145,12 +146,25 @@ cdef class YieldCurve(Curve):
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)
def list_dates(self):
+ """ returns the list of instrument dates
+
+ """
cdef size_t i
return [TDate_to_pydate(self._dates[i]) for i in range(self._ninstr)]
@@ -160,10 +174,10 @@ cdef class SpreadCurve(Curve):
Parameters
----------
- today : datetime.date
+ today : :class:`datetime.date`
yc : :class:`~pyisda.curve.YieldCurve`
- start_date : datetime.date
- step_in_date : datetime.date
+ start_date : :class:`datetime.date`
+ step_in_date : :class:`datetime.date`
cash_settle_date: :class:`datetime.date`
end_dates : list of :class:`datetime.date`
coupon_rates : :class:`array.array` of double
@@ -212,7 +226,6 @@ cdef class SpreadCurve(Curve):
if self._thisptr == NULL:
raise ValueError("something went wrong")
-
@classmethod
def from_flat_hazard(cls, base_date, double rate, Basis basis = CONTINUOUS,
str day_count_conv = 'Actual/365F'):
@@ -230,7 +243,7 @@ cdef class SpreadCurve(Curve):
day_count_cont : str, optional
Default to 'Actual/365F'
- """
+ """
cdef TDate base_date_c = pydate_to_TDate(base_date)
cdef SpreadCurve sc = cls.__new__(cls)
cdef TDate max_date = 200000 # can go higher but this should be more than enough
diff --git a/setup.py b/setup.py
index 8aae177..7c0b4f6 100644
--- a/setup.py
+++ b/setup.py
@@ -8,5 +8,6 @@ setup(
name = "pyisda",
version = '0.1',
author = 'Guillaume Horel',
- ext_modules = cythonize(extensions, nthreads = 4),
+ ext_modules = cythonize(extensions, nthreads = 4,
+ compiler_directives={'embedsignature':True}),
packages = ['pyisda'])