### Simulate Copula-GARCH Model Source: https://context7.com/alexiosg/rmgarch/llms.txt Simulates a Copula-GARCH model with specified simulation parameters, starting from a sample. ```r cgarch_sim <- cgarchsim( cgarch_fit, n.sim = 500, m.sim = 100, startMethod = "sample" ) ``` -------------------------------- ### Get Time-Varying Copula Correlations Source: https://context7.com/alexiosg/rmgarch/llms.txt Extracts the time-varying copula correlations from a fitted Copula-GARCH model. ```r R_copula <- rcor(cgarch_fit) ``` -------------------------------- ### Simulate GO-GARCH Model Source: https://context7.com/alexiosg/rmgarch/llms.txt Simulates a GO-GARCH model with specified parameters. Requires a fitted GO-GARCH object. ```r gogarch_sim <- gogarchsim( object = gogarch_fit, n.sim = 250, n.start = 50, m.sim = 500, startMethod = "sample", rseed = 123 ) ``` -------------------------------- ### Simulate VAR Model Source: https://context7.com/alexiosg/rmgarch/llms.txt Simulates a VAR model using provided coefficients, data, and residuals. Requires pre-return data and simulated residuals. ```r var_sim <- varxsim( X = returns, Bcoef = var_fit$Bcoef, p = 2, n.sim = 500, n.start = 50, prereturns = tail(returns, 2), resids = matrix(rnorm(500 * 5), ncol = 5), mexsimdata = NULL ) ``` -------------------------------- ### GO-GARCH Forecast and Simulation Source: https://context7.com/alexiosg/rmgarch/llms.txt Produces forecasts and simulations from GO-GARCH models, including higher-order moment support. ```r library(rmgarch) data(dji30ret) returns <- dji30ret[, 1:5] # Fit GO-GARCH with out-of-sample gogarch_spec <- gogarchspec( mean.model = list(model = "constant"), variance.model = list(model = "sGARCH", garchOrder = c(1, 1)), distribution.model = "manig", ica = "fastica" ) gogarch_fit <- gogarchfit(gogarch_spec, data = returns, out.sample = 50) # Forecast gogarch_fcst <- gogarchforecast( fit = gogarch_fit, n.ahead = 10, n.roll = 49 # Rolling forecasts using out-of-sample ) # Extract forecasts fitted(gogarch_fcst) sigma(gogarch_fcst, factors = FALSE) # Asset volatilities (not factor) # Forecast correlations rcor(gogarch_fcst) ``` -------------------------------- ### Calculate GO-GARCH Portfolio Distribution using FFT Source: https://context7.com/alexiosg/rmgarch/llms.txt Calculates the exact portfolio distribution for GO-GARCH models with non-Gaussian distributions using Fast Fourier Transform (FFT) convolution. ```r library(rmgarch) data(dji30ret) returns <- dji30ret[, 1:5] ``` -------------------------------- ### DCC-GARCH Simulation Source: https://context7.com/alexiosg/rmgarch/llms.txt Simulates paths from a fitted DCC-GARCH model for Monte Carlo analysis and scenario generation. ```r library(rmgarch) library(rugarch) data(dji30retw) returns <- dji30retw[, 1:5] # Fit DCC model uspec <- ugarchspec( mean.model = list(armaOrder = c(1, 1)), variance.model = list(garchOrder = c(1, 1), model = "sGARCH"), distribution.model = "norm" ) dcc_spec <- dccspec( uspec = multispec(replicate(5, uspec)), dccOrder = c(1, 1), distribution = "mvnorm" ) dcc_fit <- dccfit(dcc_spec, data = returns) # Simulate from fitted model dcc_sim <- dccsim( fitORspec = dcc_fit, n.sim = 500, # Simulation horizon n.start = 100, # Burn-in period m.sim = 1000, # Number of Monte Carlo simulations startMethod = "sample", # Use sample ending values to start rseed = 42 # For reproducibility ) # Extract simulated series sim_returns <- fitted(dcc_sim, sim = 1) # First simulation path # Get simulated correlations sim_R <- rcor(dcc_sim, sim = 1) # Get simulated covariances sim_H <- rcov(dcc_sim, sim = 1) # Access all simulation paths for VaR calculation all_sims <- sapply(1:100, function(i) fitted(dcc_sim, sim = i)[500, 1]) VaR_95 <- quantile(all_sims, 0.05) ``` -------------------------------- ### Backtest Portfolio VaR Source: https://context7.com/alexiosg/rmgarch/llms.txt Performs a backtest on calculated Value-at-Risk (VaR) against actual portfolio returns at a 1% significance level. ```r actual_returns <- as.numeric(returns %*% weights) VaRTest(0.01, actual = actual_returns, VaR = VaR_1pct) ``` -------------------------------- ### Calculate Portfolio VaR (Normal) Source: https://context7.com/alexiosg/rmgarch/llms.txt Calculates the Value-at-Risk at the 1% level for a portfolio assuming a multivariate normal distribution, using calculated portfolio margins. ```r VaR_1pct <- qdist("norm", 0.01, port_margin[, 1], port_margin[, 2], 0, 0, 0) ``` -------------------------------- ### GO-GARCH Specification and Fit Source: https://context7.com/alexiosg/rmgarch/llms.txt Implements factor-based multivariate volatility modeling using Independent Component Analysis. ```r library(rmgarch) data(dji30ret) returns <- dji30ret[, 1:5] # GO-GARCH specification with affine NIG distribution gogarch_spec <- gogarchspec( mean.model = list( model = "VAR", # Options: "constant", "AR", "VAR" lag = 2, robust = FALSE ), variance.model = list( model = "sGARCH", garchOrder = c(1, 1), variance.targeting = FALSE ), distribution.model = "manig", # Multivariate affine NIG ica = "fastica" # ICA algorithm: "fastica" or "radical" ) # Fit GO-GARCH model gogarch_fit <- gogarchfit( spec = gogarch_spec, data = returns, out.sample = 50, solver = "solnp", gfun = "tanh" # ICA nonlinearity function ) # View results print(gogarch_fit) # Extract mixing matrix A (maps factors to returns) A <- as.matrix(gogarch_fit, which = "A") # Extract whitening matrix K K <- as.matrix(gogarch_fit, which = "K") # Get dynamic covariance and correlation H <- rcov(gogarch_fit) R <- rcor(gogarch_fit) # Higher-order co-moments (unique to GO-GARCH) coskew <- rcoskew(gogarch_fit, from = 1, to = 100) # Coskewness tensor cokurt <- rcokurt(gogarch_fit, from = 1, to = 100) # Cokurtosis tensor ``` -------------------------------- ### Forecast with VAR Model Source: https://context7.com/alexiosg/rmgarch/llms.txt Generates VAR forecasts for a specified number of steps ahead, rolling the forecast sample. ```r var_fcst <- varxforecast( X = returns, Bcoef = var_fit$Bcoef, p = 2, out.sample = 50, n.ahead = 10, n.roll = 0, mregfor = NULL ) ``` -------------------------------- ### Generate VAR-based scenarios Source: https://context7.com/alexiosg/rmgarch/llms.txt Creates scenarios using a Vector Autoregression model for multivariate data. ```r var_scenarios <- fscenario( Data = returns, sim = 1000, roll = 0, model = "var", var.model = list(lag = 2, robust = FALSE), cov.method = "ML" ) ``` -------------------------------- ### Calculate Portfolio Moments from Forecast Source: https://context7.com/alexiosg/rmgarch/llms.txt Calculates portfolio moments (mean, sigma, skewness, kurtosis) from a GO-GARCH forecast object using specified weights. ```r weights <- rep(1/5, 5) port_moments <- gportmoments(gogarch_fcst, weights = weights) ``` -------------------------------- ### Fit DCC-GARCH Model in R Source: https://context7.com/alexiosg/rmgarch/llms.txt Estimates a DCC-GARCH model using a two-stage approach. Can utilize pre-fitted univariate models for efficiency. Use for estimating time-varying correlations. ```r library(rmgarch) library(rugarch) library(parallel) data(dji30retw) returns <- dji30retw[, 1:5] # Define univariate specification uspec <- ugarchspec( mean.model = list(armaOrder = c(1, 1)), variance.model = list(garchOrder = c(1, 1), model = "gjrGARCH"), distribution.model = "norm" ) # Create multispec and fit univariate models first (optional but useful) mspec <- multispec(replicate(5, uspec)) multfit <- multifit(mspec, returns) # Create DCC specification dcc_spec <- dccspec( uspec = mspec, dccOrder = c(1, 1), distribution = "mvnorm" ) # Fit DCC model (passing pre-fitted univariate models) dcc_fit <- dccfit( spec = dcc_spec, data = returns, out.sample = 50, # Keep 50 observations for out-of-sample testing solver = "solnp", fit.control = list(eval.se = TRUE, stationarity = TRUE), fit = multfit # Pass pre-fitted univariate models ) # View model summary print(dcc_fit) # Extract DCC parameters coef(dcc_fit, type = "dcc") # Returns: dcca1, dccb1 # Extract log-likelihood likelihood(dcc_fit) # Get dynamic correlation matrices R <- rcor(dcc_fit) # Returns 3D array [assets x assets x time] print(R[1, 2, 1:5]) # Correlation between asset 1 and 2, first 5 periods # Get dynamic covariance matrices H <- rcov(dcc_fit) # Returns 3D array [assets x assets x time] # Extract fitted values and residuals mu <- fitted(dcc_fit) # Conditional means sigma <- sigma(dcc_fit) # Conditional volatilities resid <- residuals(dcc_fit) # Residuals ``` -------------------------------- ### Moment-based Forecast Generation Source: https://context7.com/alexiosg/rmgarch/llms.txt Generates forecast covariance and higher co-moment matrices for DCC and GO-GARCH models. ```r library(rmgarch) data(dji30ret) returns <- dji30ret[, 1:5] # DCC-based moment forecasts dcc_spec <- dccspec( uspec = multispec(replicate(5, ugarchspec( mean.model = list(armaOrder = c(1, 0)), variance.model = list(garchOrder = c(1, 1)), distribution.model = "norm" ))), dccOrder = c(1, 1), distribution = "mvnorm" ) moments_dcc <- fmoments( spec = dcc_spec, Data = returns, n.ahead = 5, roll = 10, # Rolling estimation solver = "solnp" ) # Access forecast moments # moments_dcc contains forecast covariance matrices # GO-GARCH-based moment forecasts (includes higher moments) gogarch_spec <- gogarchspec( mean.model = list(model = "constant"), variance.model = list(model = "sGARCH", garchOrder = c(1, 1)), distribution.model = "manig", ica = "fastica" ) moments_gogarch <- fmoments( spec = gogarch_spec, Data = returns, n.ahead = 1, roll = 20, solver = "solnp" ) ``` -------------------------------- ### Scenario Generation Source: https://context7.com/alexiosg/rmgarch/llms.txt Generates Monte Carlo scenarios for risk management using various multivariate models. ```r library(rmgarch) data(dji30ret) returns <- dji30ret[, 1:5] # DCC-based scenario generation dcc_spec <- dccspec( uspec = multispec(replicate(5, ugarchspec( mean.model = list(armaOrder = c(1, 0)), variance.model = list(garchOrder = c(1, 1)), distribution.model = "norm" ))), dccOrder = c(1, 1), distribution = "mvnorm" ) scenarios <- fscenario( Data = returns, sim = 1000, # Number of scenarios roll = 10, # Rolling scenarios for backtesting model = "dcc", # Options: "gogarch", "dcc", "cgarch", "var", "mdist" spec = dcc_spec, solver = "solnp", rseed = 42 ) # Extract simulated scenarios sim_returns <- fitted(scenarios) # Simulated return scenarios # Access forecast conditional mean and covariance scenarios@scenario$forecastMu scenarios@scenario$forecastCov ``` -------------------------------- ### Fit GO-GARCH with NIG distribution Source: https://context7.com/alexiosg/rmgarch/llms.txt Configures and fits a GO-GARCH model using the NIG distribution and FastICA for independent component analysis. ```r gogarch_spec <- gogarchspec( mean.model = list(model = "AR", lag = 2), variance.model = list(model = "sGARCH", garchOrder = c(1, 1)), distribution.model = "manig", ica = "fastica" ) gogarch_fit <- gogarchfit(gogarch_spec, data = returns, gfun = "tanh") # Portfolio weights weights <- rep(1/5, 5) # Geometric (analytical) portfolio moments geom_moments <- gportmoments(gogarch_fit, weights = weights) # Returns: mu, sigma, skewness, kurtosis for each time point # FFT-based convolution for exact portfolio density conv <- convolution( gogarch_fit, weights = weights, fft.step = 0.001, fft.by = 0.0001, fft.support = c(-1, 1), use.ff = TRUE, # Use ff package for large arrays support.method = "adaptive" ) # Semi-analytic (FFT) portfolio moments fft_moments <- nportmoments(conv) # Get portfolio density function at specific time df <- dfft(conv, index = 100) x_vals <- seq(-0.1, 0.1, by = 0.001) density_vals <- df(x_vals) # Get portfolio quantile function for VaR qf <- qfft(conv, index = 100) VaR_1pct <- qf(0.01) VaR_5pct <- qf(0.05) # Sample from portfolio distribution using inverse transform set.seed(42) u <- runif(10000) portfolio_samples <- qf(u) ``` -------------------------------- ### Fit Copula-GARCH Model Source: https://context7.com/alexiosg/rmgarch/llms.txt Fits a Copula-GARCH model to the provided return data using the 'solnp' solver and evaluating standard errors. ```r cgarch_fit <- cgarchfit( spec = cgarch_spec, data = returns, solver = "solnp", fit.control = list(eval.se = TRUE) ) ``` -------------------------------- ### Specify Copula-GARCH Model Source: https://context7.com/alexiosg/rmgarch/llms.txt Specifies a Copula-GARCH model with time-varying correlation using a Student copula and DCC for dependence. ```r cgarch_spec <- cgarchspec( uspec = multispec(replicate(5, uspec)), VAR = FALSE, dccOrder = c(1, 1), asymmetric = TRUE, # Use aDCC for copula correlation distribution.model = list( copula = "mvt", # Student copula method = "ML", # Maximum Likelihood estimation time.varying = TRUE, # Dynamic copula transformation = "parametric" # Options: parametric, empirical, spd ) ) ``` -------------------------------- ### Calculate Weighted Portfolio Margins (Student-t) Source: https://context7.com/alexiosg/rmgarch/llms.txt Calculates portfolio mean and volatility using specified weights, conditional means, and conditional covariances from a DCC fit with a Student-t distribution. ```r port_margin_t <- wmargin( distribution = "mvt", weights = weights, mean = fitted(dcc_fit_t), Sigma = rcov(dcc_fit_t), shape = coef(dcc_fit_t, "dcc")["mshape"] ) ``` -------------------------------- ### Create DCC-GARCH Specification in R Source: https://context7.com/alexiosg/rmgarch/llms.txt Defines a DCC-GARCH specification object. Supports symmetric, asymmetric, and Flexible DCC models with different multivariate distributions. Use for setting up DCC models. ```r library(rmgarch) library(rugarch) # Load example data (Dow Jones 30 weekly returns) data(dji30retw) returns <- dji30retw[, 1:5] # Create univariate GARCH specification for each asset uspec <- ugarchspec( mean.model = list(armaOrder = c(1, 1)), variance.model = list(garchOrder = c(1, 1), model = "sGARCH"), distribution.model = "norm" ) # Create DCC specification with multivariate normal distribution dcc_spec <- dccspec( uspec = multispec(replicate(5, uspec)), dccOrder = c(1, 1), model = "DCC", distribution = "mvnorm" ) # Create asymmetric DCC specification with Student-t distribution adcc_spec <- dccspec( uspec = multispec(replicate(5, uspec)), dccOrder = c(1, 1), model = "aDCC", distribution = "mvt" ) # Create DCC with VAR for conditional mean var_dcc_spec <- dccspec( uspec = multispec(replicate(5, uspec)), VAR = TRUE, lag = 2, dccOrder = c(1, 1), distribution = "mvnorm" ) ``` -------------------------------- ### Calculate Weighted Portfolio Margins (Normal) Source: https://context7.com/alexiosg/rmgarch/llms.txt Calculates portfolio mean and volatility using specified weights, conditional means, and conditional covariances from a DCC fit with a normal distribution. ```r weights <- rep(1/10, 10) port_margin <- wmargin( distribution = "mvnorm", weights = weights, mean = fitted(dcc_fit), # Conditional means Sigma = rcov(dcc_fit), # Conditional covariances shape = NA, skew = NA ) ``` -------------------------------- ### Extracting Forecast Metrics Source: https://context7.com/alexiosg/rmgarch/llms.txt Methods for retrieving forecast means, correlations, and covariances from a forecast object. ```r fitted(forecast_ahead) # Returns n.ahead x n.assets x (n.roll+1) array # Extract forecast correlations R_fcst <- rcor(forecast_ahead) # List of correlation matrices # For rolling forecasts, access each roll sapply(rcor(forecast_roll), function(x) x[1, 2, 1]) # Pairwise correlation forecasts # Extract forecast covariances H_fcst <- rcov(forecast_ahead) ``` -------------------------------- ### Forecast with DCC-GARCH Model in R Source: https://context7.com/alexiosg/rmgarch/llms.txt Generates multi-step ahead or rolling forecasts from a fitted DCC-GARCH model. Supports unconditional n-ahead and rolling 1-ahead forecasts. Use for predicting future correlations. ```r library(rmgarch) library(rugarch) data(dji30retw) returns <- dji30retw[, 1:5] # Fit DCC model with out-of-sample data uspec <- ugarchspec( mean.model = list(armaOrder = c(1, 1)), variance.model = list(garchOrder = c(1, 1), model = "sGARCH"), distribution.model = "norm" ) dcc_spec <- dccspec( uspec = multispec(replicate(5, uspec)), dccOrder = c(1, 1), distribution = "mvnorm" ) dcc_fit <- dccfit(dcc_spec, data = returns, out.sample = 100) # Multi-step ahead unconditional forecast forecast_ahead <- dccforecast( fit = dcc_fit, n.ahead = 50, # 50-step ahead forecast n.roll = 0 # No rolling ) # Rolling 1-step ahead forecast using out-of-sample data forecast_roll <- dccforecast( fit = dcc_fit, n.ahead = 1, n.roll = 99 # 100 rolling forecasts (1 base + 99 additional) ) ``` -------------------------------- ### Extract Copula-GARCH Results Source: https://context7.com/alexiosg/rmgarch/llms.txt Prints the fitted Copula-GARCH model object and extracts its coefficients. ```r print(cgarch_fit) cof(cgarch_fit) ``` -------------------------------- ### DCC-GARCH Rolling Estimation Source: https://context7.com/alexiosg/rmgarch/llms.txt Performs rolling window estimation and forecasting for backtesting with automatic refitting. ```r library(rmgarch) library(rugarch) data(dji30ret) returns <- dji30ret[, 1:5] # Define specification uspec <- ugarchspec( mean.model = list(armaOrder = c(1, 0)), variance.model = list(model = "gjrGARCH"), distribution.model = "norm" ) dcc_spec <- dccspec( uspec = multispec(replicate(5, uspec)), dccOrder = c(1, 1), distribution = "mvlaplace" ) # Rolling estimation with refitting every 25 observations dcc_roll <- dccroll( spec = dcc_spec, data = returns, n.ahead = 1, forecast.length = 500, # Total forecast period refit.every = 25, # Refit every 25 observations refit.window = "moving", # Moving window (vs "recursive") solver = "solnp", fit.control = list(eval.se = FALSE) ) # Extract rolling forecasts sigma_roll <- sigma(dcc_roll) rcor_roll <- rcor(dcc_roll) rcov_roll <- rcov(dcc_roll) # Get likelihood across rolls likelihood(dcc_roll) # Plot rolling correlation plot(dcc_roll, which = 4, series = c(1, 2, 3)) ``` -------------------------------- ### Perform FastICA Independent Component Analysis Source: https://context7.com/alexiosg/rmgarch/llms.txt Implements the FastICA algorithm to extract independent components from mixed signals. ```r library(rmgarch) # Create mixed signals set.seed(100) S <- matrix(runif(10000), 5000, 2) # Independent sources A <- matrix(c(1, 1, -1, 2), 2, 2, byrow = TRUE) # Mixing matrix X <- S %*% t(A) # Mixed signals # Apply FastICA ica_result <- fastica( X = X, approach = "symmetric", # Options: "symmetric", "deflation" n.comp = 2, demean = TRUE, pca.cov = "ML", # Options: "ML", "LW", "ROB", "EWMA" gfun = "tanh", # Options: "pow3", "tanh", "gauss", "skew" epsilon = 1e-4, maxiter1 = 1000, rseed = 42, trace = TRUE ) # Results ica_result$A # Estimated mixing matrix ica_result$W # Unmixing matrix ica_result$S # Estimated independent components ica_result$whiteningMatrix ica_result$dewhiteningMatrix # Verify: S_hat %*% t(A_hat) should approximate original X reconstructed <- ica_result$S %*% t(ica_result$A) all.equal(head(X), head(reconstructed), tolerance = 1e-10) ``` -------------------------------- ### Fit DCC Model with Student-t Distribution Source: https://context7.com/alexiosg/rmgarch/llms.txt Fits a Dynamic Conditional Correlation (DCC) model with univariate GJR-GARCH specifications and a multivariate Student-t distribution. ```r dcc_spec_t <- dccspec( uspec = multispec(replicate(10, uspec)), dccOrder = c(1, 1), distribution = "mvt" ) dcc_fit_t <- dccfit(dcc_spec_t, data = returns) ``` -------------------------------- ### Specify Univariate GARCH Model Source: https://context7.com/alexiosg/rmgarch/llms.txt Defines a univariate GARCH model specification with ARMA(1,1) mean, GJR-GARCH(1,1) variance, and Student-t distribution. ```r uspec <- ugarchspec( mean.model = list(armaOrder = c(1, 1)), variance.model = list(garchOrder = c(1, 1), model = "gjrGARCH"), distribution.model = "std" # Student-t margins ) ``` -------------------------------- ### Fit VAR(2) Model Source: https://context7.com/alexiosg/rmgarch/llms.txt Estimates a Vector Autoregressive model of order 2 with a constant term, using standard estimation. ```r var_fit <- varxfit( X = returns, p = 2, # VAR lag order constant = TRUE, # Include constant robust = FALSE, # Use robust estimation postpad = "constant" # Padding method for residuals ) ``` -------------------------------- ### Extract VAR Model Results Source: https://context7.com/alexiosg/rmgarch/llms.txt Extracts various components from a fitted VAR model, including coefficients, fitted values, residuals, standard errors, and t-statistics. ```r var_fit$Bcoef # Coefficient matrix var_fit$xfitted # Fitted values (conditional mean) var_fit$xresiduals # Residuals var_fit$se # Standard errors var_fit$tstat # t-statistics ``` -------------------------------- ### Fit DCC Model with Normal Distribution Source: https://context7.com/alexiosg/rmgarch/llms.txt Fits a Dynamic Conditional Correlation (DCC) model with univariate GJR-GARCH specifications and a multivariate normal distribution. ```r uspec <- ugarchspec( mean.model = list(armaOrder = c(1, 1)), variance.model = list(garchOrder = c(1, 1), model = "gjrGARCH"), distribution.model = "norm" ) dcc_spec <- dccspec( uspec = multispec(replicate(10, uspec)), dccOrder = c(1, 1), distribution = "mvnorm" ) dcc_fit <- dccfit(dcc_spec, data = returns) ``` -------------------------------- ### Correlation Distance Visualization Source: https://context7.com/alexiosg/rmgarch/llms.txt Computes and plots rolling distance measures between correlation matrices to identify regime shifts. ```r library(rmgarch) data(dji30retw) returns <- dji30retw[, 1:10] # Fit DCC model uspec <- ugarchspec( mean.model = list(armaOrder = c(1, 0)), variance.model = list(garchOrder = c(1, 1)), distribution.model = "norm" ) dcc_spec <- dccspec( uspec = multispec(replicate(10, uspec)), dccOrder = c(1, 1), distribution = "mvnorm" ) dcc_fit <- dccfit(dcc_spec, data = returns) R <- rcor(dcc_fit) # Calculate correlation distance with various measures dist_matrix <- cordist( R = R, distance = "cmd", # Options: "ma", "ms", "meda", "meds", "eigen", "cmd" n = 25, # Distance between correlation snapshots plot = TRUE, dates = as.POSIXct(rownames(returns)), title = "Correlation Matrix Distance Over Time" ) ``` -------------------------------- ### Filter New Data with VAR Coefficients Source: https://context7.com/alexiosg/rmgarch/llms.txt Applies existing VAR coefficients to new data to filter conditional means and residuals. ```r new_data <- returns[1:500, ] var_filt <- varxfilter( X = new_data, p = 2, Bcoef = var_fit$Bcoef, postpad = "constant" ) ``` -------------------------------- ### DCC Test for Dynamic Correlation Source: https://context7.com/alexiosg/rmgarch/llms.txt Performs the Engle-Sheppard test to detect dynamic conditional correlation against a null hypothesis of constant correlation. ```r library(rmgarch) data(dji30retw) returns <- dji30retw[, 1:5] # Test for dynamic correlation dcc_test <- DCCtest( Data = returns, garchOrder = c(1, 1), # First-stage GARCH order n.lags = 5, # Number of lags to test solver = "solnp" ) # Results print(dcc_test) # $H0: "No dynamic conditional correlation" # $TestStatistic: Chi-square test statistic # $pvalue: p-value for the test # Low p-value indicates evidence of dynamic correlation if (dcc_test$pvalue < 0.05) { print("Evidence of dynamic correlation - use DCC model") } else { print("No evidence of dynamic correlation - CCC may suffice") } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.