Graphically compare the simple and continuously compounded returns
In this exercise, you will create a plot that contains both the simple and continuously compounded returns. This makes it easy to compare both types of returns.
Have a look at the sample code on the right. First of all, we have to plot the simple returns as a function of time. The argument type = l
specifies a line plot, col = blue
specifies that the simple returns line is blue, lwd = 2
specifies the line thickness, ylab = "Return"
specifies that "Return"
is the label of the y-axis and main
specifies the plot's main title.
This exercise is part of the course
Intro to Computational Finance with R
Exercise instructions
- Your task is to add the continuously compounded returns to the plot. This can be done with the
lines()
function, havingsbux_ccret
as a first argument. Furthermore, the line should be red and its thickness should be set to 2. You can do that by setting thecol
andlwd
arguments.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# The simple returns (sbux_ret) and the continuously compounded returns (sbux_ccret) have been preloaded in your workspace
# Plot the returns on the same graph
plot(sbux_ret, type = "l", col = "blue", lwd = 2, ylab = "Return", main = "Monthly Returns on SBUX")
# Add horizontal line at zero
abline(h = 0)
# Add a legend
legend(x = "bottomright", legend = c("Simple", "CC"), lty = 1, lwd = 2, col = c("blue", "red"))
# Add the continuously compounded returns