Skip to content

Commit

Permalink
Update sv_fft.py
Browse files Browse the repository at this point in the history
  • Loading branch information
jaehyukchoi committed Apr 9, 2024
1 parent 43c7a2a commit 7f4dc6c
Showing 1 changed file with 20 additions and 17 deletions.
37 changes: 20 additions & 17 deletions pyfeng/sv_fft.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ class FftABC(opt.OptABC, abc.ABC):
x_lim = 200 # integratin limit

@abc.abstractmethod
def mgf_logprice(self, xx, texp):
def mgf_logprice(self, uu, texp):
"""
Moment generating function (MGF) of log price. (forward = 1)
Args:
xx: dummy variable
uu: dummy variable
texp: time to expiry
Returns:
MGF value at xx
MGF value at uu
"""
return NotImplementedError

Expand Down Expand Up @@ -657,25 +657,28 @@ def mgf_logprice(self, uu, texp):

class CgmyFft(smile.OptSmileABC, FftABC):

C = 1
G = 1
M = 1
Y = 0
C = 1.
G = 1.
M = 1.
Y = 0.

def __init__(self, C, G, M, Y, intr=0.0, divr=0.0, is_fwd=False):
super().__init__(C, intr=intr, divr=divr, is_fwd=is_fwd)
self.G, self.M, self.Y = G, M, Y
super().__init__(C, intr=intr, divr=divr, is_fwd=is_fwd) # self.sigma = C
self.C, self.G, self.M, self.Y = C, G, M, Y

def mgf_logprice(self, xx, texp):
def mgf_logprice(self, uu, texp):

gam_Y = spsp.gamma(-self.Y)
M_pow_Y = np.power(self.M, self.Y)
G_pow_Y = np.power(self.G, self.Y)

rv = self.C * spsp.gamma(-self.Y) * (
np.power(self.M - xx, self.Y) - np.power(self.M, self.Y)
+ np.power(self.G - xx, self.Y) - np.power(self.G, self.Y)
rv = self.C * gam_Y * (
np.power(self.M - uu, self.Y) - M_pow_Y
+ np.power(self.G - uu, self.Y) - G_pow_Y
)
mu = - self.sigma * spsp.gamma(-self.Y) * (
np.power(self.M - 1, self.Y) - np.power(self.M, self.Y)
+ np.power(self.G - 1, self.Y) - np.power(self.G, self.Y)
mu = - self.C * gam_Y * (
np.power(self.M - 1., self.Y) - M_pow_Y
+ np.power(self.G - 1., self.Y) - G_pow_Y
)

np.exp(texp*(mu + rv), out=rv)
return rv

0 comments on commit 7f4dc6c

Please sign in to comment.