calc_endpoints: Calculate a vector of equally spaced end points along the...

Description Usage Arguments Details Value Examples

View source: R/rutils.R

Description

Calculate a vector of equally spaced end points along the elements of a vector, matrix, or time series.

Usage

1
calc_endpoints(x_ts, inter_val, stub_front = TRUE)

Arguments

x_ts

A vector, matrix, or time series.

inter_val

The number of elements between neighboring end points. or a string representing a time period (minutes, hours, days, etc.)

stub_front

A Boolean argument: if TRUE then add a stub interval at the beginning, else add a stub interval at the end. (default is TRUE)

Details

The end points are a vector of integers which divide the elements (rows) of x_ts into equally spaced intervals.

If inter_val is an integer then calc_endpoints() calculates the number of whole intervals that fit over the elements (rows) of x_ts. If a whole number of intervals doesn't fit over the elements (rows) of x_ts, then calc_endpoints() adds a stub interval either at the beginning (the default) or at the end.

If inter_val is a string representing a time period (minutes, hours, days, etc.), then calc_endpoints() simply calls the function endpoints() from package xts.

The function calc_endpoints() is a generalization of function endpoints() from package xts, since inter_val can accept both integer and string values. Similar to xts::endpoints(), the first integer returned by calc_endpoints() is equal to zero.

Value

An integer vector of equally spaced end points (vector of integers).

Examples

1
2
3
4
5
6
# Calculate end points with initial stub interval
rutils::calc_endpoints(1:100, inter_val=11)
# Calculate end points with a stub interval at the end
rutils::calc_endpoints(rutils::etf_env$VTI, inter_val=365, stub_front=FALSE)
# Calculate end points at the end of every hour
rutils::calc_endpoints(rutils::etf_env$VTI, inter_val="hours")

algoquant/rutils documentation built on Feb. 26, 2021, 1:30 a.m.