source('../Chapter12/utils.R') S0 = 12 mu = 0.15 sigma = 0.2 r = 0.10 delta_t = 1/12 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)) K= 14 n_months = 10 ## Build the stock price lattice: ## SSpot = make_spot_table(S0, u, d, n_months) print('Spot lattice=') print(round(SSpot, 2)) ## Part (a): Price the European call: ## C_European = evaluate_call_option(SSpot, K, q, R, type='European') print('European call option value=') print(round(C_European, 2)) ## Part (b): Price the Pay-Later option: ## pay_later_present_value = function(C, SSpot, K, q, R, type='European'){ ## ## Working backwards evaluate a call option. ## n_steps = dim(SSpot)[2] # = number of columns = number of time units + one column for the initial spot value n_rows = n_steps V = matrix(NA, nrow=n_rows, ncol=n_steps) for( jj in seq(n_rows, 1, -1) ){ for( ii in 1:jj ){ if( jj == n_steps ){ ## the final column/timestep if( SSpot[ii, jj]>K ){ V[ii, jj] = SSpot[ii, jj]-K-C }else{ V[ii, jj] = 0. } }else{ if( type=='European' ){ V[ii, jj] = (q*V[ii, jj+1] + (1-q)*V[ii+1, jj+1])/R } if( type=='American' ){ pv_option = (q*V[ii, jj+1] + (1-q) *V[ii+1, jj+1])/R early_exercise_value = max( c(SSpot[ii, jj]-K, 0) ) V[ii, jj] = max( c(pv_option, early_exercise_value) ) } } } } return(V) } ##PL = pay_later_present_value(2.0, SSpot, K, q, R) ## how to call this function ## For a sequence of C values ca1culate the present value of the pay-later option: ## ns = 100 PV = rep(NA, ns) cs = seq(1.5, 2.5, length.out=ns) for( ci in 1:ns ){ PL = pay_later_present_value(cs[ci], SSpot, K, q, R) PV[ci] = PL[1, 1] } ## Plot this present value: ## ##postscript('../../WriteUp/Graphics/Chapter13/chap_13_ex_11_pay_later_pricing.eps', onefile=FALSE, horizontal=FALSE) plot(cs, PV, type='l', pch=19, xlab='Estimated Premium', ylab='Expected Present Value') abline(h=0, col='red') grid() ##dev.off() mi = which.min(abs(PV)) print(sprintf('C= %f; min(PV)= %f', cs[mi], PV[mi])) ## Print the lattice: ## PL = pay_later_present_value(cs[mi], SSpot, K, q, R) print(round(PL, 2))