sim_df: Simulate a _Dickey-Fuller_ process using _Rcpp_.

View source: R/RcppExports.R

sim_dfR Documentation

Simulate a Dickey-Fuller process using Rcpp.

Description

Simulate a Dickey-Fuller process using Rcpp.

Usage

sim_df(init_price, eq_price, theta, coeff, innov)

Arguments

init_price

The initial price.

eq_price

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).

Details

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.

Value

A single-column matrix of simulated prices, with the same number of rows as the argument innov.

Examples

## Not run: 
# Define the Ornstein-Uhlenbeck model parameters
init_price <- 1.0
eq_price <- 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(init_price=init_price, eq_price=eq_price, theta=thetav, coeff=coeff, innov=innov)
plot(prices, t="l", main="Simulated Dickey-Fuller Prices")

## End(Not run)


algoquant/HighFreq documentation built on Feb. 9, 2024, 8:15 p.m.