multiarch 0.2.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,204 @@
1
+ Metadata-Version: 2.4
2
+ Name: multiarch
3
+ Version: 0.2.0
4
+ Summary: Fast multivariate GARCH for Python: CCC, DCC, aDCC, copula-DCC and GO-GARCH, validated against rmgarch
5
+ Author: Alex Nikolaenko
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/Legard525/multiarch
8
+ Project-URL: Issues, https://github.com/Legard525/multiarch/issues
9
+ Keywords: garch,dcc,multivariate garch,volatility,correlation,copula,go-garch,value-at-risk,econometrics,finance
10
+ Classifier: Development Status :: 4 - Beta
11
+ Classifier: Intended Audience :: Science/Research
12
+ Classifier: Intended Audience :: Financial and Insurance Industry
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Topic :: Scientific/Engineering :: Mathematics
15
+ Classifier: Topic :: Office/Business :: Financial :: Investment
16
+ Requires-Python: >=3.10
17
+ Description-Content-Type: text/markdown
18
+ License-File: LICENSE
19
+ Requires-Dist: numpy>=1.24
20
+ Requires-Dist: scipy>=1.10
21
+ Requires-Dist: pandas>=2.0
22
+ Requires-Dist: numba>=0.58
23
+ Provides-Extra: test
24
+ Requires-Dist: pytest; extra == "test"
25
+ Requires-Dist: arch; extra == "test"
26
+ Dynamic: license-file
27
+
28
+ # multiarch
29
+
30
+ [![tests](https://github.com/Legard525/multiarch/actions/workflows/tests.yml/badge.svg)](https://github.com/Legard525/multiarch/actions/workflows/tests.yml)
31
+
32
+ **Multivariate GARCH for Python.** The [`arch`](https://github.com/bashtage/arch) package
33
+ only fits univariate models, so Python has had no maintained multivariate GARCH library.
34
+ Courses and research therefore send Python users to R (`rmgarch`, `tsmarch`).
35
+ multiarch fills that gap:
36
+
37
+ - **Models:** CCC, DCC and asymmetric DCC, optionally as Gaussian or Student-t copulas, plus GO-GARCH.
38
+ - **Margins:** GARCH(1,1) or GJR-GARCH(1,1) with normal or Student-t errors.
39
+ - **Inference:** two-step standard errors that correct for the first estimation stage.
40
+ - **Large cross-sections:** a composite-likelihood estimator for many assets.
41
+ - **Outputs:** forecasts, simulation, portfolio VaR and ES, rolling backtests and specification tests.
42
+ - **Validation:** it reproduces `rmgarch`'s likelihood exactly. It runs 2–9× faster than rmgarch and 7–30× faster than tsmarch.
43
+
44
+ ```bash
45
+ pip install multiarch
46
+ ```
47
+
48
+ Requires Python ≥ 3.10, NumPy, SciPy, pandas and numba.
49
+
50
+ ## Quick start
51
+
52
+ ```python
53
+ import multiarch as ma
54
+
55
+ res = ma.DCC(returns).fit() # returns: (T, N) DataFrame, any units
56
+ print(res.summary())
57
+
58
+ res.conditional_correlation # (T, N, N) R_t
59
+ res.conditional_covariance # (T, N, N) H_t = D_t R_t D_t
60
+ res.correlation("JPM", "INTC") # one rho_t path as a Series
61
+ res.forecast(10) # mean, variance, correlation, covariance
62
+ res.value_at_risk([0.5, 0.5], level=0.01, value=1e6) # {'VaR': ..., 'ES': ...}
63
+ ```
64
+
65
+ [`examples/course_workflow.py`](https://github.com/Legard525/multiarch/blob/main/examples/course_workflow.py) walks through the standard
66
+ course sequence: EWMA → CCC → DCC → constant-correlation test → portfolio VaR → rolling VaR backtest.
67
+
68
+ ## What's in it
69
+
70
+ | | |
71
+ |---|---|
72
+ | `DCC(returns, model=...)` | `"dcc"` (Engle 2002), `"adcc"` (Cappiello, Engle & Sheppard 2006), `"ccc"` (Bollerslev 1990) |
73
+ | `vol=` | `"garch"` or `"gjr"` margins, each (1,1) |
74
+ | `mean=` | `"constant"` or `"zero"` |
75
+ | `dist=` | margin distribution, `"normal"` or `"t"` |
76
+ | `corr_dist=` | correlation-stage distribution, `"normal"` or multivariate `"t"` (defaults to `dist`) |
77
+ | `copula=` | `None`, `"normal"` or `"t"`: copula-DCC with parametric margins (as `rmgarch::cgarchfit`) |
78
+ | `estimator=` | `"full"` likelihood or `"composite"` pairwise likelihood (Engle, Shephard & Sheppard 2008) for large N |
79
+ | `convention=` | `"arch"` (default), `"rmgarch"` or `"tsmarch"`: start-up conventions that reproduce each package |
80
+ | `.fit(se=...)` | `"two-step"` (Engle & Sheppard 2001 corrected), `"naive"` or `None` |
81
+ | `.fix(params)` / `.apply(new_returns)` | evaluate fixed parameters, or filter new data with fitted ones |
82
+ | `.forecast(h)` | closed-form variances; Engle–Sheppard correlation forecast as in rmgarch |
83
+ | `.simulate(n, n_paths, start="end")` | Monte Carlo paths, including copula models |
84
+ | `.value_at_risk(w, level, horizon)` | analytic (normal or multivariate t) or simulated VaR and ES |
85
+ | `.value_at_risk_path(w, level)` | in-sample one-step VaR/ES path |
86
+ | `GOGARCH(returns)` | GO-GARCH (van der Weide 2002) with a built-in FastICA rotation |
87
+ | `rolling_forecast(returns, window, refit_every)` | rolling or expanding re-estimation with no look-ahead |
88
+ | `var_backtest(r, VaR, level)` | violation ratio, Kupiec and Christoffersen tests |
89
+ | `constant_correlation_test(returns)` | Engle & Sheppard (2001) test of CCC against DCC |
90
+ | `hosking_test(x, lags)` | multivariate portmanteau test |
91
+ | `ewma_covariance(returns, lam)` | RiskMetrics EWMA |
92
+ | `simulate_dcc(...)` | simulate from given parameters |
93
+
94
+ Estimation is scale-free: percent and fractional returns give the same parameters,
95
+ with ω and μ rescaled.
96
+
97
+ ## Validation
98
+
99
+ All numbers come from [`validation/`](https://github.com/Legard525/multiarch/tree/main/validation) and are reproducible: `Rscript rmgarch_fit.R .`
100
+ then `python compare.py`, and `Rscript tsmarch_fit.R .` then `python compare_tsmarch.py`.
101
+ The data are daily returns of DJI stocks from `rmgarch`'s `dji30ret` (T = 5,521).
102
+
103
+ ### Against rmgarch 1.3 (R 4.6)
104
+
105
+ `ll(ours @ rm)` is multiarch's log-likelihood evaluated at rmgarch's own estimates.
106
+ If both packages implement the same model, it equals rmgarch's reported value.
107
+
108
+ | case | ll (rmgarch) | ll (ours @ rm) | max \|ρ_t diff\| @ rm | ll (ours, own fit) | time rmgarch → ours |
109
+ |---|---|---|---|---|---|
110
+ | DCC, normal, N=5 | −53514.64292 | −53514.64292 | 0 | −53513.99601 | 2.8 s → 0.32 s |
111
+ | aDCC, normal | −53513.86843 | −53513.86843 | 0 | −53513.13231 | 3.4 s → 0.45 s |
112
+ | DCC, Student-t | −52235.91344 | −52235.91344 | 0 | −52237.53475 | 3.7 s → 0.60 s |
113
+ | DCC, GJR margins | −53481.97322 | −53481.97322 | 0 | −53481.59132 | 3.3 s → 0.39 s |
114
+ | DCC, zero mean | −53534.39786 | −53534.39786 | 0 | −53533.64643 | 2.1 s → 0.26 s |
115
+ | DCC, N=10 | −101267.48845 | −101267.48845 | 0 | −101266.80559 | 7.6 s → 1.2 s |
116
+ | DCC, raw returns, N=2 | 28163.98498 | 28163.98498 | 0 | 28163.97845 | 0.84 s → 0.09 s |
117
+ | t-copula DCC, t margins | −52079.16469 | −52079.16469 | 0 | −52080.47842 | 6.3 s → 3.1 s |
118
+ | Gaussian-copula DCC, t margins | −52196.46089 | −52196.46089 | 0 | −52197.96371 | 3.6 s → 1.1 s |
119
+
120
+ Timings for multiarch include the two-step standard errors.
121
+
122
+ - The likelihood functions are identical, and so are the correlation paths at the same parameters.
123
+ - The 10-step DCC covariance forecasts agree to 2e-14.
124
+ - Estimates differ only through the optimiser, and multiarch reaches higher margin likelihoods.
125
+ Because estimation is two-step, a better first stage can still leave the joint
126
+ log-likelihood slightly lower (the t and copula rows). That is a property of the two-step
127
+ estimator, not a different model.
128
+ - Standard errors for the DCC parameters *a* and *b* are within 5% of rmgarch's. For the shape ν and the aDCC asymmetry *g* they are 17–31% larger.
129
+ A 300-sample Monte Carlo (`mc_se.py`) shows that multiarch's two-step SEs are calibrated:
130
+ the median SE is 0.0059 against a sampling SD of 0.0059 for *a*, and 0.0124 against 0.0139 for *b*.
131
+ - **GO-GARCH:** given rmgarch's ICA rotation and factor parameters, the likelihood agrees to 0.06,
132
+ a difference that comes from how the constant mean is estimated. multiarch's own FastICA finds a rotation
133
+ with a likelihood 277 points higher on this data, in 0.04 s against 0.47 s.
134
+
135
+ ### Against tsmarch (the package used in *Financial Risk Forecasting* notes)
136
+
137
+ | case | ll (tsmarch) | ll (ours @ ts) | max \|ρ_t diff\| @ ts | time tsmarch → ours |
138
+ |---|---|---|---|---|
139
+ | DCC, N=2 | 28163.94124 | 28163.94306 | 4.5e-4 | 0.73 s → 0.04 s |
140
+ | DCC, N=5 | 73611.21223 | 73611.23406 | 4.2e-4 | 2.7 s → 0.10 s |
141
+ | aDCC, N=5 | 73612.01170 | 73612.03276 | 4.2e-4 | 3.8 s → 0.11 s |
142
+ | DCC, multivariate t | 74873.58661 | 74873.58785 | 3.8e-4 | 3.9 s → 0.13 s |
143
+
144
+ The margins match tsgarch exactly (σ_t to 1e-14). A residual gap of under 0.03 log-likelihood
145
+ points remains in tsmarch's compiled DCC recursion; it fades to 1e-7 by the end of the sample.
146
+
147
+ ### Notes on rmgarch's `DCCtest`
148
+
149
+ `rmgarch::DCCtest` departs from Engle & Sheppard (2001) in two ways. It calls
150
+ `qr.solve(regressand, regressors)`, which regresses the lags on the target instead of the
151
+ reverse, and it divides by √σ² instead of σ². `validation/compare.py` reproduces its statistic
152
+ exactly (65.34) from its own residuals. On the same residuals, the textbook statistic
153
+ returned by `constant_correlation_test` is 41.08.
154
+
155
+ ### Scaling
156
+
157
+ From `validation/bench.py` (T = 2,500, no SEs):
158
+
159
+ | N | full likelihood | composite likelihood |
160
+ |---|---|---|
161
+ | 5 | 0.05 s | 0.02 s |
162
+ | 25 | 0.34 s | 0.09 s |
163
+ | 50 | 0.35 s | 0.19 s |
164
+ | 100 | n/a | 0.41 s |
165
+
166
+ The full-likelihood DCC estimate of *b* is biased downward as N grows: 0.930 against a true 0.95
167
+ at N = 50. The composite estimator does not have this bias.
168
+
169
+ ## Conventions
170
+
171
+ The default (`"arch"`) follows the `arch` package for the margins (exponential backcast)
172
+ and uses Q̄ = Z′Z/T with Q₁ = Q̄. `convention="rmgarch"` reproduces rmgarch's start-up:
173
+ - σ²₁ is the sample mean of ε².
174
+ - Q̄ = cov(Z).
175
+ - The first Q step uses a pre-sample shock of ones in DCC and of zeros in copula-DCC.
176
+ - Copula uniforms are clipped at 0.99999.
177
+
178
+ `convention="tsmarch"` reproduces tsgarch's σ²₁ = ω + persistence · mean(ε²) and uses Q₁ = Q̄ = cov(Z).
179
+ These choices only affect the first few dozen observations.
180
+
181
+ ## Limitations
182
+
183
+ - Margins are GARCH(1,1) or GJR(1,1) with a constant or zero mean. There are no ARMA means or higher orders.
184
+ - DCC is of order (1,1).
185
+ - Estimation is two-step. The two-step SEs treat Q̄ and N̄ as known, as rmgarch does.
186
+ - Composite-likelihood SEs are Hessian-only.
187
+ - GO-GARCH SEs ignore estimation error in the rotation.
188
+ - Copula models use parametric margins only. Empirical and semi-parametric margins are not implemented.
189
+ - BEKK and DCC-MIDAS are not implemented.
190
+
191
+ ## References
192
+
193
+ - Bollerslev (1990), *Modelling the coherence in short-run nominal exchange rates*, REStat.
194
+ - Engle (2002), *Dynamic conditional correlation*, JBES.
195
+ - Engle & Sheppard (2001), *Theoretical and empirical properties of dynamic conditional correlation multivariate GARCH*, NBER WP 8554.
196
+ - Cappiello, Engle & Sheppard (2006), *Asymmetric dynamics in the correlations of global equity and bond returns*, J. Fin. Econometrics.
197
+ - Engle, Shephard & Sheppard (2008), *Fitting vast dimensional time-varying covariance models*, working paper.
198
+ - van der Weide (2002), *GO-GARCH: a multivariate generalized orthogonal GARCH model*, J. Applied Econometrics.
199
+ - Patton (2006), *Modelling asymmetric exchange rate dependence*, IER.
200
+ - Kupiec (1995); Christoffersen (1998); Hosking (1980).
201
+
202
+ ## License
203
+
204
+ MIT
@@ -0,0 +1,15 @@
1
+ multiarch/__init__.py,sha256=Rj6AANHp5NNflm9d8mdPnZ5y3IHLazqkX4ej3dsdBCk,703
2
+ multiarch/_kernels.py,sha256=VR2nPjvHxCTRsHvdQtXSvVStjdAgCwjSgX8xfKlUIF4,7542
3
+ multiarch/_numdiff.py,sha256=Eq2O1EG4Cqcpfq7Ae-QEkcRRZiUq2s_7smap1EIdeJo,1147
4
+ multiarch/dcc.py,sha256=K1w6H_0QfDWnHz3KV79PGe1jaqdcg5jsJIrpFyYfaT0,30591
5
+ multiarch/diagnostics.py,sha256=0IKLH3G_AZFzxE1mC_Sg0PXRgJgS_XxgA88QGZZEipo,4421
6
+ multiarch/ewma.py,sha256=zakD2rsz3AimRXI9WpcGPn0xppcpelOMlB7vQDgbbH8,812
7
+ multiarch/gogarch.py,sha256=3tyISuIqN0bgx4O_359knD0VyhsbHvlVT6tj-Pvg90Y,8783
8
+ multiarch/rolling.py,sha256=VzMrNaBb9slHU6Fvj8LyTFsaQP5pfdbp3Dz2zRfXluA,2817
9
+ multiarch/simulate.py,sha256=zoXtGfw3msON0f9PPRkDhPDBDypQA7mX0oPnzcTUSPc,1954
10
+ multiarch/univariate.py,sha256=PzCvSB7Px2oSL1tCvhV3Pa5NIKl-mJVXr3KfsnuDxBE,7091
11
+ multiarch-0.2.0.dist-info/licenses/LICENSE,sha256=XESk3GhrFUS2By9A6Yt8JVe9Gyx6eNENAKKsPRvmaDk,1066
12
+ multiarch-0.2.0.dist-info/METADATA,sha256=-wy8Zl3Y9aZl70e2z4riZkKGgm6qg-yCZqTqtyttSdI,10957
13
+ multiarch-0.2.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
14
+ multiarch-0.2.0.dist-info/top_level.txt,sha256=sZYDJXMG2bonzIxzZ83w8DFG28b4ATbhRSZZYtfoODI,10
15
+ multiarch-0.2.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.2.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Legard525
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ multiarch