Skip to content

Commit 137b85f

Browse files
committed
cleanup docstrings
1 parent 9d9f3b6 commit 137b85f

File tree

5 files changed

+70
-38
lines changed

5 files changed

+70
-38
lines changed

quantlib/models/equity/bates_model.pyx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,17 @@
44
# This program is distributed in the hope that it will be useful, but WITHOUT
55
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
66
# FOR A PARTICULAR PURPOSE. See the license for more details.
7+
"""Bates stochastic-volatility model
78
9+
extended versions of the Heston Model for the stochastic volatility
10+
of an asset including jumps.
11+
12+
References
13+
----------
14+
.. [1] A. Sepp, "Pricing European-Style Options under Jump Diffusion
15+
Processes with Stochastic Volatility: Applications of Fourier Transform"
16+
(https://papers.ssrn.com/sol3/papers.cfm?abstract_id=1412333)
17+
"""
818
include '../../types.pxi'
919

1020
from cython.operator cimport dereference as deref
@@ -31,12 +41,6 @@ cdef class BatesModel(HestonModel):
3141
(self.v0, self.kappa, self.theta, self.sigma,
3242
self.rho, self.Lambda, self.nu, self.delta)
3343

34-
def process(self):
35-
cdef BatesProcess process = BatesProcess.__new__(BatesProcess)
36-
process._thisptr = static_pointer_cast[_sp.StochasticProcess](
37-
self._thisptr.get().process())
38-
return process
39-
4044
property Lambda:
4145
def __get__(self):
4246
return (<_bm.BatesModel*> self._thisptr.get()).Lambda()

quantlib/models/equity/heston_model.pyx

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -62,39 +62,50 @@ cdef class HestonModelHelper(BlackCalibrationHelper):
6262
)
6363

6464
cdef class HestonModel:
65+
"""Heston model for the stochastic volatility of an asset
6566
66-
def __init__(self, HestonProcess process):
67+
References
68+
----------
69+
Heston, Steven L., 1993. "A Closed-Form Solution for Options with Stochastic Volatility with Applications to Bond and Currency Options." *The review of Financial Studies, Volume 6, Issue 2, 327-343.*
70+
"""
6771

72+
def __init__(self, HestonProcess process):
6873
self._thisptr = shared_ptr[_hm.HestonModel](
6974
new _hm.HestonModel(static_pointer_cast[_hp.HestonProcess](
7075
process._thisptr))
7176
)
7277

7378
def process(self):
79+
"""underlying process"""
7480
cdef HestonProcess process = HestonProcess.__new__(HestonProcess)
7581
process._thisptr = static_pointer_cast[_sp.StochasticProcess](
7682
self._thisptr.get().process())
7783
return process
7884

79-
property theta:
80-
def __get__(self):
81-
return self._thisptr.get().theta()
82-
83-
property kappa:
84-
def __get__(self):
85-
return self._thisptr.get().kappa()
86-
87-
property sigma:
88-
def __get__(self):
89-
return self._thisptr.get().sigma()
90-
91-
property rho:
92-
def __get__(self):
93-
return self._thisptr.get().rho()
94-
95-
property v0:
96-
def __get__(self):
97-
return self._thisptr.get().v0()
85+
@property
86+
def theta(self):
87+
"""variance mean reversion level"""
88+
return self._thisptr.get().theta()
89+
90+
@property
91+
def kappa(self):
92+
"""variance mean reversion speed"""
93+
return self._thisptr.get().kappa()
94+
95+
@property
96+
def sigma(self):
97+
"""volatility of the volatility"""
98+
return self._thisptr.get().sigma()
99+
100+
@property
101+
def rho(self):
102+
"""correlation"""
103+
return self._thisptr.get().rho()
104+
105+
@property
106+
def v0(self):
107+
"""spot variance"""
108+
return self._thisptr.get().v0()
98109

99110
def calibrate(self, list helpers, OptimizationMethod method, EndCriteria
100111
end_criteria, Constraint constraint=Constraint(),

quantlib/models/shortrate/onefactor_model.pyx

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,28 +15,46 @@ cimport quantlib._stochastic_process as _sp
1515
from quantlib.stochastic_process cimport StochasticProcess1D
1616

1717
cdef class ShortRateDynamics:
18-
18+
"""Base class describing the short-rate dynamics"""
1919
@property
2020
def process(self):
21+
"""Returns the risk_neutral dynamics of the state variable"""
2122
cdef StochasticProcess1D sp = StochasticProcess1D.__new__(StochasticProcess1D)
2223
sp._thisptr = static_pointer_cast[_sp.StochasticProcess](self._thisptr.get().process())
2324
return sp
2425

25-
def variable(self, Time t, Rate r):
26+
def variable(self, Time t, Rate r) -> Real:
27+
"""Compute state variable from short rate"""
2628
return self._thisptr.get().variable(t, r)
2729

2830
def short_rate(self, Time t, Real variable):
31+
"""Compute short rate from state variable"""
2932
return self._thisptr.get().shortRate(t, variable)
3033

3134
cdef class OneFactorModel(ShortRateModel):
3235

3336
@property
3437
def dynamics(self):
38+
"""short-rate dynamics
39+
40+
Returns
41+
-------
42+
dynamics : :class:`~quantlib.models.shortrate.onefactor_model.ShortRateDynamics`
43+
"""
3544
cdef ShortRateDynamics dyn = ShortRateDynamics.__new__(ShortRateDynamics)
3645
dyn._thisptr = (<_ofm.OneFactorModel*>self._thisptr.get()).dynamics()
3746
return dyn
3847

3948
cdef class OneFactorAffineModel(OneFactorModel):
49+
r"""Single-factor affine base class
50+
51+
Single-factor models with an analytical formula for discount bonds
52+
should inherit from this class. They must then implement the functions
53+
:math:`A(T,t)` and :math:`B(T,t)` such that
54+
55+
.. math::
56+
P(t, T, r_t) = A(t, T)\exp\{-B(t, T) r_t\}.
57+
"""
4058

4159
def __init__(self):
4260
raise ValueError('Cannot instantiate OneFactorAffineModel')

quantlib/models/shortrate/onefactormodels/hullwhite.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ cdef class HullWhite(Vasicek):
3939
4040
.. warning::
4141
When the term structure is relinked the :math:`r_0` parameter
42-
of the underlying Vasicek model is not updated:
42+
of the underlying Vasicek model is not updated.
4343
4444
"""
4545

quantlib/termstructures/yields/flat_forward.pyx

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,26 +21,25 @@ from quantlib.quote cimport Quote
2121

2222

2323
cdef class FlatForward(YieldTermStructure):
24-
""" Flat intereste-rate curve
24+
""" Flat interest-rate curve
2525
2626
Parameters
2727
----------
28-
29-
refererence_date: quantlib.time.date.Date or None
28+
refererence_date : :class:`~quantlib.time.date.Date` or None
3029
Reference date used by the curve. If None, the user must provide the
3130
settlement days.
32-
forward: quantlib.quote.Quote or float
31+
forward : :class:`~quantlib.quote.Quote` | float
3332
The forward value used by the curve.
34-
daycounter: quantlib.time.daycounter.DayCounter
33+
daycounter : :class:`~quantlib.time.daycounter.DayCounter`
3534
The day counter used by the curve.
36-
settlement_days: int
35+
settlement_days : int
3736
The settlement days used by this curve. If a reference date is given,
3837
this parameter is not used.
39-
calendar: quantlib.time.calendar.Calendar
38+
calendar : :class:`~quantlib.time.calendar.Calendar`
4039
The calendar used by the curve if created with the settlement days.
41-
compounding: int (default: Continuous)
40+
compounding : :class:`~quantlib.compounding.Compounding`, default Compounding.Continuous
4241
The type of compounding used by this curve.
43-
frequency: int (default: Annual)
42+
frequency : :class:`~quantlib.time.frequency.Frequency`, default `Annual`
4443
The frequency used by this curve.
4544
"""
4645

0 commit comments

Comments
 (0)