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

## ----gaussian-sv1-------------------------------------------------------------
library(wARMASVp)
set.seed(123)

# Simulate
sim <- sim_svp(2000, phi = 0.95, sigy = 1, sigv = 0.3)
y <- sim$y

# Estimate
fit <- svp(y, p = 1, J = 10)
summary(fit)

## ----gaussian-sv2-------------------------------------------------------------
y2 <- sim_svp(2000, phi = c(0.20, 0.63), sigy = 1, sigv = 0.5)$y
fit2 <- svp(y2, p = 2, J = 10)
summary(fit2)

## ----student-t----------------------------------------------------------------
yt <- sim_svp(2000, phi = 0.90, sigy = 1, sigv = 0.3,
              errorType = "Student-t", nu = 5)$y
fit_t <- svp(yt, p = 1, errorType = "Student-t")
summary(fit_t)

## ----ged----------------------------------------------------------------------
yg <- sim_svp(2000, phi = 0.90, sigy = 1, sigv = 0.3,
              errorType = "GED", nu = 1.5)$y
fit_ged <- svp(yg, p = 1, errorType = "GED")
summary(fit_ged)

## ----leverage-----------------------------------------------------------------
sim_lev <- sim_svp(2000, phi = 0.95, sigy = 1, sigv = 0.3,
                   leverage = TRUE, rho = -0.5)
fit_lev <- svp(sim_lev$y, p = 1, leverage = TRUE)
summary(fit_lev)

## ----leverage-t---------------------------------------------------------------
sim_lev_t <- sim_svp(2000, phi = 0.90, sigy = 1, sigv = 0.3,
                     errorType = "Student-t", nu = 5,
                     leverage = TRUE, rho = -0.5)
fit_lev_t <- svp(sim_lev_t$y, p = 1, errorType = "Student-t", leverage = TRUE)
summary(fit_lev_t)

## ----test-ar------------------------------------------------------------------
y_test <- sim_svp(2000, phi = 0.95, sigy = 1, sigv = 0.3)$y

# H0: SV(1) vs H1: SV(2) — should not reject
test_ar <- lmc_ar(y_test, p_null = 1, p_alt = 2, N = 49)
print(test_ar)

## ----test-lev-----------------------------------------------------------------
test_lev <- lmc_lev(y_test, p = 1, N = 49, Amat = "Weighted")
print(test_lev)

## ----test-dist----------------------------------------------------------------
# Test H0: nu = 10 (mild tails) on Student-t data with true nu = 5
test_t <- lmc_t(yt, nu_null = 10, N = 49, Amat = "Weighted")
print(test_t)

# Directional test: H1: nu < 10 (heavier tails than null)
test_t_dir <- lmc_t(yt, nu_null = 10, N = 49, Amat = "Weighted", direction = "less")
print(test_t_dir)

## ----filtering----------------------------------------------------------------
# Fit model
fit_filt <- svp(y, p = 1, J = 10)

# GMKF (recommended)
filt <- filter_svp(fit_filt, method = "mixture")
plot(filt)

## ----forecast-----------------------------------------------------------------
fit_fc <- svp(sim_lev$y, p = 1, leverage = TRUE)
fc <- forecast_svp(fit_fc, H = 20)
plot(fc)

