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.
Diese Übung ist Teil des Kurses
Quantitative Risk Management in R
Anleitung zur Übung
- Compute the log-returns of
zcbaszcb_xand the simple log-returns aszcb_x2. - Plot
zcb_xfor 1, 5 and 10-year maturities in one plot. - Plot
zcb_x2for 1, 5 and 10-year maturities in one plot. - Index
zcbinplot()to plot the yield curve for the first day inzcb. - Index
zcbinlines()to add a line to the yield curve for the last day inzcb.
Interaktive Übung
Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.
# 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, ___)