to_period | R Documentation |
Given an OHLC time series at high periodicity (say seconds), calculates the OHLC prices at a lower periodicity (say minutes).
to_period(
timeser,
period = "minutes",
k = 1,
endpoints = xts::endpoints(timeser, period, k)
)
timeser |
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
|
endpoints |
An integer vector of end points. |
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 endpoints
are passed in
explicitly, then the period
argument is ignored.
A OHLC time series of prices in xts format, with a lower periodicity defined by the endpoints.
## Not run:
# Define end points at 10-minute intervals (HighFreq::SPY are minutes bars)
endd <- rutils::calc_endpoints(HighFreq::SPY["2009"], interval=10)
# Aggregate over 10-minute endpoints:
ohlc <- rutils::to_period(timeser=HighFreq::SPY["2009"], endpoints=endd)
# Aggregate over days:
ohlc <- rutils::to_period(timeser=HighFreq::SPY["2009"], period="days")
# Equivalent to:
ohlc <- xts::to.period(x=HighFreq::SPY["2009"], period="days", name=rutils::get_name(colnames(HighFreq::SPY)[1])
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.