Different ways of plotting risk-factor and return series
You already know that you can use plot.zoo() to plot multiple time series. For a four-dimensional time series data, the call plot.zoo(data) creates four separate plots by default, unless you include the parameter plot.type = "single" to plot all four series in one plot. You can also add even more parameters such as col to specify different colors and type = "h" to get vertical bars instead of joining points, which can sometimes be a better way of displaying returns.
plot.zoo(x, plot.type, col = 1, type = "l", ...)
In this exercise, you will explore the plot.zoo() function to plot equity risk-factor data and the corresponding returns in different ways. The multivariate time series djstocks and DJ_const are available in your workspace.
Diese Übung ist Teil des Kurses
Quantitative Risk Management in R
Anleitung zur Übung
- Plot
djstocksin four separate plots. - Plot
djstocksin one plot in colors 1 to 4. The code to create an appropriate legend for the plot is provided. - Compute the log-returns of
djstocksand assign them todjstocks_x. - Plot
djstocks_xin four separate plots. - Plot
djstocks_xin four separate plots with vertical bars.
Interaktive Übung
Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.
# Plot djstocks in four separate plots
___(___)
# Plot djstocks in one plot and add legend
___(___, ___, ___)
legend(julian(x = as.Date("2009-01-01")), y = 70, legend = names(DJ_const)[1:4], fill = 1:4)
# Compute log-returns and assign to djstocks_x
djstocks_x <- ___(___)
# Plot djstocks_x in four separate plots
___(___)
# Plot djstocks_x with vertical bars
___(___, ___)