def calc_prices(spot : float, epsilon : float): vol1 = 0.04 vol2 = 0.01 kappa1 = 2 kappa2 = 0.1 theta1 = 0.04 theta2 = 0.01 epsilon1 = 0.5 epsilon2 = 2 rho1 = -0.7 rho2 = 0.8 rate = 0.05 tau = 1.005 #set to match option data strike = 100 some_option = vo.EUCall(tau, strike) some_model = hm.HestonClass(spot, vol1, kappa1, theta1, epsilon, rho1, rate) # case 1 some_model2 = hm.HestonClass(spot, vol2, kappa2, theta2, epsilon, rho2, rate) al1 = al.Andersen_Lake(some_model, some_option) mc1 = mc.Heston_monte_carlo(some_model, some_option, 10000) al2 = al.Andersen_Lake(some_model2, some_option) mc2 = mc.Heston_monte_carlo(some_model2, some_option, 10000) return al1, mc1, al2, mc2
def calcPrice(inputArray : np.array, optionList : np.array) -> np.array: someModel = hm.HestonClass(inputArray[0], inputArray[1], inputArray[2], inputArray[3], inputArray[4], inputArray[5], inputArray[6]) outputLenght = np.shape(optionList)[0] output = np.empty(outputLenght, dtype=np.float64) for i in range(outputLenght): try: output[i] = al.Andersen_Lake(someModel, optionList[i]) except: #overflow in char function, set impvol to 0 output[i] = 0 return output
def calc_imp_vol(input_array: np.array, option_list: list) -> (np.array, np.array): some_model = hm.HestonClass(input_array[0], input_array[1], input_array[2], input_array[3], input_array[4], input_array[5], input_array[6]) output_lenght = np.shape(option_list)[0] output_price = np.zeros(output_lenght, dtype=np.float64) output_imp_vol = np.zeros(output_lenght, dtype=np.float64) for i in range(output_lenght): try: output_price[i] = al.Andersen_Lake(some_model, option_list[i]) output_imp_vol[i] = some_model.impVol(output_price[i], option_list[i]) except: #overflow in char function, set impvol to 0 output_price[i] = 0 output_imp_vol[i] = 0 return output_price, output_imp_vol
some_spot = spot_plot[i] some_spot_low = some_spot - h some_spot_low2 = some_spot - 0.5 * h some_spot_high = some_spot + h some_spot_high2 = some_spot + 0.5 * h ### Andersen Lake FD ### Easy hm_c = hm.HestonClass(some_spot, vol1, kappa1, theta1, epsilon1, rho1, rate) hm_low = hm.HestonClass(some_spot_low, vol1, kappa1, theta1, epsilon1, rho1, rate) hm_low2 = hm.HestonClass(some_spot_low2, vol1, kappa1, theta1, epsilon1, rho1, rate) hm_high = hm.HestonClass(some_spot_high, vol1, kappa1, theta1, epsilon1, rho1, rate) hm_high2 = hm.HestonClass(some_spot_high2, vol1, kappa1, theta1, epsilon1, rho1, rate) al_f_x = al.Andersen_Lake(hm_c, some_option) al_f_x_p = al.Andersen_Lake(hm_high, some_option) al_f_x_p2 = al.Andersen_Lake(hm_high2, some_option) al_f_x_m = al.Andersen_Lake(hm_low, some_option) al_f_x_m2 = al.Andersen_Lake(hm_low2, some_option) price_easy_al[i] = al_f_x delta_easy_al[i] = ((al_f_x_p2 - al_f_x_m2) / h ) gamma_easy_al[i] = (al_f_x_p - 2 * al_f_x + al_f_x_m) / (h * h) ### Hard hm_c_hard = hm.HestonClass(some_spot, vol2, kappa2, theta2, epsilon2, rho2, rate) hm_low_hard = hm.HestonClass(some_spot_low, vol2, kappa2, theta2, epsilon2, rho2, rate) hm_high_hard = hm.HestonClass(some_spot_high, vol2, kappa2, theta2, epsilon2, rho2, rate) hm_low_hard2 = hm.HestonClass(some_spot_low2, vol2, kappa2, theta2, epsilon2, rho2, rate) hm_high_hard2 = hm.HestonClass(some_spot_high2, vol2, kappa2, theta2, epsilon2, rho2, rate)
print(put_price) call_price = put_price - np.exp(-some_model.rate * some_option.tau) * ( some_option.strike - some_model.forward) else: call_price = np.exp(-some_model.rate * some_option.tau) * (np.average( some_option(forward))) return call_price if __name__ == '__main__': test_model = hm.HestonClass(50, 0.01, 0.1, 0.01, 2, 0.8, 0.05) test_option = vo.EUCall(0.01, 100) print(Heston_monte_carlo(test_model, test_option, 5000)) print(Heston_monte_carlo(test_model, test_option, 5000, True)) print(al.Andersen_Lake(test_model, test_option)) """ model_input = np.loadtxt("Data/MC/HestonMC_input.csv", delimiter=",") mc_imp_vol_1 = np.loadtxt("Data/MC/Heston_mc_imp_vol_1.csv", delimiter=",") mc_price_1 = np.loadtxt("Data/MC/HestonMC_price_1.csv", delimiter=",") mc_imp_vol_10 = np.loadtxt("Data/MC/Heston_mc_imp_vol_10.csv", delimiter=",") mc_price_10 = np.loadtxt("Data/MC/HestonMC_price_10.csv", delimiter=",") mc_imp_vol_100 = np.loadtxt("Data/MC/Heston_mc_imp_vol_100.csv", delimiter=",") mc_price_100 = np.loadtxt("Data/MC/HestonMC_price_100.csv", delimiter=",") mc_imp_vol_1000 = np.loadtxt("Data/MC/Heston_mc_imp_vol_1000.csv", delimiter=",") mc_price_1000 = np.loadtxt("Data/MC/HestonMC_price_1000.csv", delimiter=",") mc_imp_vol_10000 = np.loadtxt("Data/MC/Heston_mc_imp_vol_10000.csv", delimiter=",") mc_price_10000 = np.loadtxt("Data/MC/HestonMC_price_10000.csv", delimiter=",") if not (os.path.exists("Data/train_index_200000.csv") and os.path.exists("Data/test_index_200000.csv")):
import numpy as np import itertools import matplotlib.pyplot as plt from matplotlib import cm import joblib from keras.models import load_model import glob from sklearn.metrics import mean_squared_error as mse from sklearn.preprocessing import MinMaxScaler, StandardScaler from keras.optimizers import Adam import os import itertools import pickle from Thesis.Heston import AndersenLake as al, HestonModel as hm, DataGeneration as dg, ModelGenerator as mg, MC_al, ModelTesting as mt from Thesis.misc import VanillaOptions as vo from Thesis.BlackScholes import BlackScholes as bs some_easy_case = mt.easy_case() some_heston_model = hm.HestonClass(*some_easy_case[0]) some_option = vo.EUCall(2, 75) al.Andersen_Lake(some_heston_model, some_option)
import numpy as np import time import matplotlib.pyplot as plt from Thesis.Heston import AndersenLake as al, MonteCarlo as mc, HestonModel as hm from Thesis.misc import VanillaOptions as vo model_input = np.loadtxt("Data/benchmark_input.csv", delimiter=",") #imp_vol = np.loadtxt("Data/benchmark_input.csv", delimiter = ",") some_model = hm.HestonClass(*model_input[0]) some_option = vo.EUCall(0.1, 87.5) price = al.Andersen_Lake(some_model, some_option) print(price) imp_vol = some_model.impVol(price, some_option) print(imp_vol)