sim_ou: Simulate an _Ornstein-Uhlenbeck_ process using _Rcpp_.

View source: R/RcppExports.R

sim_ouR Documentation

Simulate an Ornstein-Uhlenbeck process using Rcpp.

Description

Simulate an Ornstein-Uhlenbeck process using Rcpp.

Usage

sim_ou(init_price, eq_price, theta, innov)

Arguments

init_price

The initial price.

eq_price

The equilibrium price.

theta

The strength of mean reversion.

innov

A single-column matrix of innovations (random numbers).

Details

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.

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 <- 0.0
eq_price <- 1.0
sigmav <- 0.01
thetav <- 0.01
innov <- matrix(rnorm(1e3))
# Simulate Ornstein-Uhlenbeck process using Rcpp
prices <- HighFreq::sim_ou(init_price=init_price, eq_price=eq_price, volat=sigmav, theta=thetav, innov=innov)
plot(prices, t="l", main="Simulated Ornstein-Uhlenbeck Prices", ylab="prices")

## End(Not run)


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