Adjust univariate data for splits and dividends
If you only have close prices, you can adjust them with adjRatios()
. It has 3 arguments: splits
, dividends
, and close
. It returns an xts object with split and dividend adjustment ratios in columns "Split"
and "Div"
, respectively.
You need to provide split data via the splits
argument to calculate the split ratio. To calculate the dividend ratio, you need to provide raw dividends and raw prices via the dividends
and close
arguments, respectively.
Once you have the split and dividend adjustment ratios, you calculate the adjusted price multiplying the unadjusted price by both the split and dividend adjustment ratios.
Your workspace contains splits
, dividends
, and raw_dividends
from prior exercises, and AAPL
data from Yahoo Finance.
This exercise is part of the course
Importing and Managing Financial Data in R
Exercise instructions
- Use
adjRatios()
to calculate the split and dividend adjustment ratios. Assign the output toratios
. - Calculate the adjusted close for AAPL by extracting the close price and multiplying it by both adjustment ratios and assign it to
aapl_adjusted
. - Look at the first few rows of the adjusted close column provided by Yahoo Finance.
- Look at the first few rows of the adjusted close price you calculated, and compare that to the adjusted close from Yahoo Finance.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Calculate split and dividend adjustment ratios
ratios <- adjRatios(splits = ___, dividends = ___, close = Cl(___))
# Use the Split and Div columns to calculate adjusted close for AAPL
aapl_adjusted <- Cl(___) * ratios[, "___"] * ratios[, "___"]
# Look at first few rows of adjusted close for AAPL
___(Ad(___))
# Look at first few rows of aapl_adjusted