simdiff: Simulation of diffusion processes

View source: R/simulations_risks.R

simdiffR Documentation

Simulation of diffusion processes

Description

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

Usage

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,
  seed = 123
)

Arguments

n

Number of simulations/scenarios

horizon

Time horizon for simulation

frequency

Frequency of observations: "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)

seed

Random seed for reproducibility

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.

Value

A time series object containing the simulated paths

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)


Techtonique/ESGtoolkit documentation built on June 11, 2025, 6:24 p.m.