fileID = fopen('data.txt');
formatSpec = '%d';
data = fscanf(fileID,formatSpec);
t = 0:80;
x = 45;
y = empirical_distribution(t, data, x);
plot(t,y)
hold on



mu=0.01;
sigma = 0.1;
up_weight = 1;
down_weight = 1;
up_exp = 1/0.02;
down_exp = 1/0.02;
up_freq = 20;
down_freq = 20;

mu=0.01;
sigma = 0.1;
up_weight = 1;
down_weight = 1;
up_exp = 2;
down_exp = 2;
up_freq = 0;
down_freq = 0;

mu=0.01;
sigma = 0.1;
up_weight =[0.2,0.5,0.3];
down_weight =[0.2,0.5,0.3];
up_exp = [1/0.03,1/0.02,1/0.01] ; %from small to big
down_exp =[1/0.03, 1/0.02,1/0.01]; %from small to big
up_freq = 20;
down_freq = 20;


S_initial = 200;
K = 205;
H = 210;
gamma = 0.9;
L = 210;   
interest_rate = 0.02;


lb = phi(mu, sigma, up_weight, down_weight, up_exp, down_exp, up_freq,down_freq,1)
lambda_0 = [0.05, 0.1, 0.2, 0.5]; % lambda_0 should be larger than lb.
lambda_0 = [0.05, 0.08, 0.12, 0.2, 0.3, 0.5];
lambda_0 = [0.05, 0.06, 0.08, 0.10, 0.12, 0.20, 0.40, 0.60];
lambda_0 = [0.05, 0.06, 0.08, 0.10, 0.12, 0.20, 0.40, 0.50,  0.60, 0.80];

[lambda,linear_coeff] = fit_nonlinear(lambda_0,t,data,x, lb);
A = exp(-t.'* lambda);
f_fit = linear_coeff * A';
plot(t,f_fit);



s = life_stock_expect(mu, sigma, up_weight, down_weight, up_exp, down_exp, up_freq,down_freq, lambda, S_initial, linear_coeff, interest_rate)

[put, call]= life_vanilla(mu, sigma, up_weight, down_weight, up_exp, down_exp, up_freq,down_freq, lambda, K, S_initial, linear_coeff, interest_rate)

[put, call]= life_fixed_lookback(mu, sigma, up_weight, down_weight, up_exp, down_exp, up_freq,down_freq, lambda, K, H, S_initial, linear_coeff, interest_rate)

[name, price] = life_float_lookback(mu, sigma, up_weight, down_weight, up_exp, down_exp, up_freq,down_freq, lambda, H, S_initial, linear_coeff, interest_rate)

[name, price] = life_fractional_float_lookback(mu, sigma, up_weight, down_weight, up_exp, down_exp, up_freq,down_freq, lambda, gamma, S_initial, linear_coeff, interest_rate)

[put, call]= life_knock_in(mu, sigma, up_weight, down_weight, up_exp, down_exp, up_freq,down_freq, lambda, K, L, S_initial, linear_coeff, interest_rate)

[put, call]= life_knock_out(mu, sigma, up_weight, down_weight, up_exp, down_exp, up_freq,down_freq, lambda, K, L, S_initial, linear_coeff, interest_rate)














