Package {contagionchannels}


Type: Package
Title: Two-Stage Detection and Attribution of Cross-Border Financial Contagion Channels
Version: 0.1.3
Date: 2026-04-30
Description: Implementation of a two-stage framework for the joint detection-and-attribution of cross-border financial contagion. Stage one detects directional information flows between equity markets via Wavelet-Quantile Transfer Entropy, combining maximal-overlap discrete wavelet decomposition (Percival and Walden, 2000, ISBN:9780521685085) with the transfer-entropy estimator of Schreiber (2000) <doi:10.1103/PhysRevLett.85.461> and quantile conditioning following Han, Linton, Oka and Whang (2016) <doi:10.1016/j.jeconom.2016.03.001>. Stage two attributes each significant directional link to one of five mutually exclusive transmission channels (Trade, Financial, Geopolitical, Behavioural, Monetary Policy) through a multi-method structural identification architecture combining instrumental-variables two-stage least squares with channel-specific external instruments (Stock and Watson, 2018) <doi:10.1111/ecoj.12593>, LASSO-based instrument selection (Belloni, Chernozhukov and Hansen, 2014) <doi:10.1093/restud/rdt044>, local projections (Jorda, 2005) <doi:10.1257/0002828053828518>, heteroskedasticity-based identification (Rigobon, 2003) <doi:10.1162/003465303772815727>, and the Cinelli-Hazlett (2020) <doi:10.1111/rssb.12348> robustness-value sensitivity bound. Bundled datasets and replication scripts reproduce the headline findings of Bhandari, Parida and Sahu (2026) <doi:10.48550/arXiv.2604.26546>; the package is general-purpose and accommodates user-supplied returns and channel proxies.
License: GPL-3
Encoding: UTF-8
LazyData: true
Depends: R (≥ 4.1.0)
Imports: xts, zoo, waveslim, quantreg, igraph, parallel, MASS, stats, utils
Suggests: hdm, glmnet, ggplot2, dplyr, tidyr, patchwork, RColorBrewer, viridis, scales, readxl, knitr, rmarkdown, testthat (≥ 3.0.0)
VignetteBuilder: knitr
RoxygenNote: 7.3.3
URL: https://github.com/avishekb9/contagionchannels
BugReports: https://github.com/avishekb9/contagionchannels/issues
Config/testthat/edition: 3
NeedsCompilation: no
Packaged: 2026-05-05 14:13:57 UTC; ecolex
Author: Avishek Bhandari [aut, cre] (Indian Institute of Technology Bhubaneswar), Ipsita Parida [aut] (Indian Institute of Technology Bhubaneswar), Hitesh Kumar Sahu [aut] (Indian Institute of Technology Bhubaneswar)
Maintainer: Avishek Bhandari <avishekb@iitbbs.ac.in>
Repository: CRAN
Date/Publication: 2026-05-08 15:10:09 UTC

contagionchannels: Detection and Attribution of Cross-Border Financial Contagion Channels

Description

The package implements a two-stage framework for the joint detection- and-attribution of cross-border financial contagion. Stage one detects directional information flows between equity markets via Wavelet-Quantile Transfer Entropy. Stage two attributes each significant directional link to one of five mutually exclusive transmission channels through a multi-method structural identification architecture.

Main functions

Bundled data

g20_returns, channel_proxies, crisis_periods.

Vignettes

Author(s)

Maintainer: Avishek Bhandari avishekb@iitbbs.ac.in (Indian Institute of Technology Bhubaneswar)

Authors:

See Also

Useful links:


Construct the Five-Channel Composites

Description

Builds the five contagion-channel composites (Trade, Financial, Geopolitical, Behavioural, Monetary Policy) from a data.frame of raw channel proxies. The construction is engineered for orthogonal identification: the trade composite uses log-returns of a broad trade-weighted dollar index (genuinely time-varying), the behavioural composite is orthogonalised against the financial composite to avoid VIX-derivative contamination, and the monetary composite uses a first-differenced policy rate to remove persistence-induced first-stage F-inflation.

Usage

build_channel_composites(proxy_grid)

Arguments

proxy_grid

A data.frame with the following columns aligned on the same daily date grid: vix, hy_spread, stress_index, usd_index, gpr, geo_events, sentiment, fed_rate, term_spread, qe_dummy.

Value

A data.frame with columns Date, Trade, Financial, Geopolitical, Behavioral, and Monetary_Policy; each composite is z-scored within sample.

References

Stock, J. H., & Watson, M. W. (2018). Identification and Estimation of Dynamic Causal Effects in Macroeconomics Using External Instruments. Economic Journal, 128(610), 917-948. doi: 10.1111/ecoj.12593.

Romer, C. D., & Romer, D. H. (2004). A New Measure of Monetary Shocks. American Economic Review, 94(4), 1055-1084. doi: 10.1257/0002828042002651.

Examples


d <- load_paper_data()
ch <- build_channel_composites(d$proxies)
head(ch); cor(ch[, -1])


Build a Lagged Vector with Leading NAs

Description

Returns a vector x_{t-\ell} where the first \ell positions are NA and the remaining positions are the lagged values of x. Used throughout the package for instrument and predictor construction.

Usage

build_lag(x, lg)

Arguments

x

Numeric vector.

lg

Positive integer lag.

Value

Numeric vector of the same length as x.

Examples

build_lag(1:10, 3)

Construct a Directed Contagion Network from a WQTE Flow Matrix

Description

Builds a directed weighted network from a pairwise WQTE flow matrix by retaining only the edges whose intensity exceeds the supplied threshold. The network construction follows the standard contagion-network literature (Diebold and Yilmaz, 2014; Billio et al., 2012).

Usage

build_network(F_matrix, threshold)

Arguments

F_matrix

An N \times N numeric matrix of WQTE values.

threshold

Numeric threshold for edge retention; edges with F_matrix[i,j] > threshold are retained.

Value

An igraph object with weight edge attribute equal to the WQTE value.

Examples

m <- matrix(runif(25, 0, 0.1), 5, 5); diag(m) <- 0
g <- build_network(m, threshold = 0.05)
igraph::ecount(g)

Channel-Proxy Daily Series

Description

Daily-frequency channel-proxy series aligned on the G20 trading-day grid, used as inputs to build_channel_composites. Values are forward-filled where lower-frequency data are available.

Usage

channel_proxies

Format

A data.frame with 5,036 rows and 14 columns:

Date

Trading date

vix

CBOE Volatility Index level

hy_spread

ICE BofA US High-Yield Option-Adjusted Spread

stress_index

St. Louis Fed Financial Stress Index (STLFSI4)

usd_index

Federal Reserve Broad Trade-Weighted Dollar Index (DTWEXBGS)

gpr

Caldara-Iacoviello Geopolitical Risk Index

geo_events

Geopolitical-events indicator

vix_slope

VIX-VIX3M term-structure slope

fear_proxy

Daily absolute change in VIX

sentiment

University of Michigan Consumer Sentiment Index

fed_rate

Effective Federal Funds Rate

dgs10

10-year Treasury yield

term_spread

10-year minus 3-month Treasury yield spread

qe_dummy

Quantitative-easing program indicator (binary)

Source

Federal Reserve Economic Data (FRED), Yahoo Finance, Caldara-Iacoviello GPR data library.

Examples

data(channel_proxies)
summary(channel_proxies[, c("vix","gpr","fed_rate")])

Cinelli-Hazlett Robustness Value

Description

Computes the partial-R^2 that an unobserved confounder would need to share with both the treatment and the outcome to drive the structural coefficient to zero. The robustness value is bounded in [0, 1]; values near zero indicate that even a weakly correlated confounder could explain away the result, while values near one indicate identification-robust findings.

Usage

cinelli_hazlett_rv(theta, se, df)

Arguments

theta

Estimated structural coefficient.

se

Standard error of theta.

df

Residual degrees of freedom.

Value

A scalar in [0,1], or NA if inputs are invalid.

References

Cinelli, C., & Hazlett, C. (2020). Making Sense of Sensitivity: Extending Omitted Variable Bias. Journal of the Royal Statistical Society Series B, 82(1), 39-67. doi: 10.1111/rssb.12348.

Examples

cinelli_hazlett_rv(theta = 0.4, se = 0.1, df = 200)

Wavelet-Quantile Transfer Entropy Matrix

Description

Computes the bilateral WQTE matrix for a returns panel at one wavelet scale and one quantile, producing the directed flow matrix that serves as the Stage-1 input to the structural-attribution layer.

Usage

compute_wqte_matrix(returns, scale = 5, tau = 0.5, n_cores = 2L)

Arguments

returns

An xts or matrix of returns (rows = time, cols = markets).

scale

Integer wavelet scale. Default 5.

tau

Quantile level. Default 0.50.

n_cores

Integer; number of parallel cores for mclapply. Default 2L per CRAN policy; on Windows the function falls back to serial lapply. Increase for production-scale workloads.

Value

An N \times N matrix where entry (i,j) is the WQTE from market i to market j at the specified scale and quantile; row and column names are taken from colnames(returns).

References

Bhandari, A., & Parida, I. (2026). Wavelet-quantile transfer entropy for financial-market contagion.

Examples


d <- load_paper_data()
ix <- which(zoo::index(d$returns) >= as.Date("2008-01-01") &
            zoo::index(d$returns) <= as.Date("2008-12-31"))
F <- compute_wqte_matrix(d$returns[ix, ], scale = 5, tau = 0.50, n_cores = 2)


Crisis Sub-Period Definitions

Description

A named list of length-two character vectors specifying the start and end dates of the eight crisis sub-periods analysed in the paper.

Usage

crisis_periods

Format

A named list with eight elements:

PreCrisis

Pre-Crisis Baseline (12 Jan 2006 - 31 Jul 2007)

GFC

Global Financial Crisis (1 Aug 2007 - 30 Jun 2009)

ESDC

European Sovereign Debt Crisis (1 Dec 2009 - 30 Jun 2012)

CSC

Chinese Stock Crash (15 Jun 2015 - 31 Dec 2016)

PreCOVID

Pre-COVID interval (1 Jan 2017 - 31 Jan 2020)

COVID

COVID-19 Pandemic (1 Feb 2020 - 31 Dec 2021)

RusUkr

Russia-Ukraine episode (1 Feb 2022 - 31 Dec 2023)

MidEastTariffs

Middle-East tensions and tariffs (1 Jan 2024 - 18 Mar 2026)

Examples

data(crisis_periods)
crisis_periods$GFC

G20 Equity-Market Daily Log-Returns

Description

Daily log-return panel for 18 G20 equity-market indices spanning 12 January 2006 through 18 March 2026, used in the paper replication. The panel covers 5,036 trading days. Eight developed and ten emerging markets are represented.

Usage

g20_returns

Format

An xts object with 5,036 rows and 18 columns:

Argentina

S&P/MERVAL log-returns

Australia

S&P/ASX 200 log-returns

Brazil

IBOVESPA log-returns

Canada

S&P/TSX Composite log-returns

China

Shanghai Composite log-returns

France

CAC 40 log-returns

Germany

DAX 40 log-returns

India

BSE SENSEX log-returns

Indonesia

IDX Composite log-returns

Italy

FTSE MIB log-returns

Japan

Nikkei 225 log-returns

Mexico

S&P/BMV IPC log-returns

Russia

IMOEX log-returns

SouthAfrica

JSE All Share log-returns

SouthKorea

KOSPI log-returns

Turkey

BIST 100 log-returns

UK

FTSE 100 log-returns

USA

S&P 500 log-returns

Source

Yahoo Finance and Investing.com aggregator.

Examples

data(g20_returns)
dim(g20_returns); head(g20_returns[, 1:5])

Five-Channel IV/2SLS Channel Attribution for One Bilateral Link

Description

Estimates the structural equation

C_{ij,t} = \alpha + \sum_{c=1}^{5} \theta_c \, \mathrm{Channel}_{c,t} + \gamma_1 f_t + \gamma_2 C_{ij,t-1} + \varepsilon_{ij,t}

via two-stage least squares, treating the five channel composites as endogenous and instrumenting them with their own lagged values at t-5,\,t-10,\,t-15 plus cross-channel interactions at t-5. The first-stage F-statistic per channel, the Sargan over-identification J-test, and the Durbin-Wu-Hausman endogeneity test are reported.

Usage

iv_2sls_attribute(C_ij, ch_per, R_full, channel_names = CHN_DEFAULT)

Arguments

C_ij

Numeric vector of pairwise daily co-movement (r_i * r_j).

ch_per

A data.frame containing the five channel composites for the current period (with columns named per channel_names).

R_full

Numeric matrix of returns for the period (used to construct the global factor f_t).

channel_names

Character vector of channel column names. Default c("Trade","Financial","Geopolitical","Behavioral","Monetary_Policy").

Value

A list with elements theta (5-vector of structural coefficients), partial_F (per-channel first-stage F-stats), J_stat, J_p, dwh_F, dwh_p, and n_obs; or NULL if the regression cannot be run.

References

Stock, J. H., & Watson, M. W. (2018). Identification and Estimation of Dynamic Causal Effects in Macroeconomics Using External Instruments. Economic Journal, 128(610), 917-948. doi: 10.1111/ecoj.12593.

Mertens, K., & Ravn, M. O. (2013). The Dynamic Effects of Personal and Corporate Income Tax Changes in the United States. American Economic Review, 103(4), 1212-1247. doi: 10.1257/aer.103.4.1212.

Examples


d <- load_paper_data()
ch <- build_channel_composites(d$proxies)
p <- period_subset(d$returns, ch, d$periods$GFC)
src <- as.numeric(p$R[, "USA"]); tgt <- as.numeric(p$R[, "SouthKorea"])
fit <- iv_2sls_attribute(src * tgt, p$C, p$R)
fit$theta


LASSO-Based Instrument Selection IV Attribution (Belloni-Chernozhukov-Hansen)

Description

Estimates the channel-attribution coefficients via post-double-selection LASSO IV with the high-dimensional instrument set. Uses hdm::rlassoIV per channel with controls for the other endogenous regressors. Requires the optional hdm package.

Usage

lasso_iv_attribute(C_ij, ch_per, R_full, channel_names = CHN_DEFAULT)

Arguments

C_ij

Numeric vector of pairwise daily co-movement (r_i * r_j).

ch_per

A data.frame containing the five channel composites for the current period (with columns named per channel_names).

R_full

Numeric matrix of returns for the period (used to construct the global factor f_t).

channel_names

Character vector of channel column names. Default c("Trade","Financial","Geopolitical","Behavioral","Monetary_Policy").

Value

A list with elements theta and se, or NULL.

References

Belloni, A., Chernozhukov, V., & Hansen, C. (2014). Inference on Treatment Effects after Selection among High-Dimensional Controls. Review of Economic Studies, 81(2), 608-650. doi: 10.1093/restud/rdt044.

Examples


if (requireNamespace("hdm", quietly = TRUE)) {
  d <- load_paper_data()
  ch <- build_channel_composites(d$proxies)
  p <- period_subset(d$returns, ch, d$periods$GFC)
  src <- as.numeric(p$R[, "USA"]); tgt <- as.numeric(p$R[, "SouthKorea"])
  fit <- lasso_iv_attribute(src * tgt, p$C, p$R)
}


Load the Paper's Bundled Data

Description

Convenience loader returning a named list with the three bundled datasets (returns, channel proxies, crisis periods) used in the paper replication.

Usage

load_paper_data()

Value

A named list with elements returns, proxies, and periods.

Examples

 d <- load_paper_data(); str(d, max.level = 1) 

Local-Projection Channel Attribution at Multiple Horizons

Description

Estimates horizon-specific impulse responses of the pairwise co-movement to each channel composite at horizons h \in \{1, 5, 22\} days following Jorda (2005). The local projection at horizon h estimates

C_{ij,t+h} = \alpha_h + \beta_{c,h} \, \mathrm{Channel}_{c,t} + \mathrm{controls} + u_{ij,t+h}

separately for each channel c, with the other four channels and the lagged co-movement and global factor entering as controls.

Usage

local_projections(
  C_ij,
  ch_per,
  R_full,
  horizons = c(1, 5, 22),
  channel_names = CHN_DEFAULT
)

Arguments

C_ij

Numeric vector of pairwise daily co-movement (r_i * r_j).

ch_per

A data.frame containing the five channel composites for the current period (with columns named per channel_names).

R_full

Numeric matrix of returns for the period (used to construct the global factor f_t).

horizons

Integer vector of horizons. Default c(1, 5, 22).

channel_names

Character vector of channel column names. Default c("Trade","Financial","Geopolitical","Behavioral","Monetary_Policy").

Value

A list with one element per horizon; each element is a length-length(channel_names) numeric vector of LP coefficients.

References

Jorda, O. (2005). Estimation and Inference of Impulse Responses by Local Projections. American Economic Review, 95(1), 161-182. doi: 10.1257/0002828053828518.

Plagborg-Moller, M., & Wolf, C. K. (2021). Local Projections and VARs Estimate the Same Impulse Responses. Econometrica, 89(2), 955-980. doi: 10.3982/ECTA17813.

Examples


d <- load_paper_data()
ch <- build_channel_composites(d$proxies)
p <- period_subset(d$returns, ch, d$periods$GFC)
src <- as.numeric(p$R[, "USA"]); tgt <- as.numeric(p$R[, "SouthKorea"])
lp <- local_projections(src * tgt, p$C, p$R)


MODWT Wavelet Detail at a Specified Scale

Description

Returns the MODWT detail coefficients of a return series at the specified scale, using the Daubechies least-asymmetric filter of length 8 (LA8). The maximal-overlap discrete wavelet transform is shift-invariant and aligned with the original time-axis, making it suited to financial returns; see Percival and Walden (2000).

Usage

modwt_detail(x, scale = 5, J = 6, filter = "la8")

Arguments

x

Numeric vector of returns.

scale

Integer scale (1-6) corresponding to dyadic horizons of [2^s, 2^{s+1}] trading days. Default 5 (32-64 day horizon).

J

Integer maximum decomposition level. Default 6.

filter

Character; the wavelet filter family to use. Default "la8" for the LA8 filter. See modwt.

Value

Numeric vector of detail coefficients at scale scale.

References

Percival, D. B., & Walden, A. T. (2000). Wavelet Methods for Time Series Analysis. Cambridge University Press.

Examples

x <- rnorm(512)
d5 <- modwt_detail(x, scale = 5)
length(d5)

Summary Statistics of a Contagion Network

Description

Returns a list of standard centrality and density statistics for a directed contagion network.

Usage

network_summary(g)

Arguments

g

An igraph object.

Value

A list with elements n_edges, density, in_degree, out_degree, betweenness, and eigenvector.

Examples

m <- matrix(runif(25, 0, 0.1), 5, 5); diag(m) <- 0
g <- build_network(m, threshold = 0.05)
network_summary(g)$density

Orthogonalise One Series Against Another

Description

Returns the residuals from a regression of y on x; the residual is by construction orthogonal to x in the sample. This is the pre-processing step used to construct the behavioural channel composite, which is orthogonalised against the financial composite to avoid the within-VIX decomposition that contaminates cross-channel identification when both composites share VIX-derivative inputs.

Usage

orthogonalise_residual(y, x)

Arguments

y

Numeric vector to be orthogonalised.

x

Numeric vector against which y is orthogonalised.

Value

Numeric vector of length length(y) containing the residuals.

Examples

a <- rnorm(100); b <- 0.5 * a + rnorm(100); cor(a, orthogonalise_residual(b, a))

Subset a Returns and Channel Panel by Period

Description

Selects the rows of an xts returns object and the matching rows of a channel-composite data.frame that fall within a date range.

Usage

period_subset(returns_xts, channels_df, period_dates)

Arguments

returns_xts

An xts object of daily returns indexed by Date.

channels_df

A data.frame with a Date column matching the index of returns_xts.

period_dates

A character or Date vector of length 2 c(start, end).

Value

A list with elements R (xts subset) and C (data.frame subset).

Examples


d <- load_paper_data()
ch <- build_channel_composites(d$proxies)
p <- period_subset(d$returns, ch, c("2008-01-01","2008-12-31"))
nrow(p$C)


Evolution-of-Shares Line Plot

Description

Line plot of channel-attribution share evolution across crisis sub-periods.

Usage

plot_attribution_evolution(period_shares)

Arguments

period_shares

Per-period share data.frame (output from run_contagion_pipeline).

Value

A ggplot object.


Stacked Bar Plot of Channel-Attribution Shares

Description

Draws a stacked bar chart of channel-attribution shares across crisis sub-periods. Returns a ggplot if ggplot2 is available, else uses base barplot.

Usage

plot_attribution_stack(period_shares, ...)

Arguments

period_shares

A data.frame with columns Period, Trade, Financial, Geopolitical, Behavioral, Monetary.

...

Additional arguments passed to ggplot2::ggsave or to barplot.

Value

A ggplot object (or invisibly the matrix used for base plotting).

Examples


d <- load_paper_data()
ch <- build_channel_composites(d$proxies)
res <- run_contagion_pipeline(d$returns, ch, d$periods, n_cores = 2)
plot_attribution_stack(res$period_shares)


Two-Panel QTE Intensity Plot

Description

Top panel: mean QTE per sub-period. Bottom panel: network density per sub-period.

Usage

plot_qte_intensity(stage1_summary)

Arguments

stage1_summary

A data.frame with columns Period, MeanQTE, Density.

Value

A patchwork ggplot if available, else a multi-panel base plot.


Robustness-Value Heatmap

Description

Heatmap of Cinelli-Hazlett robustness values per channel and sub-period.

Usage

plot_robustness_value(rv_matrix)

Arguments

rv_matrix

Numeric matrix with rownames = periods, colnames = channels.

Value

A ggplot object.


Pairwise Wavelet-Quantile Transfer Entropy

Description

Estimates the directional information flow from one wavelet-detail series x to another y at the specified quantile, following the quantile-regression-based transfer-entropy estimator. A positive value indicates that conditioning on the past of x improves the conditional-quantile prediction of y beyond what y's own past supplies.

Usage

qte_pair(x, y, tau = 0.5)

Arguments

x

Numeric source series (typically a MODWT detail coefficient).

y

Numeric target series (typically a MODWT detail coefficient).

tau

Quantile level in (0,1). Default 0.50 (median).

Value

A scalar; NA if there are insufficient observations or the quantile regressions fail to converge.

References

Schreiber, T. (2000). Measuring Information Transfer. Physical Review Letters, 85(2), 461. doi: 10.1103/PhysRevLett.85.461.

Han, H., Linton, O., Oka, T., & Whang, Y.-J. (2016). The Cross- Quantilogram. Journal of Econometrics, 193(1), 251-270. doi: 10.1016/j.jeconom.2016.03.001.

Examples

x <- rnorm(500); y <- 0.3 * c(0, x[-500]) + rnorm(500)
qte_pair(x, y, tau = 0.5)

Heteroskedasticity-Based Identification (Rigobon 2003)

Description

Identifies the channel-attribution coefficients by exploiting regime shifts in the variance of returns within the period. Useful when the Sargan over-identification test rejects the joint validity of external instruments and an alternative identification strategy is required.

Usage

rigobon_id(C_ij, ch_per, R_full, channel_names = CHN_DEFAULT)

Arguments

C_ij

Numeric vector of pairwise daily co-movement (r_i * r_j).

ch_per

A data.frame containing the five channel composites for the current period (with columns named per channel_names).

R_full

Numeric matrix of returns for the period (used to construct the global factor f_t).

channel_names

Character vector of channel column names. Default c("Trade","Financial","Geopolitical","Behavioral","Monetary_Policy").

Value

A list with element theta: a length-five numeric vector of structural coefficients, or NULL.

References

Rigobon, R. (2003). Identification through Heteroskedasticity. Review of Economics and Statistics, 85(4), 777-792. doi: 10.1162/003465303772815727.

Examples


d <- load_paper_data()
ch <- build_channel_composites(d$proxies)
p <- period_subset(d$returns, ch, d$periods$GFC)
src <- as.numeric(p$R[, "USA"]); tgt <- as.numeric(p$R[, "SouthKorea"])
rig <- rigobon_id(src * tgt, p$C, p$R)


End-to-End Contagion-Channel Pipeline

Description

Runs the full two-stage detection-and-attribution pipeline over a specified set of crisis sub-periods: Stage 1 produces a per-period WQTE flow matrix at the supplied scale and quantile, and Stage 2 attributes each significant link to one of five channels via IV/2SLS. Network density, top transmitter/receiver, and per-period channel-attribution shares are returned in a list.

Usage

run_contagion_pipeline(
  returns,
  channels,
  periods,
  scale = 5,
  tau = 0.5,
  threshold_period = names(periods)[1],
  edge_quantile = 0.75,
  n_cores = 2L
)

Arguments

returns

An xts of daily returns indexed by date.

channels

A data.frame of channel composites (output of build_channel_composites).

periods

A named list of length-2 character or Date vectors specifying c(start_date, end_date) for each sub-period.

scale

Integer wavelet scale. Default 5.

tau

Quantile level. Default 0.50.

threshold_period

Name of the period in periods from which the Pre-Crisis-baseline absolute threshold is computed. Default names(periods)[1].

edge_quantile

Numeric in (0,1); the quantile of positive WQTE in the threshold period used as the absolute threshold. Default 0.75.

n_cores

Integer number of parallel cores. Default 2L per CRAN policy; raise this for production-scale runs.

Value

A list with elements

stage1

Per-period list with F (flow matrix), network, and summary.

stage2

Per-period list of attribution data.frames with one row per significant link.

period_shares

Per-period mean attribution-share data.frame.

threshold

The absolute WQTE threshold used.

Examples


d <- load_paper_data()
ch <- build_channel_composites(d$proxies)
res <- run_contagion_pipeline(d$returns, ch, d$periods, n_cores = 2)
res$period_shares


Walktrap Community Detection on a Contagion Network

Description

Detects communities using the Walktrap algorithm of Pons and Latapy (2006) on the symmetrised version of the directed contagion network.

Usage

walktrap_communities(g)

Arguments

g

An igraph object.

Value

An integer vector of community memberships, one per vertex; or NULL if the network has too few edges.

Examples

m <- matrix(runif(25, 0, 0.1), 5, 5); diag(m) <- 0
g <- build_network(m, threshold = 0.02)
walktrap_communities(g)

Z-score Standardisation

Description

Returns the z-score of a numeric vector, robust to NAs and zero-variance input.

Usage

zscore(x)

Arguments

x

Numeric vector.

Value

Numeric vector of the same length as x with mean zero and unit standard deviation; returns a zero vector if the input has no finite variation.

Examples

zscore(rnorm(100))