Simulates various diffusion processes including Geometric Brownian Motion (GBM), Cox-Ingersoll-Ross (CIR), and Ornstein-Uhlenbeck (OU) processes.

simdiff(
  n,
  horizon,
  frequency = c("annual", "semi-annual", "quarterly", "monthly", "weekly", "daily"),
  model = c("GBM", "CIR", "OU"),
  x0,
  theta1 = NULL,
  theta2 = NULL,
  theta3 = NULL,
  lambda = NULL,
  mu_z = NULL,
  sigma_z = NULL,
  p = NULL,
  eta_up = NULL,
  eta_down = NULL,
  eps = NULL,
  start_ = NULL,
  end_ = NULL,
  seed = 123
)

Arguments

n

Number of simulations/scenarios

horizon

Time horizon for simulation

frequency

Frequency of observations: if numeric (as for ts objects), better used with start_ and end_. Otherwise a string, either "annual", "semi-annual", "quarterly", "monthly", "weekly", or "daily"

model

Type of diffusion process: "GBM", "CIR", or "OU"

x0

Initial value

theta1

First parameter (drift for GBM, mean reversion for CIR/OU)

theta2

Second parameter (volatility for GBM, long-term mean for CIR/OU)

theta3

Third parameter (optional, used for some models)

lambda

Jump intensity parameter (optional)

mu_z

Mean of jump size (optional)

sigma_z

Standard deviation of jump size (optional)

p

Probability parameter (optional)

eta_up

Upward jump size (optional)

eta_down

Downward jump size (optional)

eps

Pre-generated random shocks (optional)

start_

Starting time (optional), better used with numeric frequency

end_

Ending time (optional), better used with numeric frequency

seed

Random seed for reproducibility

Value

A time series object containing the simulated paths

Details

The function simulates various diffusion processes with different frequencies. For GBM, theta1 represents the drift and theta2 the volatility. For CIR and OU processes, theta1 is the mean reversion speed and theta2 is the long-term mean.

Examples

# Simulate GBM process
eps <- simshocks(n = 10, horizon = 5, frequency = "quarterly")
sim_GBM <- simdiff(n = 10, horizon = 5, frequency = "quarterly",
                   model = "GBM", x0 = 100, theta1 = 0.03, theta2 = 0.1,
                   eps = eps)

# Simulate CIR process
sim_CIR <- simdiff(n = 10, horizon = 5, frequency = "quarterly",
                   model = "CIR", x0 = 0.04, theta1 = 1.5, theta2 = 0.04,
                   theta3 = 0.2, eps = eps)