ohlc_returns | R Documentation |
Calculate single period percentage returns from either TAQ or OHLC prices.
ohlc_returns(xtsv, lagg = 1, colnum = 4, scalit = TRUE)
xtsv |
An xts time series of either TAQ or OHLC data. |
lagg |
An integer equal to the number of time periods of lag. (default is 1) |
colnum |
The column number to extract from the OHLC data.
(default is |
scalit |
Boolean argument: should the returns be divided by the
number of seconds in each period? (default is |
The function ohlc_returns()
calculates the percentage returns
for either TAQ or OHLC data, defined as the difference of log
prices. Multi-period returns can be calculated by setting the lag
parameter to values greater than 1
(the default).
If scalit
is TRUE
(the default), then the returns are divided
by the differences of the time index (which scales the returns to units of
returns per second.)
The time index of the xtsv
time series is assumed to be in
POSIXct format, so that its internal value is equal to the number of
seconds that have elapsed since the epoch.
If scalit
is TRUE
(the default), then the returns are
expressed in the scale of the time index of the xtsv
time series.
For example, if the time index is in seconds, then the returns are given in
units of returns per second. If the time index is in days, then the
returns are equal to the returns per day.
The function ohlc_returns()
identifies the xtsv
time series as
TAQ data when it has six columns, otherwise assumes it's OHLC
data. By default, for OHLC data, it differences the Close
prices, but can also difference other prices depending on the value of
colnum
.
A single-column xts time series of returns.
# Calculate secondly returns from TAQ data
returns <- HighFreq::ohlc_returns(xtsv=HighFreq::SPY_TAQ)
# Calculate close to close returns
returns <- HighFreq::ohlc_returns(xtsv=HighFreq::SPY)
# Calculate open to open returns
returns <- HighFreq::ohlc_returns(xtsv=HighFreq::SPY, colnum=1)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.