Learn R Programming

tsbox (version 0.3.1)

ts_index: Indices from Levels or Percentage Rates

Description

ts_index returns an indexed series, with value of 1 at the base date or range. ts_compound builds an index from percentage change rates, starting with 1 and compounding the rates.

Usage

ts_compound(x, denominator = 100)

ts_index(x, base = NULL)

Value

a ts-boxable time series, with the same class as the input.

Arguments

x

ts-boxable time series, an object of class ts, xts, zoo, data.frame, data.table, tbl, tbl_ts, tbl_time, tis, irts or timeSeries.

denominator

numeric, set equal to one if percentage change rate is given a decimal fraction

base

base date, character string, Date or POSIXct, at which the index is set to 1. If two dates are provided, the average with the range is set equal to 1 (see examples).

Examples

Run this code
head(ts_compound(ts_pc(ts_c(fdeaths, mdeaths))))
head(ts_index(ts_df(ts_c(fdeaths, mdeaths)), "1974-02-01"))
# \donttest{
ts_plot(
  `My Expert Knowledge` = ts_chain(
    mdeaths,
    ts_compound(ts_bind(ts_pc(mdeaths), 15, 23, 33))),
  `So Far` = mdeaths,
  title = "A Very Manual Forecast"
)

# average of 1974 = 1
ts_index(mdeaths, c("1974-01-01", "1974-12-31"))
# }

Run the code above in your browser using DataLab