Interest-rate data
The object zcb
contains daily values of Canadian zero-coupon-bond yields, expressed as percentages, for the period 2006-2015. Yields are the key risk-factor when it comes to analysing the interest-rate risk in a portfolio of bonds or other fixed-income products.
It is not so clear what is the best way of calculating risk-factor changes for yields. It is possible to compute log-returns, provided yields are not negative, and it is also possible to calculate simple returns. To compute the simple returns of a series, use only diff()
instead of diff()
and log()
.
In this exercise, you will plot time series of yields for fixed times to maturity, and plot risk-factor changes for these yields. You will also plot the whole yield curve on particular dates. The zcb
data has been loaded into your workspace. A vector yield_cols
containing the names of the columns corresponding to maturities of 1, 5 and 10 years has been created. A numerical vector maturity
containing all the maturities in years has also been created.
This exercise is part of the course
Quantitative Risk Management in R
Exercise instructions
- Compute the log-returns of
zcb
aszcb_x
and the simple log-returns aszcb_x2
. - Plot
zcb_x
for 1, 5 and 10-year maturities in one plot. - Plot
zcb_x2
for 1, 5 and 10-year maturities in one plot. - Index
zcb
inplot()
to plot the yield curve for the first day inzcb
. - Index
zcb
inlines()
to add a line to the yield curve for the last day inzcb
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Compute log-returns as zcb_x and simple returns as zcb_x2
zcb_x <- ___(___)
zcb_x2 <- ___(___)
# Plot zcb_x for 1, 5 and 10-year maturities
___(___)
# Plot zcb_x2 for 1, 5 and 10-year maturities
___(___)
# Plot the yield curve for the first day of zcb
plot(maturity, ___, ylim = range(zcb), type = "l", ylab = "yield (%)", col = "red")
# Add a line for the last day of zcb
lines(maturity, ___)