sim: Simulation of Open, High, Low, and Close Prices
Description
This function performs simulations consisting of n periods and where each period consists of a given number of trades.
For each trade, the actual price \(P_t\) is simulated as \(P_t = P_{t-1}e^{\sigma x}\), where \(\sigma\) is the standard deviation per trade and \(x\) is a random draw from a unit normal distribution.
The standard deviation per trade equals the volatility divided by the square root of the number of trades.
Trades are assumed to be observed with a given probability.
The bid (ask) for each trade is defined as \(P_t\) multiplied by one minus (plus) half the spread and we assume a 50% chance that a bid (ask) is observed.
High and low prices equal the highest and lowest prices observed during the period.
Open and Close prices equal the first and the last price observed in the period.
If no trade is observed for a period, then the previous Close is used as the Open, High, Low, and Close prices for that period.
A data.frame of open, high, low, and close prices if units=1 (default).
Otherwise, an xts object is returned (requires the xts package to be installed).
Arguments
n
the number of periods to simulate.
trades
the number of trades per period.
prob
the probability to observe a trade.
spread
the bid-ask spread.
volatility
the open-to-close volatility.
overnight
the close-to-open volatility.
drift
the expected return per period.
units
the units of the time period. One of: 1, sec, min, hour, day, week, month, year.
sign
whether to return positive prices for buys and negative prices for sells.
References
Ardia, D., Guidotti, E., Kroencke, T.A. (2024). Efficient Estimation of Bid-Ask Spreads from Open, High, Low, and Close Prices. Journal of Financial Economics, 161, 103916.
tools:::Rd_expr_doi("10.1016/j.jfineco.2024.103916")
# reduce number of threads to pass CRAN checks (you can ignore this)data.table::setDTthreads(1)
# simulate 10 open, high, low, and close prices with spread 1%sim(n = 10, spread = 0.01)