Learn R Programming

quantmod (version 0.4-5)

adjustOHLC: Adjust Open,High,Low,Close Prices For Splits and Dividends

Description

Adjust all columns of an OHLC object for split and dividend.

Usage

adjustOHLC(x, adjust = c("split","dividend"), use.Adjusted = FALSE, ratio = NULL, symbol.name=deparse(substitute(x)))

Arguments

x
An OHLC object
adjust
adjust by split, dividend, or both (default)
use.Adjusted
use the ‘Adjusted’ column in Yahoo! data to adjust
ratio
ratio to adjust with, bypassing internal calculations
symbol.name
used if x is not named the same as the symbol adjusting

Value

An object of the original class, with prices adjusted for splits and dividends.

Warning

Using use.Adjusted = TRUE will be less precise than the method that employs actual split and dividend information. This is due to loss of precision from Yahoo! using Adjusted columns of only two decimal places. The advantage is that this can be run offline, and for short series or those with few adjustments the loss of precision will be small. The resulting precision loss will be from row observation to row observation, as the calculation will be exact for intraday values.

Details

This function calculates the adjusted Open, High, Low, and Close prices according to split and dividend information.

There are three methods available to calculate the new OHLC object prices.

By default, getSplits and getDividends are called to retrieve the respective information. These may dispatch to custom methods following the “.” methodology used by quantmod dispatch. See getSymbols for information related to extending quantmod. This information is passed to adjRatios from the TTR package, and the resulting ratio calculations are used to adjust to observed historical prices. This is the most precise way to adjust a series.

The second method works only on standard Yahoo! data containing an explicit Adjusted column.

A final method allows for one to pass a ratio into the function directly.

All methods proceed as follows:

New columns are derived by taking the ratio of adjusted value to original Close, and multiplying by the difference of the respective column and the original Close. This is then added to the modified Close column to arrive at the remaining ‘adjusted’ Open, High, Low column values.

If no adjustment is needed, the function returns the original data unaltered.

References

Yahoo Finance http://finance.yahoo.com

See Also

getSymbols.yahoo getSplits getDividends

Examples

Run this code
## Not run: 
# getSymbols("AAPL", from="1990-01-01", src="yahoo")
# head(AAPL)
# head(AAPL.a <- adjustOHLC(AAPL))
# head(AAPL.uA <- adjustOHLC(AAPL, use.Adjusted=TRUE))
# 
# # intrada adjustments are precise across all methods
# # an example with Open to Close (OpCl)
# head(cbind(OpCl(AAPL),OpCl(AAPL.a),OpCl(AAPL.uA)))
# 
# # Close to Close changes ma lose precision
# head(cbind(ClCl(AAPL),ClCl(AAPL.a),ClCl(AAPL.uA)))
# ## End(Not run)

Run the code above in your browser using DataLab