Plotting consecutive portfolio returns
Regression to the mean is also an important concept in investing. Here you'll look at the annual returns from investing in companies in the Standard and Poor 500 index (S&P 500), in 2018 and 2019.
The sp500_yearly_returns
dataset contains three columns:
variable | meaning |
---|---|
symbol | Stock ticker symbol uniquely identifying the company. |
return_2018 | A measure of investment performance in 2018. |
return_2019 | A measure of investment performance in 2019. |
A positive number for the return means the investment increased in value; negative means it lost value.
Just as with baseball home runs, a naive prediction might be that the investment performance stays the same from year to year, lying on the "y equals x" line.
sp500_yearly_returns
is available and ggplot2
is loaded.
This exercise is part of the course
Introduction to Regression in R
Exercise instructions
- Using
sp500_yearly_returns
, draw a scatter plot ofreturn_2019
vs.return_2018
. - Add an "A-B line", colored
"green"
, with size1
. - Add a smooth trend line made with the linear regression method, and no standard error ribbon.
- Fix the coordinates so distances along the x and y axes appear the same.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Using sp500_yearly_returns, plot return_2019 vs. return_2018
___ +
# Make it a scatter plot
___ +
# Add a line at y = x, colored green, size 1
___ +
# Add a linear regression trend line, no std. error ribbon
___ +
# Fix the coordinate ratio
___