Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions quantlib/indexes/ibor/libor.pyx
Original file line number Diff line number Diff line change
@@ -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'

Expand Down
14 changes: 6 additions & 8 deletions quantlib/indexes/inflation_index.pyx
Original file line number Diff line number Diff line change
@@ -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'

Expand Down
14 changes: 6 additions & 8 deletions quantlib/indexes/interest_rate_index.pyx
Original file line number Diff line number Diff line change
@@ -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
Expand Down
16 changes: 6 additions & 10 deletions quantlib/math/hestonhwcorrelationconstraint.pyx
Original file line number Diff line number Diff line change
@@ -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
Expand Down
14 changes: 6 additions & 8 deletions quantlib/models/calibration_helper.pyx
Original file line number Diff line number Diff line change
@@ -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
Expand Down
16 changes: 10 additions & 6 deletions quantlib/models/equity/bates_model.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down
14 changes: 6 additions & 8 deletions quantlib/models/equity/heston_model.pxd
Original file line number Diff line number Diff line change
@@ -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

Expand Down
65 changes: 37 additions & 28 deletions quantlib/models/equity/heston_model.pyx
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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(),
Expand Down
14 changes: 6 additions & 8 deletions quantlib/models/model.pyx
Original file line number Diff line number Diff line change
@@ -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'

Expand Down
14 changes: 6 additions & 8 deletions quantlib/models/shortrate/calibrationhelpers/swaption_helper.pyx
Original file line number Diff line number Diff line change
@@ -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
Expand Down
22 changes: 20 additions & 2 deletions quantlib/models/shortrate/onefactor_model.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
2 changes: 1 addition & 1 deletion quantlib/models/shortrate/onefactormodels/hullwhite.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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.

"""

Expand Down
14 changes: 6 additions & 8 deletions quantlib/termstructures/inflation/seasonality.pyx
Original file line number Diff line number Diff line change
@@ -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
Expand Down
17 changes: 8 additions & 9 deletions quantlib/termstructures/yields/flat_forward.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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.
"""

Expand Down
14 changes: 6 additions & 8 deletions quantlib/time/imm.pyx
Original file line number Diff line number Diff line change
@@ -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
Expand Down