sim_df | R Documentation |
Simulate a Dickey-Fuller process using Rcpp.
sim_df(prici, priceq, theta, coeff, innov)
prici |
The initial price. |
priceq |
The equilibrium price. |
theta |
The strength of mean reversion. |
coeff |
A single-column matrix of autoregressive coefficients. |
innov |
A single-column matrix of innovations (random numbers). |
The function sim_df()
simulates the following Dickey-Fuller
process:
r_i = \theta \, (\mu - p_{i-1}) + \varphi_1 r_{i-1} + \ldots + \varphi_n r_{i-n} + \xi_i
p_i = p_{i-1} + r_i
Where r_i
and p_i
are the simulated returns and prices,
\theta
and \mu
are the Ornstein-Uhlenbeck parameters,
\varphi_i
are the autoregressive coefficients, and
\xi_i
are the normal innovations.
The recursion starts with: r_1 = \xi_1
and p_1 = init\_price
.
The Dickey-Fuller process is a combination of an
Ornstein-Uhlenbeck process and an autoregressive process.
The order n
of the autoregressive process AR(n)
, is
equal to the number of rows of the autoregressive coefficients
coeff
.
The function sim_df()
simulates the Dickey-Fuller
process using fast Rcpp C++
code.
The function sim_df()
returns a single-column matrix
representing the time series of 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 <- 1.0
priceq <- 2.0
thetav <- 0.01
# Define AR coefficients
coeff <- matrix(c(0.1, 0.3, 0.5))
# Calculate matrix of standard normal innovations
innov <- matrix(rnorm(1e3, sd=0.01))
# Simulate Dickey-Fuller process using Rcpp
prices <- HighFreq::sim_df(prici=prici, priceq=priceq, theta=thetav, coeff=coeff, innov=innov)
plot(prices, t="l", main="Simulated Dickey-Fuller Prices")
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.