## ----setup, include = FALSE---------------------------------------------------
knitr::opts_chunk$set(
  collapse = TRUE,
  comment  = "#>",
  echo     = TRUE,
  message  = FALSE,
  warning  = FALSE,
  fig.width  = 6,
  fig.height = 4
)

## ----simulate, fig.width=6, fig.height=4--------------------------------------
library(JumpDiffSim)

# Create a MertonModel S4 object with default parameters
m <- MertonModel(
  mu      =  0.05,   # drift
  sigma   =  0.20,   # diffusion volatility
  lambda  =  1,      # average jumps per year
  mu_j    = -0.10,   # mean log-jump size
  sigma_j =  0.15    # std dev of log-jumps
)

# Display the model
show(m)

# Simulate 200 paths over 1 year with 252 daily steps
sim <- simulateMerton(m, n = 200, T_ = 1, steps = 252, seed = 42)

# Diagnostic plots
plts <- diagnosticPlots(sim)
print(plts$fan_chart)
print(plts$density)

## ----fit----------------------------------------------------------------------
# Generate reproducible synthetic log-returns
# (all examples use jdSampleData() -- no internet required)
ret <- jdSampleData("merton", n = 500, seed = 42)

# Fit the Merton model via Maximum Likelihood Estimation
fit <- fitMerton(ret, verbose = FALSE)

# Parameter estimates and convergence
print(fit)

# 95% Wald confidence intervals
confint(fit)

## ----moments------------------------------------------------------------------
# Theoretical mean, variance, skewness, and excess kurtosis
# contributed by the jump component
jumpMoments(m)

