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

View source: R/rutils.R

calc_endpointsR Documentation

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

Description

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

Usage

calc_endpoints(xtsv, interval, stub_front = TRUE)

Arguments

xtsv

A vector, matrix, or time series.

interval

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 xtsv into equally spaced intervals.

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

If interval 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 interval 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

# Calculate end points with initial stub interval
rutils::calc_endpoints(1:100, interval=11)
# Calculate end points with a stub interval at the end
rutils::calc_endpoints(rutils::etfenv$VTI, interval=365, stub_front=FALSE)
# Calculate end points at the end of every hour
rutils::calc_endpoints(rutils::etfenv$VTI, interval="hours")

algoquant/rutils documentation built on April 18, 2024, 12:05 a.m.