sim_schwartz: Simulate a _Schwartz_ process using _Rcpp_.

View source: R/RcppExports.R

sim_schwartzR Documentation

Simulate a Schwartz process using Rcpp.

Description

Simulate a Schwartz process using Rcpp.

Usage

sim_schwartz(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_schwartz() simulates a Schwartz process using fast Rcpp C++ code.

The Schwartz process is the exponential of the Ornstein-Uhlenbeck process, and similar comments apply to it. The prices are calculated as the exponentially compounded returns, so they are never negative. The log prices can be obtained by taking the logarithm of the prices.

The function sim_schwartz() 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 function sim_schwartz() 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 Schwartz model parameters
init_price <- 1.0
eq_price <- 2.0
thetav <- 0.01
innov <- matrix(rnorm(1e3, sd=0.01))
# Simulate Schwartz process using Rcpp
prices <- HighFreq::sim_schwartz(init_price=init_price, eq_price=eq_price, theta=thetav, innov=innov)
plot(prices, t="l", main="Simulated Schwartz Prices", ylab="prices")

## End(Not run)


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