Adjust for stock splits and dividends
Stock splits can create large historical price changes even though they do not change the value of the company. So, you must adjust all pre-split prices in order to calculate historical returns correctly.
Similarly, you must adjust all pre-dividend prices. Dividends do reduce the company's value by the amount of the dividend payment, but the investor's return isn't affected because they receive the offsetting dividend payment.
In this exercise, you will learn how to use the adjustOHLC()
function to adjust raw historical OHLC prices for splits and dividends, so historical returns can be calculated accurately.
Yahoo Finance provides raw prices and a split- and dividend-adjusted close column. The output of adjustOHLC()
should match Yahoo's adjusted close column. AAPL
data from Yahoo Finance is already loaded in your workspace.
While not necessary to complete this exercise, Yahoo Finance provides an accessible example of the adjusted close calculation, if you're interested in learning more.
This is a part of the course
“Importing and Managing Financial Data in R”
Exercise instructions
- Look at the first few rows of
AAPL
- Use
adjustOHLC()
to adjust theAAPL
data. Assign the result to an object namedaapl_adjusted
. - Look at the first few rows of
aapl_adjusted
. Notice the close column ofaapl_adjusted
is the same as the adjusted close column ofAAPL
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Look at first few rows of AAPL
# Adjust AAPL for splits and dividends
# Look at first few rows of aapl_adjusted