sim | R Documentation |
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
)
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: |
sign |
whether to return positive prices for buys and negative prices for sells. |
Simulated open, high, low, and close prices.
Please cite Ardia, Guidotti, & Kroencke (2024) when using this package in publication.
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. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1016/j.jfineco.2024.103916")}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.