diff --git a/quantlib/indexes/ibor/libor.pyx b/quantlib/indexes/ibor/libor.pyx index 5ab623287..d836ef48a 100644 --- a/quantlib/indexes/ibor/libor.pyx +++ b/quantlib/indexes/ibor/libor.pyx @@ -1,11 +1,9 @@ -""" - Copyright (C) 2011, Enthought Inc - Copyright (C) 2011, Patrick Henaff - - This program is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - FOR A PARTICULAR PURPOSE. See the license for more details. -""" +# Copyright (C) 2011, Enthought Inc +# Copyright (C) 2011, Patrick Henaff +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the license for more details. include '../../types.pxi' diff --git a/quantlib/indexes/inflation_index.pyx b/quantlib/indexes/inflation_index.pyx index b677ef034..2c86a7c3e 100644 --- a/quantlib/indexes/inflation_index.pyx +++ b/quantlib/indexes/inflation_index.pyx @@ -1,11 +1,9 @@ -""" - Copyright (C) 2016, Enthought Inc - Copyright (C) 2016, Patrick Henaff - - This program is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - FOR A PARTICULAR PURPOSE. See the license for more details. -""" +# Copyright (C) 2016, Enthought Inc +# Copyright (C) 2016, Patrick Henaff +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the license for more details. include '../types.pxi' diff --git a/quantlib/indexes/interest_rate_index.pyx b/quantlib/indexes/interest_rate_index.pyx index 6e4a619cf..99d8957d4 100644 --- a/quantlib/indexes/interest_rate_index.pyx +++ b/quantlib/indexes/interest_rate_index.pyx @@ -1,11 +1,9 @@ -""" - Copyright (C) 2011, Enthought Inc - Copyright (C) 2011, Patrick Henaff - - This program is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - FOR A PARTICULAR PURPOSE. See the license for more details. -""" +# Copyright (C) 2011, Enthought Inc +# Copyright (C) 2011, Patrick Henaff +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the license for more details. include '../types.pxi' from cython.operator cimport dereference as deref diff --git a/quantlib/math/hestonhwcorrelationconstraint.pyx b/quantlib/math/hestonhwcorrelationconstraint.pyx index a13e8bccb..76607730c 100644 --- a/quantlib/math/hestonhwcorrelationconstraint.pyx +++ b/quantlib/math/hestonhwcorrelationconstraint.pyx @@ -1,13 +1,9 @@ -""" - Copyright (C) 2015, Enthought Inc - Copyright (C) 2015, Patrick Henaff - - This program is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - FOR A PARTICULAR PURPOSE. See the license for more details. -""" - -include '../types.pxi' +# Copyright (C) 2015, Enthought Inc +# Copyright (C) 2015, Patrick Henaff +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the license for more details. from quantlib.handle cimport shared_ptr from quantlib.math.optimization cimport Constraint diff --git a/quantlib/models/calibration_helper.pyx b/quantlib/models/calibration_helper.pyx index 1e3900faf..f691f418a 100644 --- a/quantlib/models/calibration_helper.pyx +++ b/quantlib/models/calibration_helper.pyx @@ -1,11 +1,9 @@ -""" - Copyright (C) 2015, Enthought Inc - Copyright (C) 2015, Patrick Henaff - - This program is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - FOR A PARTICULAR PURPOSE. See the license for more details. -""" +# Copyright (C) 2015, Enthought Inc +# Copyright (C) 2015, Patrick Henaff +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the license for more details. from quantlib.types cimport Real, Size, Volatility from quantlib.handle cimport shared_ptr diff --git a/quantlib/models/equity/bates_model.pyx b/quantlib/models/equity/bates_model.pyx index 2c344027c..6fe1d9c75 100644 --- a/quantlib/models/equity/bates_model.pyx +++ b/quantlib/models/equity/bates_model.pyx @@ -4,7 +4,17 @@ # This program is distributed in the hope that it will be useful, but WITHOUT # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # FOR A PARTICULAR PURPOSE. See the license for more details. +"""Bates stochastic-volatility model +extended versions of the Heston Model for the stochastic volatility +of an asset including jumps. + +References +---------- +.. [1] A. Sepp, "Pricing European-Style Options under Jump Diffusion + Processes with Stochastic Volatility: Applications of Fourier Transform" + (https://papers.ssrn.com/sol3/papers.cfm?abstract_id=1412333) +""" include '../../types.pxi' from cython.operator cimport dereference as deref @@ -31,12 +41,6 @@ cdef class BatesModel(HestonModel): (self.v0, self.kappa, self.theta, self.sigma, self.rho, self.Lambda, self.nu, self.delta) - def process(self): - cdef BatesProcess process = BatesProcess.__new__(BatesProcess) - process._thisptr = static_pointer_cast[_sp.StochasticProcess]( - self._thisptr.get().process()) - return process - property Lambda: def __get__(self): return (<_bm.BatesModel*> self._thisptr.get()).Lambda() diff --git a/quantlib/models/equity/heston_model.pxd b/quantlib/models/equity/heston_model.pxd index 3c4b99614..56d51b4d9 100644 --- a/quantlib/models/equity/heston_model.pxd +++ b/quantlib/models/equity/heston_model.pxd @@ -1,11 +1,9 @@ -""" - Copyright (C) 2011, Enthought Inc - Copyright (C) 2011, Patrick Henaff - - This program is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - FOR A PARTICULAR PURPOSE. See the license for more details. -""" +# Copyright (C) 2011, Enthought Inc +# Copyright (C) 2011, Patrick Henaff +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the license for more details. from . cimport _heston_model as _hm diff --git a/quantlib/models/equity/heston_model.pyx b/quantlib/models/equity/heston_model.pyx index 8bbf7b7e8..d4b027e69 100644 --- a/quantlib/models/equity/heston_model.pyx +++ b/quantlib/models/equity/heston_model.pyx @@ -1,12 +1,10 @@ -""" - Copyright (C) 2011, Enthought Inc - Copyright (C) 2011, Patrick Henaff - - This program is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - FOR A PARTICULAR PURPOSE. See the license for more details. -""" +# Copyright (C) 2011, Enthought Inc +# Copyright (C) 2011, Patrick Henaff +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the license for more details. +""" Heston model for the stochastic volatility of an asset""" from quantlib.types cimport Real from libcpp cimport bool from cython.operator cimport dereference as deref @@ -64,39 +62,50 @@ cdef class HestonModelHelper(BlackCalibrationHelper): ) cdef class HestonModel: + """Heston model for the stochastic volatility of an asset - def __init__(self, HestonProcess process): + References + ---------- + 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.* + """ + def __init__(self, HestonProcess process): self._thisptr = shared_ptr[_hm.HestonModel]( new _hm.HestonModel(static_pointer_cast[_hp.HestonProcess]( process._thisptr)) ) def process(self): + """underlying process""" cdef HestonProcess process = HestonProcess.__new__(HestonProcess) process._thisptr = static_pointer_cast[_sp.StochasticProcess]( self._thisptr.get().process()) return process - property theta: - def __get__(self): - return self._thisptr.get().theta() - - property kappa: - def __get__(self): - return self._thisptr.get().kappa() - - property sigma: - def __get__(self): - return self._thisptr.get().sigma() - - property rho: - def __get__(self): - return self._thisptr.get().rho() - - property v0: - def __get__(self): - return self._thisptr.get().v0() + @property + def theta(self): + """variance mean reversion level""" + return self._thisptr.get().theta() + + @property + def kappa(self): + """variance mean reversion speed""" + return self._thisptr.get().kappa() + + @property + def sigma(self): + """volatility of the volatility""" + return self._thisptr.get().sigma() + + @property + def rho(self): + """correlation""" + return self._thisptr.get().rho() + + @property + def v0(self): + """spot variance""" + return self._thisptr.get().v0() def calibrate(self, list helpers, OptimizationMethod method, EndCriteria end_criteria, Constraint constraint=Constraint(), diff --git a/quantlib/models/model.pyx b/quantlib/models/model.pyx index f57a9233b..51ff3610a 100644 --- a/quantlib/models/model.pyx +++ b/quantlib/models/model.pyx @@ -1,11 +1,9 @@ -""" - Copyright (C) 2015, Enthought Inc - Copyright (C) 2015, Patrick Henaff - - This program is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - FOR A PARTICULAR PURPOSE. See the license for more details. -""" +# Copyright (C) 2015, Enthought Inc +# Copyright (C) 2015, Patrick Henaff +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the license for more details. include '../types.pxi' diff --git a/quantlib/models/shortrate/calibrationhelpers/swaption_helper.pyx b/quantlib/models/shortrate/calibrationhelpers/swaption_helper.pyx index 518608d03..c47b2c80e 100644 --- a/quantlib/models/shortrate/calibrationhelpers/swaption_helper.pyx +++ b/quantlib/models/shortrate/calibrationhelpers/swaption_helper.pyx @@ -1,11 +1,9 @@ -""" - Copyright (C) 2015, Enthought Inc - Copyright (C) 2015, Patrick Henaff - - This program is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - FOR A PARTICULAR PURPOSE. See the license for more details. -""" +# Copyright (C) 2015, Enthought Inc +# Copyright (C) 2015, Patrick Henaff +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the license for more details. from quantlib.types cimport Real from quantlib.handle cimport Handle, shared_ptr, static_pointer_cast diff --git a/quantlib/models/shortrate/onefactor_model.pyx b/quantlib/models/shortrate/onefactor_model.pyx index 135b38def..974373630 100644 --- a/quantlib/models/shortrate/onefactor_model.pyx +++ b/quantlib/models/shortrate/onefactor_model.pyx @@ -15,28 +15,46 @@ cimport quantlib._stochastic_process as _sp from quantlib.stochastic_process cimport StochasticProcess1D cdef class ShortRateDynamics: - + """Base class describing the short-rate dynamics""" @property def process(self): + """Returns the risk_neutral dynamics of the state variable""" cdef StochasticProcess1D sp = StochasticProcess1D.__new__(StochasticProcess1D) sp._thisptr = static_pointer_cast[_sp.StochasticProcess](self._thisptr.get().process()) return sp - def variable(self, Time t, Rate r): + def variable(self, Time t, Rate r) -> Real: + """Compute state variable from short rate""" return self._thisptr.get().variable(t, r) def short_rate(self, Time t, Real variable): + """Compute short rate from state variable""" return self._thisptr.get().shortRate(t, variable) cdef class OneFactorModel(ShortRateModel): @property def dynamics(self): + """short-rate dynamics + + Returns + ------- + dynamics : :class:`~quantlib.models.shortrate.onefactor_model.ShortRateDynamics` + """ cdef ShortRateDynamics dyn = ShortRateDynamics.__new__(ShortRateDynamics) dyn._thisptr = (<_ofm.OneFactorModel*>self._thisptr.get()).dynamics() return dyn cdef class OneFactorAffineModel(OneFactorModel): + r"""Single-factor affine base class + + Single-factor models with an analytical formula for discount bonds + should inherit from this class. They must then implement the functions + :math:`A(T,t)` and :math:`B(T,t)` such that + + .. math:: + P(t, T, r_t) = A(t, T)\exp\{-B(t, T) r_t\}. + """ def __init__(self): raise ValueError('Cannot instantiate OneFactorAffineModel') diff --git a/quantlib/models/shortrate/onefactormodels/hullwhite.pyx b/quantlib/models/shortrate/onefactormodels/hullwhite.pyx index 8b3d8f19b..da4676b7f 100644 --- a/quantlib/models/shortrate/onefactormodels/hullwhite.pyx +++ b/quantlib/models/shortrate/onefactormodels/hullwhite.pyx @@ -39,7 +39,7 @@ cdef class HullWhite(Vasicek): .. warning:: When the term structure is relinked the :math:`r_0` parameter - of the underlying Vasicek model is not updated: + of the underlying Vasicek model is not updated. """ diff --git a/quantlib/termstructures/inflation/seasonality.pyx b/quantlib/termstructures/inflation/seasonality.pyx index ac404594f..cf053b2f7 100644 --- a/quantlib/termstructures/inflation/seasonality.pyx +++ b/quantlib/termstructures/inflation/seasonality.pyx @@ -1,11 +1,9 @@ -""" - Copyright (C) 2016, Enthought Inc - Copyright (C) 2016, Patrick Henaff - - This program is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - FOR A PARTICULAR PURPOSE. See the license for more details. -""" +# Copyright (C) 2016, Enthought Inc +# Copyright (C) 2016, Patrick Henaff +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the license for more details. from quantlib.types cimport Rate from quantlib.handle cimport shared_ptr diff --git a/quantlib/termstructures/yields/flat_forward.pyx b/quantlib/termstructures/yields/flat_forward.pyx index 482b9162a..441ee0da5 100644 --- a/quantlib/termstructures/yields/flat_forward.pyx +++ b/quantlib/termstructures/yields/flat_forward.pyx @@ -21,26 +21,25 @@ from quantlib.quote cimport Quote cdef class FlatForward(YieldTermStructure): - """ Flat intereste-rate curve + """ Flat interest-rate curve Parameters ---------- - - refererence_date: quantlib.time.date.Date or None + refererence_date : :class:`~quantlib.time.date.Date` or None Reference date used by the curve. If None, the user must provide the settlement days. - forward: quantlib.quote.Quote or float + forward : :class:`~quantlib.quote.Quote` | float The forward value used by the curve. - daycounter: quantlib.time.daycounter.DayCounter + daycounter : :class:`~quantlib.time.daycounter.DayCounter` The day counter used by the curve. - settlement_days: int + settlement_days : int The settlement days used by this curve. If a reference date is given, this parameter is not used. - calendar: quantlib.time.calendar.Calendar + calendar : :class:`~quantlib.time.calendar.Calendar` The calendar used by the curve if created with the settlement days. - compounding: int (default: Continuous) + compounding : :class:`~quantlib.compounding.Compounding`, default Compounding.Continuous The type of compounding used by this curve. - frequency: int (default: Annual) + frequency : :class:`~quantlib.time.frequency.Frequency`, default `Annual` The frequency used by this curve. """ diff --git a/quantlib/time/imm.pyx b/quantlib/time/imm.pyx index 3a3be9880..d5f1c724b 100644 --- a/quantlib/time/imm.pyx +++ b/quantlib/time/imm.pyx @@ -1,11 +1,9 @@ -""" - Copyright (C) 2014, Enthought Inc - Copyright (C) 2014, Patrick Henaff - - This program is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - FOR A PARTICULAR PURPOSE. See the license for more details. -""" +# Copyright (C) 2014, Enthought Inc +# Copyright (C) 2014, Patrick Henaff +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the license for more details. from cython.operator cimport dereference as deref from libcpp cimport bool