# In this script we price a bond according to the market yield and estimate its
# Present Value Sensitivity using Duration and Convexity using continuous 
# compounding. 



library(tidyverse)

# Market yield (computed in`S3.Estimating the market yield curve by replication.R`)
load("Examples/market.yield.curve.Rdata")
market.yield.curve

# Let's use continuous compounding. Select the appropriate columns and change the
# yield column name to "y_t".
market.yield.curve






# Let's consider the following bond.
coupon.rate <- 0.05
face.value <- 100
maturity <- 5

# Price the bond (please add a first line full of zeros)
bond.market.price.tbl










save(bond.market.price.tbl, file = "Examples/bond.market.price.tbl.Rdata")

# Please compute the sensitivity measures - Duration and Convexity

sensitivity









# Now let us consider a parallel shift of 1% (\delta\bar{y} = 0.01) and 
# approximate the bond price accordingly.
paral.shift <- -0.01

sensitivity







sensitivity$approx.1st.order
sensitivity$approx.2nd.order

# Let us check what would be the exact new value (homework - similar to part of
# the script 'S2.Example spot rates, forward rates and bond valuation.R')

pert <- c(0,rep(1,5))*paral.shift
pert
bond.price.perturbed.1

