R/G.spillover.R

#'  Generalized spillover index
#' 
#' @description 
#' Computes the generalized spillover index proposed in Diebold and Yilmaz (2012) 
#' which is based on the General Forecast Variance Decompositon introduced by Pesaran and Shin (1998).
#' 
#' @param x Object of class \sQuote{\code{varest}} generated by \code{VAR()} from vars package.
#' @param n.ahead Integer specifying the steps ahead.
#' @param standardized A logical value indicating whether the values should be divided by the number of columns
#' to get a percentage. 
#' 
#' @details
#' This function computes the Generalized Directional Spillover Table which has as its
#' \eqn{ij^{th}}{ij^th} entry the estimated contribution \emph{to} the forecast error variance 
#' of variable \emph{i} coming \emph{from} innovations to variable \emph{j}. The off-diagonal
#' column sums are the \emph{Contributions to Others}, while the row sums represent 
#' \emph{Contributions from Others}, when these are totaled across  countries then we have
#' the numerator of the Spillover Index. Similarly, the columns sums or rows sums 
#' (including diagonal), when totaled across countries, give the denominator of the 
#' Spillover Index, which is 100\%.
#'    
#' \code{G.spillover} is based upon the General Forecast Error Variance Decompositon introduced by 
#' Pesaran and Shin (1998) and its explicit formulation can be found in Diebold and Yilmaz (2010).
#' 
#' @return A \code{data.frame} consisting of the spillover index.
#' @references
#' Diebold, F. X. & Yilmaz, K.(2012). \emph{Better to Give than to Receive: Predictive Directional Measurement of Volatility Spillovers}. International Journal of Forecasting.
#' 
#' Pesaran, M. H. and Shin, Y. (1998). \emph{Generalized impulse response analysis in linear multivariate models}. Economics Letters, 58(1):17-29.
#' @author Jilber Urbina
#' @seealso \code{\link{O.spillover}}
#' @export
#' 
#' @examples
#' # Replicating Diebold and Yilmaz (2012)
#' data(dy2012)
#' VAR_4 <- VAR(dy2012[,-1], p=4) 
#' G.spillover(VAR_4, standardized = FALSE)
#' @keywords models regression
#' 


G.spillover <- function (x, n.ahead = 10, standardized=TRUE) 
{
  
  if (!inherits(x, "varest")) {
    stop("\nPlease provide an object of class 'varest', generated by 'VAR()'.\n")
  }
  var.est <- x
  n.ahead <- abs(as.integer(n.ahead))
  EVD <- g.fevd(var.est, n.ahead = n.ahead)
  K <- var.est$K
  table <- do.call(rbind, lapply(EVD, "[", n.ahead, )) *100
  CFO <- rowSums(table - diag(diag(table)))
  CTO <- colSums(table) - diag(table)
  CTOT <- colSums(table)
  table <- rbind(table, `C. to others (spillover)` = CTO, `C. to others including own` = CTOT)
  
  index <- function(x) {(sum(x)-sum(diag(x)))/nrow(x)}
  
  if(standardized){
    table <- cbind(table, `C. from others` =  c(CFO, sum(CFO), sum(CTOT) )) / K
  } else{
    table <- cbind(table, `C. from others` = c(CFO, index(table[1:K, ]), sum(CTOT)))
  }
  
  return(table)
}

Try the Spillover package in your browser

Any scripts or data that you put into this service are public.

Spillover documentation built on June 22, 2024, 12:25 p.m.