to_period: Aggregate an _OHLC_ time series to a lower periodicity.

Description Usage Arguments Details Value Examples

View source: R/rutils.R

Description

Given an OHLC time series at high periodicity (say seconds), calculates the OHLC prices at a lower periodicity (say minutes).

Usage

1
2
3
4
5
6
to_period(
  oh_lc,
  period = "minutes",
  k = 1,
  end_points = xts::endpoints(oh_lc, period, k)
)

Arguments

oh_lc

An OHLC time series of prices in xts format.

period

aggregation interval ("seconds", "minutes", "hours", "days", "weeks", "months", "quarters", and "years").

k

The number of periods to aggregate over (for example if period="minutes" and k=2, then aggregate over two minute intervals.)

end_points

An integer vector of end points.

Details

The function to_period() performs a similar aggregation as function xts::to.period() from package xts, but has the flexibility to aggregate to a user-specified vector of end points. The function to_period() simply calls the compiled function toPeriod() (from package xts), to perform the actual aggregations. If end_points are passed in explicitly, then the period argument is ignored.

Value

A OHLC time series of prices in xts format, with a lower periodicity defined by the end_points.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
## Not run: 
# Define end points at 10-minute intervals (HighFreq::SPY is minutely bars)
end_points <- rutils::calc_endpoints(HighFreq::SPY["2009"], inter_val=10)
# Aggregate over 10-minute end_points:
rutils::to_period(oh_lc=HighFreq::SPY["2009"], end_points=end_points)
# Aggregate over days:
rutils::to_period(oh_lc=HighFreq::SPY["2009"], period="days")
# Equivalent to:
xts::to.period(x=HighFreq::SPY["2009"], period="days", name=rutils::get_name(colnames(HighFreq::SPY)[1])

## End(Not run)

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