source('utils.R') S0 = 50 K = 50 sigma = 0.2 r = 0.1 D = 3 ## the dividend payment (per share) delta = 3.5/12 ## of a year (when the dividend payment is made) n_months = 6 T = n_months/12 delta_t = 1/12 ## monthly timesteps ## Parameters of the stock: ## u = exp(sigma*sqrt(delta_t)) d = 1/u R = 1 + r/12 # total return over the next month q = (R - d)/(u - d) print(c(u, d, R, q)) ## Build the stock (S*) the random component stock lattice: ## SStarSpot = make_spot_table(S0 - D*exp(-r*delta), u, d, n_months) print('S* (random part) lattice=') print(round(SStarSpot, 2)) ## Compute the true stock price lattice (including the present value of the dividend): ## n_steps = n_months+1 n_rows = n_steps SSpot = matrix(NA, nrow=n_rows, ncol=n_steps) for( jj in 1:n_steps ){ ## Has the dividend been paid yet? ## t = (jj-1)/12 if( t < delta ){ div_part = D*exp(-r* (delta-t)) }else{ div_part = 0 } for( ii in 1:jj ){ SSpot[ii, jj] = SStarSpot[ii, jj] + div_part } } print('Stock Price lattice=') print(round(SSpot, 2)) C_European = evaluate_call_option(SSpot, K, q, R, type='European') print('European call option value=') print(round(C_European, 2)) C_American = evaluate_call_option(SSpot, K, q, R, type='American') print('American call option value=') print(round(C_American, 2))