random_ohlc: Calculate a random _OHLC_ time series of prices and trading...

View source: R/HighFreq.R

random_ohlcR Documentation

Calculate a random OHLC time series of prices and trading volumes, in xts format.

Description

Calculate a random OHLC time series either by simulating random prices following geometric Brownian motion, or by randomly sampling from an input time series.

Usage

random_ohlc(
  ohlc = NULL,
  reducit = TRUE,
  volat = 6.5e-05,
  drift = 0,
  datev = seq(from = as.POSIXct(paste(Sys.Date() - 3, "09:30:00")), to =
    as.POSIXct(paste(Sys.Date() - 1, "16:00:00")), by = "1 sec"),
  ...
)

Arguments

ohlc

An OHLC time series of prices and trading volumes, in xts format (default is NULL).

volat

The volatility per period of the datev time index (default is 6.5e-05 per second, or about 0.01=1.0% per day).

drift

The drift per period of the datev time index (default is 0.0).

datev

The time index for the OHLC time series.

reducit

Boolean argument: should ohlc time series be transformed to reduced form? (default is TRUE)

Details

If the input ohlc time series is NULL (the default), then the function random_ohlc() simulates a minutely OHLC time series of random prices following geometric Brownian motion, over the two previous calendar days.

If the input ohlc time series is not NULL, then the rows of ohlc are randomly sampled, to produce a random time series.

If reducit is TRUE (the default), then the ohlc time series is first transformed to reduced form, then randomly sampled, and finally converted to standard form.

Note: randomly sampling from an intraday time series over multiple days will cause the overnight price jumps to be re-arranged into intraday price jumps. This will cause moment estimates to become inflated compared to the original time series.

Value

An xts time series with the same dimensions and the same time index as the input ohlc time series.

Examples

# Create minutely synthetic OHLC time series of random prices
ohlc <- HighFreq::random_ohlc()
# Create random time series from SPY by randomly sampling it
ohlc <- HighFreq::random_ohlc(ohlc=HighFreq::SPY["2012-02-13/2012-02-15"])


algoquant/HighFreq documentation built on Feb. 9, 2024, 8:15 p.m.