### Load and Inspect stock.prices Dataset Source: https://context7.com/cran/spillover/llms.txt Loads the daily stock prices dataset for six global indices. Displays the first and last few observations. ```r data(stock.prices) head(stock.prices) tail(stock.prices) ``` -------------------------------- ### Load and Inspect dy2012 Dataset Source: https://context7.com/cran/spillover/llms.txt Loads the Diebold and Yilmaz (2012) benchmark dataset and displays the first few rows and summary statistics. Requires the Spillover and vars packages. ```r library(Spillover) library(vars) data(dy2012) head(dy2012) summary(dy2012) ``` -------------------------------- ### Load and Inspect Rolling Returns and Volatilities Source: https://context7.com/cran/spillover/llms.txt Loads datasets for rolling average returns and Garman-Klass volatilities for six stock indices. Displays the first few observations for each. ```r data(rol.returns) data(rol.vol) head(rol.returns) head(rol.vol) ``` -------------------------------- ### Load and Inspect dy2009 Dataset Source: https://context7.com/cran/spillover/llms.txt Loads the Diebold and Yilmaz (2009) benchmark dataset and displays the first few rows and summary statistics. ```r data(dy2009) head(dy2009) summary(dy2009) ``` -------------------------------- ### Estimate Rolling Net Directional Spillover (Legacy) Source: https://context7.com/cran/spillover/llms.txt Estimates rolling net directional spillover using either generalized or orthogonalized methods. Newer code should use `dynamic.spillover()` instead. Requires `Spillover`, `vars`, and `zoo` libraries. ```r library(Spillover) library(vars) library(zoo) data(dy2012) # Generalized rolling net spillover G_net <- roll.net(as.zoo(dy2012[, -1]), width = 200, index = "generalized", p = 2) # Orthogonalized rolling net (partial averaging over orderings) O_net <- roll.net(as.zoo(dy2012[, -1]), width = 200, index = "orthogonalized", ortho.type = "partial", p = 2) plot(G_net, main = "Rolling Net Spillovers (Generalized)") ``` -------------------------------- ### Plot Net Pairwise Volatility Source: https://github.com/cran/spillover/blob/master/inst/doc/Spillover.html Generates a plot of net pairwise volatility from dy_results. Ensure dy_results is pre-calculated. ```R pp_netpairwise <- plotdy(dy_results, direction = "net_pairwise") ``` -------------------------------- ### Compute Static Spillover Table (Table 2) Source: https://github.com/cran/spillover/blob/master/inst/doc/Spillover.html Calculates the spillover table (Table 2) using a VAR(4) model and 10-day-ahead variance decomposition. Requires the dplyr package for data manipulation. ```r require(dplyr) dy2012 %>% dplyr::select(-Date) %>% VAR(p=4) %>% G.spillover(standardized = FALSE) %>% round(2) ``` -------------------------------- ### Load Spillover Package and DY2012 Data Source: https://github.com/cran/spillover/blob/master/inst/doc/Spillover.html Loads the Spillover package and the dy2012 dataset. Ensures the correct data is loaded by retrieving Table 1 from the paper. ```r options(repos = list(CRAN="http://cran.rstudio.com/")) library(Spillover, quietly = TRUE) data(dy2012) ``` -------------------------------- ### Apply Pandoc Div Source Code Styles to Pre Source Code Source: https://github.com/cran/spillover/blob/master/inst/doc/Spillover.html This JavaScript snippet modifies CSS rules to apply styles from 'div.sourceCode' to 'pre.sourceCode'. It ensures consistent styling for code blocks, especially when background colors or text colors are defined. ```javascript (function() { var sheets = document.styleSheets; for (var i = 0; i < sheets.length; i++) { if (sheets[i].ownerNode.dataset["origin"] !== "pandoc") continue; try { var rules = sheets[i].cssRules; } catch (e) { continue; } var j = 0; while (j < rules.length) { var rule = rules[j]; if (rule.type !== rule.STYLE_RULE || rule.selectorText !== "div.sourceCode") { j++; continue; } var style = rule.style.cssText; if (rule.style.color === '' && rule.style.backgroundColor === '') { j++; continue; } sheets[i].deleteRule(j); sheets[i].insertRule('pre.sourceCode{' + style + '}', j); } } })(); ``` -------------------------------- ### Plot Pairwise FROM-TO Network Source: https://github.com/cran/spillover/blob/master/inst/doc/Spillover.html Generates a pairwise FROM-TO plot from dyadic results. This plot visualizes directed relationships between entities. ```R pp_from_to_pairwise <- plotdy(dy_results, direction = "from_to_pairwise") ``` -------------------------------- ### Calculate and Plot Dynamic Total Spillover Index Source: https://github.com/cran/spillover/blob/master/inst/doc/Spillover.html Computes the dynamic total spillover index using a rolling window of 200 days and a generalized index. The results are then plotted using ggplot2. ```r total_dynamic <- total.dynamic.spillover(as.zoo(dy2012[,-1]), width = 200, index="generalized", p=4) require(ggplot2) tibble(Date= dy2012$Date[-c(1:199)], index = total_dynamic) %>% mutate(Date=as.Date(as.character(Date))) %>% ggplot(aes(x=Date, y=index)) + geom_line()+ labs(caption = "Fig 2. Total volatility spillovers, four asset classes.")+ theme(plot.caption = element_text(hjust = 0)) ``` -------------------------------- ### Calculate Dynamic Spillover Source: https://github.com/cran/spillover/blob/master/inst/doc/Spillover.html Calculates directional spillovers using dynamic methods. Requires specifying the data, a width parameter, and the order 'p'. ```R dy_results <- dynamic.spillover(data=dy2012, width=200, p=4) ``` -------------------------------- ### roll.net() — Rolling Net Directional Spillover (Legacy) Source: https://context7.com/cran/spillover/llms.txt Estimates rolling net directional spillover for each variable. This is a legacy function, and newer code should use `dynamic.spillover()` instead. ```APIDOC ## roll.net() ### Description Estimates rolling net directional spillover (Contributions To Others minus Contributions From Others) for each variable, returning a multicolumn `zoo` object. Supports orthogonalized (`"partial"` or `"total"` averaging) and generalized variants. Newer code should use `dynamic.spillover()` instead. ### Parameters - `data` (zoo object): Input data, typically a multicolumn zoo object. - `width` (numeric): The rolling window width. - `index` (character): Type of index to compute. Options are `"generalized"` or `"orthogonalized"`. - `ortho.type` (character, optional): Type of orthogonalization for `"orthogonalized"` index. Options are `"partial"` or `"total"`. - `p` (numeric): The lag order for the VAR model used in the estimation. ### Request Example ```r library(Spillover) library(vars) library(zoo) data(dy2012) # Generalized rolling net spillover G_net <- roll.net(as.zoo(dy2012[, -1]), width = 200, index = "generalized", p = 2) # Orthogonalized rolling net (partial averaging over orderings) O_net <- roll.net(as.zoo(dy2012[, -1]), width = 200, index = "orthogonalized", ortho.type = "partial", p = 2) plot(G_net, main = "Rolling Net Spillovers (Generalized)") ``` ### Response - Returns a multicolumn `zoo` object containing the rolling net directional spillover estimates. ``` -------------------------------- ### O.spillover() — Orthogonalized Spillover Index Source: https://context7.com/cran/spillover/llms.txt Computes the orthogonalized directional spillover table based on Cholesky FEVD. It offers strategies for handling variable ordering dependencies: 'single' uses the current ordering, 'partial' averages over a random subset of orderings, and 'total' averages over all possible orderings for exact results. ```APIDOC ## O.spillover() ### Description Computes the orthogonalized directional spillover table based on Cholesky FEVD, as in Diebold and Yilmaz (2009). Because results depend on variable ordering, three averaging strategies are offered via `ortho.type`: `"single"` uses the current ordering; `"partial"` averages over a random subset of all K! orderings (faster); `"total"` averages over all K! orderings (exact but slow for large K). ### Parameters - `ortho.type` (string): Strategy for handling variable ordering. Options: `"single"`, `"partial"`, `"total"`. - `standardized` (boolean): Whether to standardize the spillover index. ### Request Example ```r library(Spillover) library(vars) data(dy2009) VAR.2 <- VAR(dy2009[, -1], p = 2) # Single ordering (replicates Table 3 from DY 2009) O.spillover(VAR.2, ortho.type = "single", standardized = FALSE) # Average over a random partial set of orderings (faster approximation) O.spillover(VAR.2, n.ahead = 10, ortho.type = "partial", standardized = TRUE) # Average over all K! orderings (exact, slower) O.spillover(VAR.2, n.ahead = 10, ortho.type = "total", standardized = TRUE) ``` ``` -------------------------------- ### total.dynamic.spillover() — Rolling Total Spillover Index Source: https://context7.com/cran/spillover/llms.txt Estimates the scalar total spillover index over a rolling window, returning a `zoo` time series. Supports both orthogonalized and generalized index variants. Useful for plotting a single aggregate connectedness line over time. ```APIDOC ## total.dynamic.spillover() ### Description Estimates the scalar total spillover index over a rolling window, returning a `zoo` time series. Supports both orthogonalized (`"single"`, `"partial"`, `"total"`) and generalized index variants. Useful for plotting a single aggregate connectedness line over time. ### Parameters - `data` (zoo): Input data as a zoo object. - `width` (integer): The size of the rolling window. - `index` (string): Type of index. Options: `"generalized"`, `"orthogonalized"` (default). - `ortho.type` (string): Orthogonalization strategy if `index` is `"orthogonalized"`. Options: `"single"`, `"partial"`, `"total"`. - `p` (integer): The VAR lag order. ### Request Example ```r library(Spillover) library(vars) library(zoo) library(ggplot2) library(dplyr) library(tibble) data(dy2012) # Generalized total dynamic spillover (replicates Fig 2 in DY 2012) total_dynamic <- total.dynamic.spillover( data = as.zoo(dy2012[, -1]), width = 200, index = "generalized", p = 4 ) # Plot as time series tibble( Date = dy2012$Date[-c(1:199)], index = as.numeric(total_dynamic) ) %>% mutate(Date = as.Date(as.character(Date))) %>% ggplot(aes(x = Date, y = index)) + geom_line() + labs( title = "Total Volatility Spillover Index", caption = "Fig 2. Total volatility spillovers, four asset classes.", x = "", y = "Spillover Index (%)" ) # Orthogonalized variant with single ordering O_total <- total.dynamic.spillover(as.zoo(dy2012[, -1]), width = 200, p = 4) # Compare single, partial and total orthogonalization strategies single <- total.dynamic.spillover(as.zoo(dy2012[1:1200, 2:4]), width = 200, p = 4) partial <- total.dynamic.spillover(as.zoo(dy2012[1:1200, 2:4]), width = 200, p = 4, ortho.type = "partial") total_o <- total.dynamic.spillover(as.zoo(dy2012[1:1200, 2:4]), width = 200, p = 4, ortho.type = "total") plot(cbind(single, partial, total_o), col = 1:3, main = "Spillover index comparison") ``` ``` -------------------------------- ### Estimate Dynamic Directional Spillover Source: https://context7.com/cran/spillover/llms.txt Estimates full directional spillover dynamics over time using a rolling window. This is the recommended function for time-varying connectedness analysis. ```r library(Spillover) library(vars) data(dy2012) # Estimate directional spillovers with a 200-observation rolling window dy_results <- dynamic.spillover( data = dy2012, # data.frame: first column = dates, rest = variables width = 200, # rolling window size n.ahead = 10, # forecast horizon standardized = TRUE, remove.own = TRUE, # exclude own-variable spillovers from directional sums p = 4 # VAR lag order (passed to VAR()) ) class(dy_results) #> [1] "directional.spillover" names(dy_results) #> [1] "from" "to" "net" #> [4] "net_pairwise" "from_to_pairwise" head(dy_results$from) # Directional FROM each variable over time head(dy_results$net) # Net spillover (from - to) over time head(dy_results$net_pairwise) # Net pairwise spillovers between variable pairs ``` -------------------------------- ### Plot Net Volatility Spillovers Source: https://github.com/cran/spillover/blob/master/inst/doc/Spillover.html Generates a plot of net volatility spillovers. Requires pre-computed `dy_results`. ```R pp_net <- plotdy(dy_results, direction = "net") ``` -------------------------------- ### g.fevd() — Generalized Forecast Error Variance Decomposition Source: https://context7.com/cran/spillover/llms.txt Computes the generalized FEVD proposed by Pesaran and Shin (1998) for a fitted VAR model. This decomposition is invariant to variable ordering. Returns a list of length K (number of variables), each element being a matrix of cumulative FEVD contributions at each horizon up to n.ahead. ```APIDOC ## g.fevd() ### Description Computes the generalized FEVD proposed by Pesaran and Shin (1998) for a fitted VAR model. Unlike the Cholesky-based FEVD, this decomposition is invariant to variable ordering. Returns a list of length K (number of variables), each element being a matrix of cumulative FEVD contributions at each horizon up to `n.ahead`. The result is an object of class `varfevd`. ### Parameters - `VAR.fit`: A fitted `varest` object from the `vars` package. - `n.ahead`: The forecast horizon. - `normalized`: Logical, if TRUE (default), FEVD contributions are normalized to sum to 1. If FALSE, raw Pesaran-Shin values are returned. ### Request Example ```r library(Spillover) library(vars) data(stock.prices) stocks <- stock.prices[, 1:3] # Use first 3 indices VAR.fit <- VAR(stocks, p = 2) # Normalized generalized FEVD (each row sums to 1) gfevd_norm <- g.fevd(VAR.fit, n.ahead = 10) gfevd_norm[["SP500"]] # Un-normalized (raw Pesaran-Shin values) gfevd_raw <- g.fevd(VAR.fit, n.ahead = 10, normalized = FALSE) gfevd_raw[["FTSE"]] ``` ### Response - Returns a list of length K (number of variables), where each element is a matrix of cumulative FEVD contributions at each horizon up to `n.ahead`. ``` -------------------------------- ### dynamic.spillover() — Rolling-Window Directional Spillover Source: https://context7.com/cran/spillover/llms.txt Estimates full directional spillover dynamics over time using a rolling window, returning an object of class `directional.spillover`. This is the primary function for time-varying connectedness analysis. ```APIDOC ## dynamic.spillover() ### Description Estimates full directional spillover dynamics over time using a rolling window, returning an object of class `directional.spillover`. The output list contains five data frames — `from`, `to`, `net`, `net_pairwise`, and `from_to_pairwise` — each with a `Date` column plus one column per variable or variable pair. This is the primary function for time-varying connectedness analysis and should be preferred over the older `roll.spillover()` / `roll.net()` functions. ### Parameters - `data` (data.frame): Input data where the first column is dates and the rest are variables. - `width` (integer): The size of the rolling window. - `n.ahead` (integer): The forecast horizon. - `standardized` (boolean): Whether to standardize the spillover index. - `remove.own` (boolean): Whether to exclude own-variable spillovers from directional sums. - `p` (integer): The VAR lag order (passed to VAR()). ### Response - Returns an object of class `directional.spillover` containing `from`, `to`, `net`, `net_pairwise`, and `from_to_pairwise` data frames. ### Request Example ```r library(Spillover) library(vars) data(dy2012) # Estimate directional spillovers with a 200-observation rolling window dy_results <- dynamic.spillover( data = dy2012, # data.frame: first column = dates, rest = variables width = 200, # rolling window size n.ahead = 10, # forecast horizon standardized = TRUE, remove.own = TRUE, # exclude own-variable spillovers from directional sums p = 4 # VAR lag order (passed to VAR()) ) class(dy_results) #> [1] "directional.spillover" names(dy_results) #> [1] "from" "to" "net" #> [4] "net_pairwise" "from_to_pairwise" head(dy_results$from) # Directional FROM each variable over time head(dy_results$net) # Net spillover (from - to) over time head(dy_results$net_pairwise) # Net pairwise spillovers between variable pairs ``` ``` -------------------------------- ### Compute Generalized Spillover Table Source: https://context7.com/cran/spillover/llms.txt Computes the full generalized directional spillover table using a fitted VAR model. The table entries represent contributions to forecast error variance. Requires Spillover, vars, and dplyr packages. The 'standardized' argument controls whether results are presented as percentages. ```r library(Spillover) library(vars) library(dplyr) data(dy2012) # Replicate Table 2 from Diebold and Yilmaz (2012) VAR_4 <- dy2012 %>% dplyr::select(-Date) %>% VAR(p = 4) spillover_table <- G.spillover(VAR_4, n.ahead = 10, standardized = FALSE) round(spillover_table, 2) # Standardized (percentage) form G.spillover(VAR_4, n.ahead = 10, standardized = TRUE) ``` -------------------------------- ### Legacy Rolling Total Spillover Index Source: https://context7.com/cran/spillover/llms.txt An older rolling-window total spillover estimator that returns a zoo object. Newer code should prefer `dynamic.spillover()`. ```r library(Spillover) library(vars) library(zoo) data(dy2012) # Orthogonalized rolling index, VAR(4), single Cholesky ordering O_index <- roll.spillover(as.zoo(dy2012[, -1]), width = 200, p = 4) # Generalized rolling index G_index <- roll.spillover(as.zoo(dy2012[, -1]), width = 200, index = "generalized", p = 4) plot(cbind(O_index, G_index), col = 1:2, main = "Rolling Spillover Index: Orthogonalized vs Generalized") ``` -------------------------------- ### Compute Generalized FEVD Source: https://context7.com/cran/spillover/llms.txt Computes the generalized Forecast Error Variance Decomposition (FEVD) for a fitted VAR model. The decomposition is invariant to variable ordering. Requires Spillover and vars packages. The 'normalized' argument controls whether results are scaled to sum to 1. ```r library(Spillover) library(vars) data(stock.prices) stocks <- stock.prices[, 1:3] # Use first 3 indices VAR.fit <- VAR(stocks, p = 2) # Normalized generalized FEVD (each row sums to 1) gfevd_norm <- g.fevd(VAR.fit, n.ahead = 10) gfevd_norm(("SP500")) # FEVD matrix for SP500 # Un-normalized (raw Pesaran-Shin values) gfevd_raw <- g.fevd(VAR.fit, n.ahead = 10, normalized = FALSE) gfevd_raw(("FTSE")) ``` -------------------------------- ### Plot Net Volatility Spillovers Source: https://github.com/cran/spillover/blob/master/inst/doc/Spillover.html Applies plot labels and theme adjustments to a net volatility spillover plot. Use this to customize the final visualization of spillover effects. ```R pp_net + labs(caption = "Fig. 5. Net volatility spillovers, four asset classes.")+ theme(plot.caption = element_text(hjust = 0.5)) ``` -------------------------------- ### roll.spillover() — Rolling Total Spillover Index (Legacy) Source: https://context7.com/cran/spillover/llms.txt An older rolling-window total spillover estimator that returns a `zoo` object. Functionally similar to `total.dynamic.spillover()`; newer code should prefer `dynamic.spillover()`. Accepts both orthogonalized and generalized variants via the `index` argument. ```APIDOC ## roll.spillover() ### Description An older rolling-window total spillover estimator that returns a `zoo` object. Functionally similar to `total.dynamic.spillover()`; newer code should prefer `dynamic.spillover()`. Accepts both orthogonalized and generalized variants via the `index` argument. ### Parameters - `data` (zoo): Input data as a zoo object. - `width` (integer): The size of the rolling window. - `index` (string): Type of index. Options: `"generalized"`, `"orthogonalized"` (default). - `p` (integer): The VAR lag order. ### Request Example ```r library(Spillover) library(vars) library(zoo) data(dy2012) # Orthogonalized rolling index, VAR(4), single Cholesky ordering O_index <- roll.spillover(as.zoo(dy2012[, -1]), width = 200, p = 4) # Generalized rolling index G_index <- roll.spillover(as.zoo(dy2012[, -1]), width = 200, index = "generalized", p = 4) plot(cbind(O_index, G_index), col = 1:2, main = "Rolling Spillover Index: Orthogonalized vs Generalized") ``` ``` -------------------------------- ### G.spillover() — Generalized Spillover Index Source: https://context7.com/cran/spillover/llms.txt Computes the full generalized directional spillover table as in Diebold and Yilmaz (2012). The table's `ij`-th entry is the estimated contribution *to* variable `i`'s forecast error variance from innovations in variable `j`. Row totals give 'Contributions from Others'; column totals give 'Contributions to Others'. The bottom-right scalar is the total spillover index. ```APIDOC ## G.spillover() ### Description Computes the full generalized directional spillover table as in Diebold and Yilmaz (2012). The table's `ij`-th entry is the estimated contribution *to* variable `i`'s forecast error variance from innovations in variable `j`. Row totals give "Contributions from Others"; column totals give "Contributions to Others". The bottom-right scalar is the total spillover index. ### Parameters - `VAR.fit`: A fitted `varest` object from the `vars` package. - `n.ahead`: The forecast horizon. - `standardized`: Logical, if TRUE (default), values are divided by K to produce percentages. If FALSE, raw values are returned. ### Request Example ```r library(Spillover) library(vars) library(dplyr) data(dy2012) # Replicate Table 2 from Diebold and Yilmaz (2012) VAR_4 <- dy2012 %>% dplyr::select(-Date) %>% VAR(p = 4) spillover_table <- G.spillover(VAR_4, n.ahead = 10, standardized = FALSE) round(spillover_table, 2) # Standardized (percentage) form G.spillover(VAR_4, n.ahead = 10, standardized = TRUE) ``` ### Response - Returns a matrix representing the generalized directional spillover table. The bottom-right scalar is the total spillover index. ``` -------------------------------- ### Estimate Rolling Total Spillover Index Source: https://context7.com/cran/spillover/llms.txt Estimates the scalar total spillover index over a rolling window. Supports generalized and orthogonalized variants. Useful for plotting a single aggregate connectedness line over time. ```r library(Spillover) library(vars) library(zoo) library(ggplot2) library(dplyr) library(tibble) data(dy2012) # Generalized total dynamic spillover (replicates Fig 2 in DY 2012) total_dynamic <- total.dynamic.spillover( data = as.zoo(dy2012[, -1]), width = 200, index = "generalized", p = 4 ) # Plot as time series tibble( Date = dy2012$Date[-c(1:199)], index = as.numeric(total_dynamic) ) %>% mutate(Date = as.Date(as.character(Date))) %>% ggplot(aes(x = Date, y = index)) + geom_line() + labs( title = "Total Volatility Spillover Index", caption = "Fig 2. Total volatility spillovers, four asset classes.", x = "", y = "Spillover Index (%)" ) # Orthogonalized variant with single ordering O_total <- total.dynamic.spillover(as.zoo(dy2012[, -1]), width = 200, p = 4) # Compare single, partial and total orthogonalization strategies single <- total.dynamic.spillover(as.zoo(dy2012[1:1200, 2:4]), width = 200, p = 4) partial <- total.dynamic.spillover(as.zoo(dy2012[1:1200, 2:4]), width = 200, p = 4, ortho.type = "partial") total_o <- total.dynamic.spillover(as.zoo(dy2012[1:1200, 2:4]), width = 200, p = 4, ortho.type = "total") plot(cbind(single, partial, total_o), col = 1:3, main = "Spillover index comparison") ``` -------------------------------- ### plotdy() — Plot Directional Spillover Dynamics Source: https://context7.com/cran/spillover/llms.txt Produces ggplot2 area charts for any directional component of a `directional.spillover` object returned by `dynamic.spillover()`. The `direction` argument selects which component to plot. ```APIDOC ## plotdy() ### Description Produces ggplot2 area charts for any directional component of a `directional.spillover` object returned by `dynamic.spillover()`. The `direction` argument selects which component to plot: `"from"`, `"to"`, `"net"`, `"net_pairwise"`, or `"from_to_pairwise"`. Returns a `ggplot` object that can be further customized with standard ggplot2 layers. ### Parameters - `dy_results` (directional.spillover object): The output from `dynamic.spillover()`. - `direction` (character): The component of the spillover to plot. Options include `"from"`, `"to"`, `"net"`, `"net_pairwise"`, or `"from_to_pairwise"`. ### Request Example ```r library(Spillover) library(vars) library(ggplot2) data(dy2012) dy_results <- dynamic.spillover(data = dy2012, width = 200, p = 4) # Fig 3: Directional FROM each asset class pp_from <- plotdy(dy_results, direction = "from") pp_from + labs(caption = "Fig 3. Directional volatility spillovers, FROM four asset classes.") + theme(plot.caption = element_text(hjust = 0.5)) # Fig 4: Directional TO each asset class pp_to <- plotdy(dy_results, direction = "to") # Fig 5: Net directional spillovers pp_net <- plotdy(dy_results, direction = "net") pp_net + facet_wrap(~variables, scales = "fixed") # force shared y-axis # Fig 6: Net pairwise spillovers between variable pairs pp_netpairwise <- plotdy(dy_results, direction = "net_pairwise") # From/To pairwise spillovers pp_from_to <- plotdy(dy_results, direction = "from_to_pairwise") ``` ### Response - Returns a `ggplot` object that can be further customized. ``` -------------------------------- ### Plot Directional Spillover Dynamics Source: https://context7.com/cran/spillover/llms.txt Generates ggplot2 area charts for directional spillover components (from, to, net, net_pairwise, from_to_pairwise). Returns a ggplot object for further customization. Requires `Spillover`, `vars`, and `ggplot2` libraries. ```r library(Spillover) library(vars) library(ggplot2) data(dy2012) dy_results <- dynamic.spillover(data = dy2012, width = 200, p = 4) # Fig 3: Directional FROM each asset class pp_from <- plotdy(dy_results, direction = "from") pp_from + labs(caption = "Fig 3. Directional volatility spillovers, FROM four asset classes.") + theme(plot.caption = element_text(hjust = 0.5)) # Fig 4: Directional TO each asset class pp_to <- plotdy(dy_results, direction = "to") # Fig 5: Net directional spillovers pp_net <- plotdy(dy_results, direction = "net") pp_net + facet_wrap(~variables, scales = "fixed") # force shared y-axis # Fig 6: Net pairwise spillovers between variable pairs pp_netpairwise <- plotdy(dy_results, direction = "net_pairwise") # From/To pairwise spillovers pp_from_to <- plotdy(dy_results, direction = "from_to_pairwise") ``` -------------------------------- ### Plot Directional Spillovers (TO) Source: https://github.com/cran/spillover/blob/master/inst/doc/Spillover.html Use this function to plot directional spillovers TO specified asset classes. Ensure 'dy_results' contains the necessary spillover analysis results. ```R pp_to <- plotdy(dy_results, direction = "to") ``` -------------------------------- ### Plot Directional Spillovers (From) Source: https://github.com/cran/spillover/blob/master/inst/doc/Spillover.html Generates a plot of directional volatility spillovers originating from specified data. This function is used to create visualizations similar to Figure 3 in Diebold and Yilmaz (2012). ```R pp_from <- plotdy(data=dy_results, direction = "from") ``` -------------------------------- ### Compute Orthogonalized Spillover Index Source: https://context7.com/cran/spillover/llms.txt Computes the orthogonalized directional spillover table. Results depend on variable ordering, with options for single ordering, partial averaging, or total averaging over all permutations. ```r library(Spillover) library(vars) data(dy2009) VAR.2 <- VAR(dy2009[, -1], p = 2) # Single ordering (replicates Table 3 from DY 2009) O.spillover(VAR.2, ortho.type = "single", standardized = FALSE) # Average over a random partial set of orderings (faster approximation) O.spillover(VAR.2, n.ahead = 10, ortho.type = "partial", standardized = TRUE) # Average over all K! orderings (exact, slower) O.spillover(VAR.2, n.ahead = 10, ortho.type = "total", standardized = TRUE) ``` -------------------------------- ### Remove Pandoc Header Attributes Source: https://github.com/cran/spillover/blob/master/inst/doc/Spillover.html This JavaScript code removes Pandoc-added attributes from headers to ensure compatibility with older Pandoc versions. It targets specific header elements within the document. ```javascript document.addEventListener('DOMContentLoaded', function(e) { var hs = document.querySelectorAll("div.section\[class*='level'\] > :first-child"); var i, h, a; for (i = 0; i < hs.length; i++) { h = hs[i]; if (!/^h[1-6]$/i.test(h.tagName)) continue; h = hs[i]; if (!/^h[1-6]$/i.test(h.tagName)) continue; a = h.attributes; while (a.length > 0) h.removeAttribute(a[0].name); } }); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.