Skip to content

Commit

Permalink
[CLEAN] cleaning BGIG and tempered Stable, a small error was correcte…
Browse files Browse the repository at this point in the history
…d for TS (num params = 6)
  • Loading branch information
gagazzotti committed Dec 10, 2024
1 parent fa8ca57 commit 5e8052d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 31 deletions.
4 changes: 0 additions & 4 deletions fypy/model/levy/BGIG.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,6 @@ def p_m(self) -> float:
"""Model Parameter"""
return self._params[5]

# =============================
# Fourier Interface Implementation
# =============================

####################################
####### CUMULANTS HELPERS ##########
####################################
Expand Down
56 changes: 29 additions & 27 deletions fypy/model/levy/TemperedStable.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
"""Implementation of Tempered Stable model"""

from typing import List, Tuple, Optional, Union
import numpy as np
from scipy.special import gamma

from fypy.model.levy.LevyModel import LevyModel
from fypy.model.FourierModel import Cumulants
from fypy.termstructures.ForwardCurve import ForwardCurve
from fypy.termstructures.DiscountCurve import DiscountCurve
import numpy as np
from typing import List, Tuple, Optional, Union
from scipy.special import gamma


class TemperedStable(LevyModel):
"""
Tempered Stable Model as introduced in:
Tempered stable distributions and processes, U. Kuchler and S. Tappe
"""

def __init__(
self,
forwardCurve: ForwardCurve,
Expand All @@ -19,24 +27,15 @@ def __init__(
beta_m: float = 0.3,
lambda_m: float = 2,
):
"""
Carr-Geman-Madan-Yor (CGMY) model. When Y=0, this model reduces to VG
:param forwardCurve: ForwardCurve term structure
:param C: float, viewed as a measure of the overall level of activity, and influences kurtosis
:param G: float, rate of exponential decay on the right tail
:param M: float, rate of exponential decay on the left tail. Typically for equities G < M, ie the left
tail is then heavier than the right (more down risk)
:param Y: float, controls the "fine structure" of the process
"""
super().__init__(
forwardCurve=forwardCurve,
discountCurve=discountCurve,
params=np.asarray([alpha_p, beta_p, lambda_p, alpha_m, beta_m, lambda_m]),
)

# ================
# Model Parameters
# ================
####################################
####### MODEL PARAMETERS ##########
####################################

@property
def alpha_p(self) -> float:
Expand Down Expand Up @@ -68,13 +67,14 @@ def lambda_m(self) -> float:
"""Model Parameter"""
return self._params[5]

# =============================
# Fourier Interface Implementation
# =============================
####################################
####### CUMULANTS HELPERS ##########
####################################

def cumulants(self, T: float) -> Cumulants:
"""
Evaluate the cumulants of the model at a given time. This is useful e.g. to figure out integration bounds etc
Evaluate the cumulants of the model at a given time.
This is useful e.g. to figure out integration bounds etc
during pricing
:param T: float, time to maturity (time at which cumulants are evaluated)
:return: Cumulants object
Expand All @@ -85,7 +85,6 @@ def cumulants(self, T: float) -> Cumulants:
rn_drift = self.risk_neutral_log_drift()

def cumulants_gen(n: int):

return gamma(n - beta_p) * alpha_p / (lambda_p ** (n - beta_p)) + (
-1
) ** n * gamma(n - beta_m) * alpha_m / (lambda_m ** (n - beta_m))
Expand All @@ -100,9 +99,11 @@ def cumulants_gen(n: int):

def symbol(self, xi: Union[float, np.ndarray]):
"""
Levy symbol, uniquely defines Characteristic Function via: chf(T,xi) = exp(T*symbol(xi)), for all T>=0
Levy symbol, uniquely defines Characteristic Function via:
chf(T,xi) = exp(T*symbol(xi)), for all T>=0
:param xi: np.ndarray or float, points in frequency domain
:return: np.ndarray or float, symbol evaluated at input points in frequency domain
:return: np.ndarray or float, symbol evaluated at
input points in frequency domain
"""
alpha_p, beta_p, lambda_p = self.alpha_p, self.beta_p, self.lambda_p
alpha_m, beta_m, lambda_m = self.alpha_m, self.beta_m, self.lambda_m
Expand All @@ -120,7 +121,8 @@ def symbol(self, xi: Union[float, np.ndarray]):

def convexity_correction(self) -> float:
"""
Computes the convexity correction for the Levy model, added to log process drift to ensure
Computes the convexity correction for the Levy model,
added to log process drift to ensure
risk neutrality
"""
alpha_p, beta_p, lambda_p = self.alpha_p, self.beta_p, self.lambda_p
Expand All @@ -130,12 +132,12 @@ def convexity_correction(self) -> float:
+ alpha_m * gamma(-beta_m) * ((lambda_m + 1) ** beta_m - lambda_m**beta_m)
)

# =============================
# Calibration Interface Implementation
# =============================
#############################################
### Calibration Interface Implementation ###
#############################################

def num_params(self) -> int:
return 5
return 6

def param_bounds(self) -> Optional[List[Tuple]]:
return [(0, np.inf), (0, 1), (0, np.inf), (0, np.inf), (0, 1), (0, np.inf)]
Expand Down

0 comments on commit 5e8052d

Please sign in to comment.