connectedness for Stata, Part 3: Portfolios, Clustered Networks and Bootstrap Inference
StataConnectednessSpilloversBootstrapClustered ConnectednessPortfolio OptimizationHedgingDCC-GARCHEconometricsFinancial NetworksOpen Source

connectedness for Stata, Part 3: Portfolios, Clustered Networks and Bootstrap Inference

Prof. Dr. Nikolaos Antonakakis
191 views

Versions 0.8.0 to 0.9.2 of the free connectedness package for Stata add portfolio and hedging tools, DCC-GARCH R² connectedness, alternative normalizations, good and bad volatility spillovers, clustered network connectedness and bootstrap inference with event tests, with worked examples and checks against R and published results.

In Part 1 I introduced connectedness, a free Stata package for Diebold-Yilmaz and TVP-VAR connectedness, and in Part 2 I added frequency, quantile, R², penalized and DCC-GARCH connectedness. Since then, six more releases have taken the package from version 0.7.2 to 0.9.2.

The first three close the remaining gaps to David Gabauer's ConnectednessApproach R package: portfolio and hedging tools, DCC-GARCH R² connectedness, partial and conditional correlations, alternative normalizations, adaptive penalized VARs and the spillover asymmetry measure. The next three add two methods that, as far as I know, are not yet available in another R or Stata package: clustered network connectedness and a bootstrap test of whether connectedness changed after an event.

As in Part 2, each feature comes with a worked example on a dataset that ships with the package. Every number and figure below comes from running these examples in Stata 19 with version 0.9.2.

New to the package? Part 1 explains the connectedness measures (TO, FROM, NET, NPDC and the TCI) and the basic models, and Part 2 covers the extensions up to version 0.7.2.

What is new since Part 2

Portfolios and hedging

The new command cnportfolio: minimum connectedness, multivariate hedging, risk-parity and equally weighted portfolios, bivariate weights and hedge ratios, with hedging effectiveness and Sharpe ratios.

DCC-GARCH R²

R² decomposed connectedness of the DCC-GARCH conditional correlations, as in Cocca, Gabauer and Pomberger (2024).

Correlations

estat correlation gives the conditional or partial correlations of every period.

Normalizations

normalize(maxrow|maxcol|spectral): the scalar normalizations of Caloia, Cipollini and Muzzioli (2019).

Adaptive penalized VARs

adaptive reweights the LASSO, ridge and elastic-net penalties, as in Demirer, Diebold, Liu and Yilmaz (2018).

Good and bad volatility

positive() and negative() take realized semivariances and give the spillover asymmetry measure (SAM).

Clustered connectedness

clusters() splits connectedness into own, within-cluster and cross-cluster shares (Buchwalter, Diebold and Yilmaz 2026).

Bootstrap inference

estat bootstrap gives bias-corrected bands and event probabilities (Greenwood-Nimmo, Kočenda and Nguyen 2024), now also for pairwise and net pairwise measures.

The six releases:

VersionWhat it adds
0.8.0cnportfolio: portfolio and hedging strategies
0.8.1DCC-GARCH R² connectedness, estat correlation, a quantile frequency example
0.8.2Scalar normalizations, adaptive LASSO, ridge and elastic net, spillover asymmetry measure
0.9.0Clustered network connectedness
0.9.1estat bootstrap: bias-corrected bootstrap bands and event tests
0.9.2Bootstrap bands for pairwise and NPDC measures, and event tests for any measure with stat()

With 0.8.2, every connectedness model of ConnectednessApproach 1.0.4 is available in Stata. The package also ships with a new dataset, the daily volatilities of 19 equity markets from the replication files of Greenwood-Nimmo, Kočenda and Nguyen (2024), used in the bootstrap examples below.

Install or update

The same commands as before install or update the package. net get copies the 19 example datasets into the current working directory.

net install connectedness, from("https://raw.githubusercontent.com/Nikosanton82/connectedness-stata/main") replace
net get connectedness, from("https://raw.githubusercontent.com/Nikosanton82/connectedness-stata/main")
which connectedness_estat      // should report version 0.9.2

Worked examples

1Portfolios and hedging with cnportfolio

Connectedness measures are often used to build portfolios. Broadstock, Chatziantoniou and Gabauer (2022) propose the minimum connectedness portfolio, which gives more weight to assets that are less connected with the others, and Cocca, Gabauer and Pomberger (2024) a multivariate hedging portfolio. cnportfolio computes these and the risk-parity, equally weighted and bivariate portfolios and hedge ratios from the matrices that the last estimation stored for every period. The example uses the four NASDAQ OMX clean energy indices of Cocca, Gabauer and Pomberger (2024), green economy (GRE), solar (SOL), wind (WIN) and geothermal (GEO), with a DCC-GARCH model (Gabauer 2020).

use cn_cgp2024, clear
tsset t
foreach v in GRE SOL WIN GEO {
    generate double r_`v' = `v'/100          // decimal returns
}
connectedness GRE SOL WIN GEO, model(dccgarch) horizon(10) datevar(date) replace
cnportfolio r_GRE r_SOL r_WIN r_GEO, method(mcp) saving(p_mcp, replace)
cnportfolio r_GRE r_SOL r_WIN r_GEO, method(rpp) saving(p_rpp, replace)
cnportfolio r_GRE r_SOL r_WIN r_GEO, method(ewp) saving(p_ewp, replace)
cnportfolio r_GRE r_SOL r_WIN r_GEO, method(mhp) saving(p_mhp, replace)
Minimum connectedness portfolio
Matrix: pairwise connectedness index   Periods: 3152   Results: p_dcc
Variance test: F test   Annualization: 252/year   Weights: long only
-----------------------------------------------------------------------------
             | --- Weight ------------------------ --- Portfolio ------------
             |     Mean Std.Dev.       5%      95%       HE  p-value       SR
-------------+---------------------------------------------------------------
         GRE |     0.10     0.06     0.00     0.20    -0.32    0.000     0.46
         SOL |     0.23     0.07     0.10     0.33     0.61    0.000     0.46
         WIN |     0.32     0.04     0.25     0.37     0.41    0.000     0.46
         GEO |     0.35     0.02     0.32     0.38     0.39    0.000     0.46
-----------------------------------------------------------------------------
Cumulative returns of three portfolios of clean energy indices
Figure 1. Cumulative returns of the minimum connectedness, risk-parity and equally weighted portfolios of four clean energy indices, December 2010 to June 2023. The three strategies move closely together.

The minimum connectedness portfolio puts about two thirds of its weight on wind and geothermal and only 10% on the broad green economy index. Its annualized Sharpe ratio is 0.46, against 0.49 for risk parity and 0.51 for equal weights, so in this sample the simplest strategy does at least as well. The multivariate hedging portfolio, which hedges each index with the other three, lowers the variance of a single index by between 22% (geothermal) and 60% (green economy).

Each method reports the mean and quantiles of the weights or hedge ratios, the hedging effectiveness (HE), a test of equal variances (test(): F, Bartlett, Fligner-Killeen, Levene or Brown-Forsythe) and the annualized return, risk and Sharpe ratio, and saves the series in a frame. matrix(pci|cov|cor) chooses the matrix the weights are based on, and nolong allows short positions.

2DCC-GARCH R² connectedness and correlations

Cocca, Gabauer and Pomberger (2024) apply the R² decomposition of Part 2 to the conditional correlations of a DCC-GARCH model, so connectedness can be measured in every period without a rolling window. With the same data, approach(r2) does this, and estat correlation gives the conditional correlations or, with partial, the partial correlations of every period.

connectedness GRE SOL WIN GEO, model(dccgarch) approach(r2) datevar(date) replace
cngraph tci
estat correlation, partial frame(p_pcor) replace
Total connectedness of four clean energy indices from DCC-GARCH R-squared decomposition
Figure 2. Total connectedness from the R² decomposition of the DCC-GARCH correlations. It peaks near 60% in 2011 and again in March 2020.

The average TCI is 37.28% (49.70% corrected). The green economy index is the only net transmitter (NET = 5.18), plausibly because the broad index overlaps with the other three, and its average partial correlation with the solar index, 0.54, is the highest of any pair.

3Normalization schemes

The generalized forecast error variance decomposition does not sum to one across each row, so Diebold and Yilmaz (2012) divide every row by its sum. Caloia, Cipollini and Muzzioli (2019) show that this row normalization can change the ranking of net spillovers, and propose scalar normalizations that divide the whole matrix by one number: the largest row sum, the largest column sum or the spectral radius. normalize() implements them. The example uses the volatilities of US stocks, bonds, commodities and the dollar from Diebold and Yilmaz (2012).

use cn_dy2012, clear
tsset t
connectedness SP500 R_10Y DJUBSCOM USDX, lags(4) horizon(10)
foreach n in maxrow maxcol spectral {
    connectedness SP500 R_10Y DJUBSCOM USDX, lags(4) horizon(10) normalize(`n') replace
}
NET (percent)    SP500     R_10Y  DJUBSCOM      USDX
     row          5.13     -0.54     -1.69     -2.90
  maxrow          5.40     -1.63     -0.97     -2.79
  maxcol          5.37     -1.63     -0.97     -2.77
spectral          5.61     -1.70     -1.01     -2.90
NET connectedness of four US asset classes under four normalizations
Figure 3. NET connectedness of US stocks, the 10-year yield, commodities and the dollar under row normalization and the three scalar normalizations.

Under row normalization, commodities are a larger net receiver than bonds (−1.69 against −0.54). Under all three scalar normalizations the order reverses, as Caloia, Cipollini and Muzzioli (2019) report: bonds become the larger net receiver (about −1.6) and commodities the smaller one (about −1.0). Stocks remain the only net transmitter. The TO, FROM, NET and TCI values match Table 11 of their paper to the three decimals published.

4Good and bad volatility: the spillover asymmetry measure

Baruník, Kočenda and Vácha (2017) separate the volatility spillovers of good news from those of bad news with realized semivariances: the variance from positive returns and the variance from negative returns. positive() and negative() take the two sets of series directly and estimate the total, positive and negative systems; the spillover asymmetry measure (SAM) is the TCI of the positive system minus that of the negative one. The example uses daily squared returns of four exchange rates, split by sign, with 500-day windows.

use cn_g2020, clear
tsset t
foreach v in EUR GBP CHF JPY {
    generate double rv_`v' = `v'^2
    generate double rp_`v' = cond(`v' > 0, `v'^2, 0)
    generate double rn_`v' = cond(`v' < 0, `v'^2, 0)
}
connectedness rv_*, positive(rp_*) negative(rn_*) window(500) datevar(date) replace
frame cn_results: tsline sam
Spillover asymmetry measure of four exchange rates
Figure 4. Spillover asymmetry measure (positive minus negative TCI) of the euro, pound, Swiss franc and yen. Flat stretches that last exactly 500 days show a single extreme day entering and later leaving the window.

On average, good-volatility spillovers are slightly larger (SAM = 2.63 TCI points), but the sign changes over time: mostly negative before 2007, mostly positive from 2008 to early 2015, and negative afterwards. The figure is also a useful caution. With squared daily returns, one extreme day can dominate a rolling window for its whole length, so the measure is worth checking with other window lengths and with realized semivariances from intraday data, as in the original papers.

5Clustered network connectedness

Standard connectedness measures treat every variable alike. Buchwalter, Diebold and Yilmaz (2026) group the variables into clusters, such as regions, and identify shocks that may be correlated within a cluster but are orthogonal across clusters. Each cluster's forecast error variance then splits into three shares: its own shocks, co-movement with other members of the same cluster, and contagion from other clusters. The results are averaged over all orderings of the clusters. clusters() works with every VAR-type and TVP-VAR model; the example uses the weekly equity returns of 19 markets from Diebold and Yilmaz (2009), in three regions.

use cn_dy2009, clear
tsset t
local reg `""Americas: US ARG BRA CHL MEX" "Europe: UK FRA GER TUR" "AsiaPacific: HKG JPN AUS IDN KOR MYS PHL SGP TAI THA""'
connectedness US-TUR, lags(2) horizon(12) clusters(`reg') replace
matrix list e(cl_shares)
connectedness US-TUR, lags(2) horizon(12) window(104) clusters(`reg') datevar(date) replace
frame cn_results: tsline cl_comove cl_contag
e(cl_shares)[4,5]
                own  comove  contag      to     net
   Americas   48.57   20.82   30.61   30.27   -0.34
     Europe   44.20   25.43   30.36   38.45    8.08
AsiaPacific   46.17   35.98   17.86   14.80   -3.06
    average   46.31   27.41   26.28      .z      .z

Over the full sample, about 30% of the forecast error variance of American and European markets is contagion from other regions, against 18% for Asia-Pacific, where co-movement within the region is larger (36%). Europe is the only net transmitter of contagion (NET = 8.08). With one cluster the decomposition is the generalized FEVD, and with one variable per cluster it is the Cholesky FEVD averaged over orderings.

Co-movement within regions and contagion across regions of 19 equity markets
Figure 5. System shares of co-movement within regions and contagion across regions, rolling 104-week windows. Contagion rises from about 32% in 1994 to about 55% in late 2007.

Co-movement stays between about 22% and 32%, while contagion trends up, with a jump in 1998 and a steep rise in 2006 and 2007. The replication do-file cn_rep_2025bdy.do applies the paper's own design, an adaptive elastic-net VAR, to the same data.

6Bootstrap bands: is the TCI estimated precisely?

Connectedness measures are usually reported without standard errors, and referees often ask whether a rise in the TCI is significant. Greenwood-Nimmo, Kočenda and Nguyen (2024) propose a residual bootstrap of the VAR in each window. estat bootstrap implements it: new samples are generated recursively from the estimated VAR, unstable draws are discarded, a first round of draws estimates the bias of each measure and a second round gives bias-corrected percentile bands. The example uses the daily volatilities of 19 equity markets from their replication files, with 200-day windows.

use cn_gkn2024, clear
tsset t
connectedness US-TUR, lags(2) horizon(10) window(202) datevar(date) replace
estat bootstrap, reps(500) every(10) seed(1357) npdc
frame cn_boot: twoway rarea tci_lo tci_hi date || line tci_bc date || line tci date
Bias-corrected total connectedness of 19 equity markets with bootstrap bands
Figure 6. TCI of 19 equity markets: estimate (dashed), bias-corrected TCI and 95% band, every tenth window. The dotted vertical lines mark 17 October 1997, 11 September 2001 and 9 August 2007.

The bias is positive in every window, as the authors find, and large: 9.25 TCI points on average, so the bias-corrected TCI averages 43.39% against an estimate of 52.65%. With 19 variables and 200 observations per window, the uncorrected index overstates connectedness noticeably, which matters when levels are compared across studies. A full rolling bootstrap refits the VAR 2 × reps() times in every window, so every() keeps the run time manageable.

7Event tests: did connectedness rise after the event?

event() gives, for each event date, the probability that the bias-corrected TCI of the window ending on the event date, and of the windows leads() later, exceeds its level just before the event. The authors treat probabilities of at least 90% as significant. The example reproduces Table 3 of their paper, with 20 events and 1,000 draws per round.

* the 20 event dates are listed in replication/cn_rep_2024gkn.do
estat bootstrap, event(17oct1997 27oct1997 13jul1998 /* ... */ 09aug2007) ///
    leads(0 1 5 10 22) seed(1357)
Probability (percent) that the bias-corrected TCI is above its level in the window
before the event, by lead (windows after the event window)
-----------------------------------------------------------------------------
Event               Window|         0         1         5        10        22
--------------------------+--------------------------------------------------
17oct1997        17oct1997|     93.6*     83.1     100.0*    100.0*    100.0*
11sep2001        11sep2001|     99.1*    100.0*    100.0*    100.0*    100.0*
14nov2003        14nov2003|     45.2      50.1      81.4      46.4      41.8
09aug2007        09aug2007|     52.0      56.3      50.5      99.9*     99.9*
-----------------------------------------------------------------------------
* at least 90 percent. Windows are dated by their last observation.
Event probabilities from Stata against those published in the paper
Figure 7. The 200 event probabilities of Table 3 (20 events, 5 leads, generalized and orthogonalized FEVD): published values against those of connectedness for Stata.

A bootstrap with different random draws cannot reproduce the published numbers exactly, but it should come close. For each identification, 96 of the 100 probabilities are within 5 percentage points of the paper's, and the mean absolute difference is 1.5 points (generalized) and 1.3 points (orthogonalized). The verdict at 90% is the same for 99 and 100 of the 100. One detail matters: the Istanbul bombing of 15 November 2003 fell on a Saturday, and the paper's figures correspond to the previous trading day, so the replication do-file cn_rep_2024gkn.do uses 14 November. By default, a date without a window moves to the next window.

threshold(#) gives the probability of a rise of at least # percent, decrease that of a fall, reference(#) compares with the mean of several earlier windows, and detect(#) computes the probability for every window to locate changes at unknown dates.

8Pairwise and net pairwise measures, and stat()

Version 0.9.2 extends the bootstrap to the pairwise connectedness table (pairwise) and to net pairwise directional connectedness (npdc), from the same draws at almost no extra cost. In rolling estimations the bands go into a long frame with one row per window and ordered pair, so one pair is easy to plot. The run above stored them for the 342 ordered pairs of the 19 markets.

frame cn_boot_pw: twoway (rarea npdc_lo npdc_hi date) (line npdc_bc date) ///
    if from == "US" & to == "JPN"
estat bootstrap, event(17oct1997 11sep2001 09aug2007) leads(0 1 5 22) seed(1357) ///
    stat(npdc US JPN)
Net spillover from the US to Japan with bootstrap bands
Figure 8. Bias-corrected net spillover from the US to Japan and its 95% band, every tenth window.
Probability (percent) that the bias-corrected net spillover from US to JPN is
above its level in the window before the event, by lead
-------------------------------------------------------------------
Event               Window|         0         1         5        22
--------------------------+----------------------------------------
17oct1997        17oct1997|     41.3       9.5       4.1      72.8
11sep2001        11sep2001|     44.8      54.7      95.7*     95.2*
09aug2007        09aug2007|     70.0      89.8      33.6      31.8
-------------------------------------------------------------------

On average the US is a net transmitter to Japan (2.1 points), but the band excludes zero in only 44 of the 264 windows shown and never lies entirely below zero. After 11 September 2001, the net spillover from the US to Japan is higher with a probability of about 95% one week and one month later, while the Hong Kong crisis of October 1997 did not raise it. stat() also takes to, from, net and pairwise measures. Static results display the bias-corrected pairwise and NPDC tables, with a star where the interval of a net spillover excludes zero.

Checked against R and the published results

As before, everything is tested against an independent reference. For the ports, the reference is ConnectednessApproach 1.0.4 and the R packages it relies on. Neither the clustered method nor the bootstrap has public code, so I wrote independent R implementations from the papers and compared both programs on the same random draws.

FeatureReferenceLargest difference
Portfolios and hedging (0.8.0)17 R cases3 × 10−14; risk-parity weights 6 × 10−9, the precision of R's solver
DCC-GARCH R², correlations (0.8.1)5 R cases6 × 10−14 with R's DCC-GARCH estimates
Normalizations, adaptive penalized VARs (0.8.2)9 R cases; Table 11 of Caloia et al. (2019)3 × 10−13; the published table to its three decimals
Clustered connectedness (0.9.0)Independent R implementation, 6 cases; nested cases8 × 10−13; generalized and Cholesky FEVD to 2 × 10−15
Bootstrap and event tests (0.9.1)Independent R bootstrap on the same draws; Table 3 of the paper7 × 10−14; 96 of 100 published probabilities within 5 points
Pairwise and NPDC bands, stat() (0.9.2)Independent R bootstrap on the same draws8 × 10−14

The certification script now runs 280 tests, all of which pass in Stata 19, and the logs are in the docs/ folder of the repository. I also installed the releases from GitHub into an empty folder and reran the help examples and replication do-files, to check that nothing depends on my development setup.

How it was built

As with the earlier releases, these were developed with the assistance of Claude Code. I guided the work, reviewed, corrected and proofread everything, tested it in Stata 19, and confirmed that it matches the references above.

Feedback and what comes next

The next releases will add new model classes, such as BEKK volatility spillovers, regime-dependent and persistence-based connectedness, mixed-frequency data and adaptive window lengths. Version 1.0 will then fix the syntax, the package will go to SSC, and a second Stata Journal article will cover clustered connectedness and bootstrap inference. The article on the core package is under review at the Stata Journal.

If you use the new features, I would like to hear how they work in your applications. Please report bugs, questions or requests on GitHub Issues or get in touch with me directly.

How to cite

If you use the package in your research, please cite the repository:

Antonakakis, N. (2026). connectedness: VAR-type, TVP-VAR and DCC-GARCH connectedness measures for Stata (Version 0.9.2) [Computer software]. GitHub. https://github.com/Nikosanton82/connectedness-stata
@software{antonakakis2026connectedness,
  author  = {Antonakakis, Nikolaos},
  title   = {connectedness: {VAR}-type, {TVP-VAR} and {DCC-GARCH} connectedness measures for {Stata}},
  year    = {2026},
  version = {0.9.2},
  url     = {https://github.com/Nikosanton82/connectedness-stata}
}

Please also cite the methodological papers behind the measures you report (listed below) and the ConnectednessApproach R package on which much of the implementation is based.

References

  1. Baruník, J., Kočenda, E., and Vácha, L. (2017). Asymmetric volatility connectedness on the forex market. Journal of International Money and Finance, 77, 39–56. https://doi.org/10.1016/j.jimonfin.2017.06.003
  2. Broadstock, D. C., Chatziantoniou, I., and Gabauer, D. (2022). Minimum connectedness portfolios and the market for green bonds: Advocating socially responsible investment (SRI) activity. In C. Floros and I. Chatziantoniou (Eds.), Applications in Energy Finance (pp. 217–253). Springer. https://doi.org/10.1007/978-3-030-92957-2_9
  3. Buchwalter, B., Diebold, F. X., and Yilmaz, K. (2026). Clustered network connectedness: A new measurement framework, with application to global equity markets. NBER Working Paper 34796. https://doi.org/10.3386/w34796
  4. Caloia, F. G., Cipollini, A., and Muzzioli, S. (2019). How do normalization schemes affect net spillovers? A replication of the Diebold and Yilmaz (2012) study. Energy Economics, 84, 104536. https://doi.org/10.1016/j.eneco.2019.104536
  5. Cocca, T., Gabauer, D., and Pomberger, S. (2024). Clean energy market connectedness and investment strategies: New evidence from DCC-GARCH R2 decomposed connectedness measures. Energy Economics, 136, 107680. https://doi.org/10.1016/j.eneco.2024.107680
  6. Demirer, M., Diebold, F. X., Liu, L., and Yilmaz, K. (2018). Estimating global bank network connectedness. Journal of Applied Econometrics, 33(1), 1–15. https://doi.org/10.1002/jae.2585
  7. Diebold, F. X., and Yilmaz, K. (2009). Measuring financial asset return and volatility spillovers, with application to global equity markets. Economic Journal, 119(534), 158–171. https://doi.org/10.1111/j.1468-0297.2008.02208.x
  8. Diebold, F. X., and Yilmaz, K. (2012). Better to give than to receive: Predictive directional measurement of volatility spillovers. International Journal of Forecasting, 28, 57–66. https://doi.org/10.1016/j.ijforecast.2011.02.006
  9. Gabauer, D. (2020). Volatility impulse response analysis for DCC-GARCH models: The role of volatility transmission mechanisms. Journal of Forecasting, 39(5), 788–796. https://doi.org/10.1002/for.2648
  10. Gabauer, D. (2025). ConnectednessApproach: Connectedness approach. R package version 1.0.4. https://CRAN.R-project.org/package=ConnectednessApproach
  11. Greenwood-Nimmo, M., Kočenda, E., and Nguyen, V. H. (2024). Detecting statistically significant changes in connectedness: A bootstrap-based technique. Economic Modelling, 140, 106843. https://doi.org/10.1016/j.econmod.2024.106843

Share this post

Written by

Prof. Dr. Nikolaos Antonakakis