source('utils.R') sigma = 0.3 S0 = 36 K = 40 r = 0.08 T_months = 5 ## time to expiration print('Monthly timesteps:') delta_t = 1/12 ## monthly timesteps ## Parameters of the stock: ## u = exp(sigma*sqrt(delta_t)) d = 1/u R = 1+ delta_t*r # total return over the next month q = (R - d)/(u - d) print(c(u, d, R, q)) ## Build the stock price grid: ## SSpot = make_spot_table(S0, u, d, T_months) print('Spot lattice=') print(round(SSpot, 2)) P_European = evaluate_put_option(SSpot, K, q, R, type='European') print('European put option_value=') print(round(P_European, 2)) P_American = evaluate_put_option(SSpot, K, q, R, type='American') print('American put option_value=') print(round(P_American, 2)) print('Half-month intervals:') delta_t = (1/12)/2 ## timesteps are every two weeks ## Parameters of the stock: ## u = exp(sigma*sqrt(delta_t)) d = 1/u R = 1+ delta_t*r # total return over the next month q = (R - d)/(u - d) print(c(u, d, R, q)) ## Build the stock price grid: ## SSpot = make_spot_table(S0, u, d, 2*T_months) print('Spot lattice=') print(round(SSpot, 2)) P_European = evaluate_put_option(SSpot, K, q, R, type='European') print('European put option_value=') print(round(P_European, 2)) P_American = evaluate_put_option(SSpot, K, q, R, type='American') print('American put option_value=') print(round(P_American, 2))