source('../Chapter12/utils.R') source('../Chapter14/utils.R') r0 = 0.06 u = 1.2 d = 0.9 ## Get the grid of spot rates: ## n_years = 10 rrate = make_spot_table(r0, u, d, n_years) rrate = upper_triangular_to_ascending_triangle(rrate) print('Short rate lattice=') print(round(rrate, 3)) E0 = short_rate_lattice_to_elementary_prices(rrate) print(round(E0, 3)) ## Sum the columns of the elemntary price grid: ## E0[is.na(E0)] = 0 E00 = colSums(E0) print('Bond prices=') print(E00) ks = 0:(n_years+1) sk = (1/E00)^(1/ks) - 1 sk_pct = sk * 100 print('Forward rates=') print(round(sk_pct, 2))