contagion: Contagion Simulations

Description Usage Arguments Value References Examples

View source: R/contagion.R

Description

Given a matrix of exposures, a vector of buffers and weights (optional) the functions simulates contagion for all the shock vectors provided. You may choose from the implemented propagation contagion method or create you own propagation method. Details on how to create your own method will be provided in a future version.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
contagion(exposures, 
          buffer, 
          shock = "all", 
          weights = NULL, 
          method = c("debtrank", "threshold"), 
          ...,
          exposure_type = c("assets", "liabilities", "impact", "vulnerability"),
          keep.history = FALSE, 
          abs.tol = .Machine$double.eps ^ 0.2, 
          max.it = min(1000, nrow(v)*10),
          verbose = TRUE)

Arguments

exposures

an adjacency matrix, (sparse) Matrix or an igraph object with the network of bilateral exposures between vertices. By default, the function expects the exposures in the form of an assets matrix in which A -> B means that A has an asset with B. However, you can change that with the parameter exposure_type. When using a matrix, preferably it should have rows and columns names.

buffer

a numeric vector with the capital buffer for each vertex. Values should be in the same row/column order as the network of bilateral exposures. The buffer is not needed if exposure_type = "vulnerability".

shock

a list with the shock vectors. If "all" (the default) the function will run a simulation for the default of each vertex in the network.

weights

default is NULL. You can use a numeric vector of weights to give some economic significance to the measures, like, for instance, the total assets of the nodes.

method

the contagion propagation method. Currently, you should use either "debtrank" for the DebtRank propagation method or "threshold" for the traditional default cascades. The DebtRank version implemented is the one proposed in Bardoscia et al (2015). If you want to use the old "single-hit" DebtRank of Battiston et al (2012), simply provide the argument single.hit = TRUE.

...

other arguments to be passed to the contagion propagation method.

exposure_type

character vector indicating the type of the bilateral exposures. It can be an "assets" network (where A -> B means that A has an asset with B), a "liabilities" network (where A -> B means that A has a debt with B), a (binary) "impact" matrix (where A -> B indicates the relative impact of A in B's capital buffer), or a (binary) "vulnerability" matrix (where A -> B indicates the relative impact A suffers from B's default). The default is "assets".

keep.history

keep all the history of stress levels? This can use a lot of memory, so the default is FALSE.

abs.tol

the desired accuracy.

max.it

the maximum number of iterations.

verbose

gives verbose output. Default is TRUE.

Value

The function returns an object of class "contagion" with the results of the simulation.

References

Bardoscia M, Battiston S, Caccioli F, Caldarelli G (2015) DebtRank: A Microscopic Foundation for Shock Propagation. PLoS ONE 10(6): e0130406. doi: 10.1371/journal.pone.0130406

Battiston, S., Puliga, M., Kaushik, R., Tasca, P., and Caldarelli, G. (2012). DebtRank: Too central to fail? Financial networks, the FED and systemic risk. Scientific reports, 2:541.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# Loads simulated banking data
data("sim_data")
head(sim_data)

# seed for reproducibility
set.seed(15)

# minimum density estimation
# verbose = F to prevent printing
md_mat <- matrix_estimation(sim_data$assets, sim_data$liabilities, method = "md", verbose = FALSE)

# rownames and colnames for the matrix
rownames(md_mat) <- colnames(md_mat) <- sim_data$bank

# DebtRank simulation
contdr <- contagion(exposures = md_mat, buffer = sim_data$buffer, weights = sim_data$weights, 
                    shock = "all", method = "debtrank", verbose = FALSE)
summary(contdr)

plot(contdr)

# Traditional default cascades simulation
contthr <-  contagion(exposures = md_mat, buffer = sim_data$buffer, weights = sim_data$weights, 
                      shock = "all", method = "threshold", verbose = FALSE)
summary(contthr)

# simulating shock scenarios 1% to 25% shock in all vertices
s <- seq(0.01, 0.25, by = 0.01)
shocks <- lapply(s, function(x) rep(x, nrow(md_mat)))
names(shocks) <- paste(s*100, "pct shock")

cont <- contagion(exposures = md_mat, buffer = sim_data$buffer, shock = shocks, 
                 weights = sim_data$weights, method = "debtrank", verbose = FALSE)
summary(cont)
plot(cont)

carloscinelli/NetworkRiskMeasures documentation built on March 7, 2020, 4:39 p.m.