This function performs simulations consisting of n
periods (e.g., days) 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.
sim(
n = 10000,
trades = 390,
prob = 1,
spread = 0.01,
volatility = 0.03,
overnight = 0,
drift = 0,
units = "day",
sign = FALSE
)
Simulated open, high, low, and close prices.
the number of periods to simulate.
the number of trades per period.
the probability to observe a trade.
the bid-ask spread.
the open-to-close volatility.
the close-to-open volatility.
the expected return per period.
the units of the time period. One of: sec
, min
, hour
, day
, week
, month
, year
.
whether to return positive prices for buys and negative prices for sells.
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")