Adjust-Series {PMwR}R Documentation

Adjust Time Series for Dividends and Splits

Description

Adjust a time series for dividends and splits.

Usage

div_adjust(x, t, div, backward = TRUE, additive = FALSE)

split_adjust(x, t, ratio, backward = TRUE)

Arguments

x

a numeric vector: the series to be adjusted

t

An integer vector, specifying the positions in x at which dividends were paid (‘ex-days’) or at which a split occurred. Timestamps may be duplicated, e.g. several payments may occur on a single timestamp.

div

A numeric vector, specifying the dividends (or payments, cashflows). If necessary, recycled to the length of t.

ratio

a numeric vector, specifying the split ratios. The ratio must be ‘American Style’: a 2-for-1 stock split, for example, corresponds to a ratio of 2. (In other countries, for instance Germany, a 2-for-1 stock split would be called a 1-for-1 split: you keep your shares and receive one new share per share that you own.)

backward

logical; see Details

additive

logical; see Details

Details

The function transforms xx into returns, and with those returns specified in tt calculated as

xt+Dtxt11,\frac{x_t + D_t}{x_{t-1}} - 1\,,

in which xx is the price, DD are dividends and tt is time. The adjusted xx is then reconstructed from those returns.

When additive is TRUE, dividends are simply added back to the series; see Examples.

With backward set to TRUE, which is the default, the final prices in the unadjusted series matches the final prices in the adjusted series.

Value

a numeric vector of length equal to length(x)

Author(s)

Enrico Schumann

References

Schumann, E. (2023) Portfolio Management with R. https://enricoschumann.net/PMwR/

Using div_adjust for handling generic external cashflows: https://enricoschumann.net/R/packages/PMwR/manual/PMwR.html#returns-with-external-cashflows

Examples

x <- c(9.777, 10.04, 9.207, 9.406)
div <- 0.7
t <- 3

div_adjust(x, t, div)
div_adjust(x, t, div, FALSE)



## assume there were three splits: adjust shares outstanding
shares <- c(100, 100, 200, 200, 1000, 1500)
t <- c(3, 5, 6)
ratio <- c(2, 5, 1.5)
### => invert ratio
split_adjust(shares, t, 1/ratio)
## [1] 1500 1500 1500 1500 1500 1500

split_adjust(shares, t, 1/ratio, backward = FALSE)
## [1] 100 100 100 100 100 100



## 'additive' ** FALSE ** (default setting)
x <- c(100, 95, 100, 95, 100)
div <- 5
t <- c(2, 4)
div_adjust(x, t, div)
## 90.25  90.25  95.00  95.00 100.00
returns(div_adjust(x, t, div))
## 0.00000000 0.05263158 0.00000000 0.05263158
## ==> reflect _actual_ returns 100/95 - 1

## 'additive' ** TRUE **
div_adjust(x, t, div, additive = TRUE)
## 90  90  95  95 100
returns(div_adjust(x, t, div, additive = TRUE))
## 0.00000000 0.05555556 0.00000000 0.05263158
## ==> reflect return 95/90 - 1

[Package PMwR version 0.19-5 Index]