Skip to content

Commit

Permalink
Updating Documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
quantgirluk committed May 25, 2024
1 parent 9437991 commit 409e099
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 9 deletions.
36 changes: 29 additions & 7 deletions aleatory/processes/euler_maruyama/ckls_process.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,37 @@
"""Chan-Karolyi-Longstaff-Sanders (CKLS) process"""

from aleatory.processes.euler_maruyama.ckls_process_generic import CKLSProcessGeneric
from aleatory.processes import BrownianMotion, Vasicek, CIRProcess, GBM


class CKLSProcess(CKLSProcessGeneric):

r"""
Chan-Karolyi-Longstaff-Sanders (CKLS) process
.. image:: _static/ckls_process_draw.png
A CKLS process :math:`X = \{X : t \geq 0\}` is characterised by the following
Stochastic Differential Equation
.. math::
dX_t = (\alpha + \beta X_t) dt + \sigma X_t^{\gamma} dW_t, \ \ \ \ \forall t\in (0,T],
with initial condition :math:`X_0 = x_0`, where
- :math:`\alpha \in \mathbb{R}`
- :math:`\beata \in \mathbb{R}`
- :math:`\sigma>0` is the scale of the volatility
- :math:`\gamma\geq 0` is the elasticity term
- :math:`W_t` is a standard Brownian Motion.
Reference: CHAN, K.C., KAROLYI, G.A., LONGSTAFF, F.A. and SANDERS, A.B. (1992),
An Empirical Comparison of Alternative Models of the Short-Term Interest Rate. The Journal of Finance,
47: 1209-1227. https://doi.org/10.1111/j.1540-6261.1992.tb04011.x
"""
def __new__(cls, *args, **kwargs):
alpha = kwargs['alpha'] if 'alpha' in kwargs else 0.5
beta = kwargs['beta'] if 'beta' in kwargs else 0.5
Expand All @@ -26,10 +55,3 @@ def __new__(cls, *args, **kwargs):
else:
return CKLSProcessGeneric(alpha=alpha, beta=beta, sigma=sigma, gamma=gamma, initial=initial, T=T, rng=rng)

# def __init__(self, alpha=0.5, beta=0.5, sigma=0.1, gamma=1.0, initial=1.0, T=1.0, rng=None):
# super().__init__(alpha, beta, sigma, gamma, initial, T, rng)

# def __str__(self):
# return "CKLS process with parameters alpha={alpha}, beta={beta}, sigma={sigma}, gamma={gamma}, initial={initial} on [0, {T}].".format(
# T=str(self.T), gamma=str(self.gamma), alpha=str(self.alpha), beta=str(self.beta), sigma=str(self.sigma),
# initial=self.initial)
2 changes: 1 addition & 1 deletion aleatory/processes/euler_maruyama/ckls_process_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class CKLSProcessGeneric(SPEulerMaruyama):
r"""
Chan-Karolyi-Longstaff-Sanders (CKLS) process
.. image:: _static/cev_process_drawn.png
.. image:: _static/ckls_process_draw.png
A CKLS process :math:`X = \{X : t \geq 0\}` is characterised by the following
Expand Down
16 changes: 15 additions & 1 deletion aleatory/processes/jump/poisson.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Poisson Process"""

import matplotlib.pyplot as plt
import numpy as np
from scipy.stats import poisson
Expand All @@ -10,6 +11,19 @@


class PoissonProcess(BaseProcess):
r"""Poisson Process
.. image:: _static/poisson_process_draw.png
A Poisson point process is a type of random mathematical object that consists of points randomly located on
a mathematical space with the essential feature that the points occur independently of one another.
A Poisson process :math:`{N(t) : t\geq 0}` with intensity rate :math:`\lambda>0` is defined by the following properties:
1. :math:`N(t)` has a Poisson distribution with parameter :math:`\lambda t`, for each :math:`t> 0`.
2. It has independent increments
"""

def __init__(self, rate=1.0, rng=None):
super().__init__(rng=rng)
Expand Down Expand Up @@ -182,4 +196,4 @@ def draw(self, N, T=None, style="seaborn-v0_8-whitegrid", colormap="RdYlBu_r", e
plt.show()

return fig

Binary file added docs/source/_static/ckls_process_draw.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/source/_static/poisson_process_draw.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 20 additions & 0 deletions tests/test_ckls.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,26 @@
import unittest


def test_ckls_process():
name = "Chan-Karolyi-Longstaff-Sanders (CKLS) Process"
process = CKLSProcess(alpha=0.5, beta=1.5, sigma=0.5, gamma=0.3, initial=1.0, T=1.0)
# fig = process.plot(n=100, N=10, figsize=(9, 6), dpi=200, title=name)
# fig.savefig("ckls1.png")
fig = process.draw(n=100, N=300, figsize=(11, 6), dpi=200, title=name, envelope=True)
# fig.savefig("ckls2.png")
# process = CKLSProcess(alpha=0.5, beta=-2.0, sigma=0.5, gamma=0.0, initial=1.0, T=1.0)
# fig = process.draw(n=100, N=300, colormap="PuOr", figsize=(11, 6), dpi=200, title=name)
# fig.savefig("ckls3.png")
# process = CKLSProcess(alpha=0.0, beta=-2.0, sigma=0.5, gamma=1.0, initial=3.0, T=1.0)
# fig = process.draw(n=100, N=300, colormap="PiYG", figsize=(11, 6), dpi=200, title=name)
# fig.savefig("ckls4.png")
# process = CKLSProcess(alpha=0.0, beta=0.0, sigma=0.5, gamma=0.0, initial=2.0, T=1.0)
# fig = process.draw(n=100, N=300, colormap="Spectral", figsize=(11, 6), dpi=200, title=name)
# fig.savefig("ckls5.png")
# process.draw(n=100, N=200, envelope=False, figsize=(12, 6))
# process.draw(n=100, N=200, envelope=False, orientation='horizontal', figsize=(12, 6))
# process.draw(n=100, N=200, envelope=False, orientation='vertical', figsize=(12, 6), )

class test_ckls:
vis = False

Expand Down

0 comments on commit 409e099

Please sign in to comment.