# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3 (ipykernel)
#     language: python
#     name: python3
# ---

import numpy as np
import matplotlib.pyplot as plt


# # Siu et al 2004 Gamma Garch Option Pricing

def Y(r,v,a,h,Xt):
    """equation 3.12 siu et al"""
    return r + v*h**0.5 - 0.5* h - (a*h)**0.5 + Xt
def h(omega,alpha,beta,a,ht,Xt):
    """equation 3.13 siu et al"""
    return omega + alpha*(Xt - (a*ht)**0.5)**2 + beta*ht
def htalt(a,v,h):
    """equation 3.14 siu et al"""
    return a**2 * (1- np.exp((v*h**0.5 - 0.5 * h - (a*h)**0.5)/a))
def X(a,b):
    """returns gamma / Xt in siu et al"""
    return np.random.gamma(a, b, 1)[0] 
def b(v,h,a):
    """equation 3.11 in siu et al"""
    return 1/((1- np.exp((v*h**0.5 - 0.5 * h - (a*h)**0.5)/a)))


# +
omega = 0.00003577
alpha = 0.155966
beta = 0.646049
v = 0.04873824 # lambda in siu et al
r = 0.001 # risk free rate r
ht = 1.4 # starting value for variance
a = 4 # shape parameter for gamma distribution
print ("{:<6} {:<6} {:<6} {:<6}".format('bt','Xt','ht', "Yt"))

myb = []
myX = []
myh = []
myY = []

for i in range(25):
    bt = b(v,ht,a)
    Xt = X(a, bt)
    ht = h(omega,alpha,beta,a,ht,Xt)
    #ht = htalt(a,v,ht)
    Yt = Y(r,v,a,ht,Xt)
    print ("{:<6.4f} {:<6.4f} {:<6.4f} {:<6.4f}".format( bt, Xt, ht, Yt))
    myb.append(bt), myX.append(Xt), myh.append(ht), myY.append(Yt) 
    
# -

plt.figure(figsize = (12,8))
plt.subplot(111)
plt.plot(myb, color = "blue", label = "bt")
plt.plot(myX, color = "black", label = "Xt")
plt.plot(myh, color = "red", label = "ht")
plt.plot(myY, color = "yellow", label = "Yt")
plt.legend()





StarcoderdataJupyterScriptsDedupFiltered