source('utils.R') ## rent is in millions: rent_cost = 2 ##rent_cost = 0 # building the grid with this value you will see that you will never harvest u = 1.2 d = 0.9 r = 0.10 S0 = 5 ## the inital value of the trees (in millions) R = 1 + r # total return over the next year q = (R - d)/(u - d) print(c(u, d, R, q)) n_years = 10 delta_t = 1 ## yearly steps growth_factor = c(1, 1.6, 1.5, 1.4, 1.3, 1.2, 1.15, 1.1, 1.05, 1.02, 1.01) sum_growth_factor = cumprod(growth_factor) print(round(growth_factor, 2)) print(round(sum_growth_factor, 2)) ## Build the value lattice: ## SSpot = make_spot_table(S0, u, d, n_years) print('Spot (number value) lattice=') print(round(SSpot, 2)) ## Price the "as you like it" option by working backwards: ## n_years = length(growth_factor)-1 n_steps = n_years+1 LV = matrix(NA, nrow=n_steps, ncol=n_steps) ## the value of the number Harvest = matrix(NA, nrow=n_steps, ncol=n_steps) ## whether to harvest the number at this node for( jj in seq(n_years+1, 1, -1) ){ for( ii in 1:jj ){ if( jj == (n_years+1) ){ ## the final column/timestep LV[ii, jj] = SSpot[ii, jj] * sum_growth_factor[jj] ## you must cut at the end of the 10th year Harvest[ii, jj] = 1 }else{ cut_trees = SSpot[ii, jj] * sum_growth_factor[jj] rent = -rent_cost + (q*LV[ii, jj+1] + (1-q) *LV[ii+1, jj+1])/R LV[ii, jj] = max(c(cut_trees, rent)) if( cut_trees > rent ){ Harvest[ii, jj] = 1 }else{ Harvest[ii, jj] = 0 } } } } print('Lumber value lattice=') print(round(LV, 2)) print('Cut trees at this node or not') print(round(Harvest, 2))