sim_ou | R Documentation |
Simulate an Ornstein-Uhlenbeck process using Rcpp.
sim_ou(prici, priceq, theta, innov)
prici |
The initial price. |
priceq |
The equilibrium price. |
theta |
The strength of mean reversion. |
innov |
A single-column matrix of innovations (random numbers). |
The function sim_ou()
simulates the following
Ornstein-Uhlenbeck process:
r_i = p_i - p_{i-1} = \theta \, (\mu - p_{i-1}) + \xi_i
p_i = p_{i-1} + r_i
Where r_i
and p_i
are the simulated returns and prices,
\theta
, \mu
, and \sigma
are the
Ornstein-Uhlenbeck parameters, and \xi_i
are the standard
innovations.
The recursion starts with: r_1 = \xi_1
and p_1 = init\_price
.
The function sim_ou()
simulates the percentage returns as equal to
the difference between the equilibrium price \mu
minus the latest
price p_{i-1}
, times the mean reversion parameter \theta
, plus
a random normal innovation. The log prices are calculated as the sum of
returns (not compounded), so they can become negative.
The function sim_ou()
simulates the Ornstein-Uhlenbeck
process using fast Rcpp C++
code.
The function sim_ou()
returns a single-column matrix
representing the time series of simulated prices.
A single-column matrix of simulated prices, with the same
number of rows as the argument innov
.
## Not run:
# Define the Ornstein-Uhlenbeck model parameters
prici <- 0.0
priceq <- 1.0
sigmav <- 0.01
thetav <- 0.01
innov <- matrix(rnorm(1e3))
# Simulate Ornstein-Uhlenbeck process using Rcpp
prices <- HighFreq::sim_ou(prici=prici, priceq=priceq, volat=sigmav, theta=thetav, innov=innov)
plot(prices, t="l", main="Simulated Ornstein-Uhlenbeck Prices", ylab="prices")
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.