gvar-toolbox 0.1.0__tar.gz

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.
Files changed (128) hide show
  1. gvar_toolbox-0.1.0/MANIFEST.in +9 -0
  2. gvar_toolbox-0.1.0/PKG-INFO +37 -0
  3. gvar_toolbox-0.1.0/README.md +126 -0
  4. gvar_toolbox-0.1.0/gvar/__init__.py +28 -0
  5. gvar_toolbox-0.1.0/gvar/__main__.py +19 -0
  6. gvar_toolbox-0.1.0/gvar/_build_stamp.py +15 -0
  7. gvar_toolbox-0.1.0/gvar/argspec.py +1834 -0
  8. gvar_toolbox-0.1.0/gvar/auggvar.py +1047 -0
  9. gvar_toolbox-0.1.0/gvar/auggvar_compare.py +424 -0
  10. gvar_toolbox-0.1.0/gvar/checkpoints.py +420 -0
  11. gvar_toolbox-0.1.0/gvar/cli.py +520 -0
  12. gvar_toolbox-0.1.0/gvar/compat.py +351 -0
  13. gvar_toolbox-0.1.0/gvar/core/__init__.py +1 -0
  14. gvar_toolbox-0.1.0/gvar/core/bootstrap.py +2038 -0
  15. gvar_toolbox-0.1.0/gvar/core/cointegration.py +305 -0
  16. gvar_toolbox-0.1.0/gvar/core/conditional.py +131 -0
  17. gvar_toolbox-0.1.0/gvar/core/contemp.py +215 -0
  18. gvar_toolbox-0.1.0/gvar/core/correlations.py +79 -0
  19. gvar_toolbox-0.1.0/gvar/core/critical_values.py +173 -0
  20. gvar_toolbox-0.1.0/gvar/core/diagnostics.py +192 -0
  21. gvar_toolbox-0.1.0/gvar/core/diagnostics_est.py +98 -0
  22. gvar_toolbox-0.1.0/gvar/core/dominant_unit.py +863 -0
  23. gvar_toolbox-0.1.0/gvar/core/exogeneity.py +378 -0
  24. gvar_toolbox-0.1.0/gvar/core/forecast.py +109 -0
  25. gvar_toolbox-0.1.0/gvar/core/foreign.py +363 -0
  26. gvar_toolbox-0.1.0/gvar/core/identification.py +351 -0
  27. gvar_toolbox-0.1.0/gvar/core/impulse.py +879 -0
  28. gvar_toolbox-0.1.0/gvar/core/joins.py +88 -0
  29. gvar_toolbox-0.1.0/gvar/core/lowmem.py +44 -0
  30. gvar_toolbox-0.1.0/gvar/core/lowmem_shrink.py +142 -0
  31. gvar_toolbox-0.1.0/gvar/core/matlab_rng.py +533 -0
  32. gvar_toolbox-0.1.0/gvar/core/persistence.py +44 -0
  33. gvar_toolbox-0.1.0/gvar/core/restricted.py +96 -0
  34. gvar_toolbox-0.1.0/gvar/core/selection.py +351 -0
  35. gvar_toolbox-0.1.0/gvar/core/solve.py +223 -0
  36. gvar_toolbox-0.1.0/gvar/core/stability.py +269 -0
  37. gvar_toolbox-0.1.0/gvar/core/tcdecomp.py +186 -0
  38. gvar_toolbox-0.1.0/gvar/core/tvweights.py +383 -0
  39. gvar_toolbox-0.1.0/gvar/core/unitroot.py +202 -0
  40. gvar_toolbox-0.1.0/gvar/core/varx.py +81 -0
  41. gvar_toolbox-0.1.0/gvar/core/weights.py +547 -0
  42. gvar_toolbox-0.1.0/gvar/defaults.py +1850 -0
  43. gvar_toolbox-0.1.0/gvar/demo/__init__.py +4 -0
  44. gvar_toolbox-0.1.0/gvar/demo/compare.py +222 -0
  45. gvar_toolbox-0.1.0/gvar/demo/fetch.py +256 -0
  46. gvar_toolbox-0.1.0/gvar/doctor/__init__.py +5 -0
  47. gvar_toolbox-0.1.0/gvar/doctor/budget.py +131 -0
  48. gvar_toolbox-0.1.0/gvar/doctor/calib.py +81 -0
  49. gvar_toolbox-0.1.0/gvar/doctor/cli.py +159 -0
  50. gvar_toolbox-0.1.0/gvar/doctor/env.py +690 -0
  51. gvar_toolbox-0.1.0/gvar/doctor/ladder.py +582 -0
  52. gvar_toolbox-0.1.0/gvar/doctor/parity.py +62 -0
  53. gvar_toolbox-0.1.0/gvar/doctor/privacy.py +126 -0
  54. gvar_toolbox-0.1.0/gvar/doctor/report.py +146 -0
  55. gvar_toolbox-0.1.0/gvar/doctor/run.py +431 -0
  56. gvar_toolbox-0.1.0/gvar/doctor/schema/doctor-report-2.json +269 -0
  57. gvar_toolbox-0.1.0/gvar/evaluate.py +513 -0
  58. gvar_toolbox-0.1.0/gvar/explore.py +1204 -0
  59. gvar_toolbox-0.1.0/gvar/forecast_benchmarks.py +146 -0
  60. gvar_toolbox-0.1.0/gvar/forecast_dm.py +503 -0
  61. gvar_toolbox-0.1.0/gvar/forecast_eval.py +1841 -0
  62. gvar_toolbox-0.1.0/gvar/forecast_stats.py +184 -0
  63. gvar_toolbox-0.1.0/gvar/forecast_targets.py +165 -0
  64. gvar_toolbox-0.1.0/gvar/horizons.py +148 -0
  65. gvar_toolbox-0.1.0/gvar/io/__init__.py +2 -0
  66. gvar_toolbox-0.1.0/gvar/io/artifacts.py +353 -0
  67. gvar_toolbox-0.1.0/gvar/io/biff.py +393 -0
  68. gvar_toolbox-0.1.0/gvar/io/countrydata_export.py +141 -0
  69. gvar_toolbox-0.1.0/gvar/io/custom_workbook.py +289 -0
  70. gvar_toolbox-0.1.0/gvar/io/ddps_trade.py +158 -0
  71. gvar_toolbox-0.1.0/gvar/io/dots.py +342 -0
  72. gvar_toolbox-0.1.0/gvar/io/drop.py +575 -0
  73. gvar_toolbox-0.1.0/gvar/io/extend.py +289 -0
  74. gvar_toolbox-0.1.0/gvar/io/fc_eval_sheets.py +538 -0
  75. gvar_toolbox-0.1.0/gvar/io/full_dataset.py +106 -0
  76. gvar_toolbox-0.1.0/gvar/io/full_output.py +4480 -0
  77. gvar_toolbox-0.1.0/gvar/io/graphs_export.py +408 -0
  78. gvar_toolbox-0.1.0/gvar/io/legacy_adapter.py +2102 -0
  79. gvar_toolbox-0.1.0/gvar/io/main_settings.py +823 -0
  80. gvar_toolbox-0.1.0/gvar/io/matlab_tree_export.py +906 -0
  81. gvar_toolbox-0.1.0/gvar/io/microfit_export.py +225 -0
  82. gvar_toolbox-0.1.0/gvar/io/naming.py +139 -0
  83. gvar_toolbox-0.1.0/gvar/io/output_classification.py +236 -0
  84. gvar_toolbox-0.1.0/gvar/io/ppp_gdp.py +558 -0
  85. gvar_toolbox-0.1.0/gvar/io/regional_export.py +316 -0
  86. gvar_toolbox-0.1.0/gvar/io/run_join.py +228 -0
  87. gvar_toolbox-0.1.0/gvar/io/sources.py +647 -0
  88. gvar_toolbox-0.1.0/gvar/io/tc_decomposition.py +129 -0
  89. gvar_toolbox-0.1.0/gvar/io/time_varying.py +51 -0
  90. gvar_toolbox-0.1.0/gvar/io/transforms.py +520 -0
  91. gvar_toolbox-0.1.0/gvar/io/uploads.py +957 -0
  92. gvar_toolbox-0.1.0/gvar/io/variables.py +433 -0
  93. gvar_toolbox-0.1.0/gvar/levels_dependent.py +216 -0
  94. gvar_toolbox-0.1.0/gvar/mcp_server.py +5227 -0
  95. gvar_toolbox-0.1.0/gvar/model_shape.py +20 -0
  96. gvar_toolbox-0.1.0/gvar/pipeline.py +3398 -0
  97. gvar_toolbox-0.1.0/gvar/plots.py +230 -0
  98. gvar_toolbox-0.1.0/gvar/present.py +963 -0
  99. gvar_toolbox-0.1.0/gvar/provenance.py +215 -0
  100. gvar_toolbox-0.1.0/gvar/refusals.py +95 -0
  101. gvar_toolbox-0.1.0/gvar/regional_aggregation.py +179 -0
  102. gvar_toolbox-0.1.0/gvar/regions.py +233 -0
  103. gvar_toolbox-0.1.0/gvar/report.py +280 -0
  104. gvar_toolbox-0.1.0/gvar/service/__init__.py +19 -0
  105. gvar_toolbox-0.1.0/gvar/service/data.py +127 -0
  106. gvar_toolbox-0.1.0/gvar/service/refine.py +112 -0
  107. gvar_toolbox-0.1.0/gvar/service/run.py +146 -0
  108. gvar_toolbox-0.1.0/gvar/spec/__init__.py +12 -0
  109. gvar_toolbox-0.1.0/gvar/spec/catalogue.py +813 -0
  110. gvar_toolbox-0.1.0/gvar/spec/foreign.py +150 -0
  111. gvar_toolbox-0.1.0/gvar/spec/model.py +301 -0
  112. gvar_toolbox-0.1.0/gvar/spec/route.py +715 -0
  113. gvar_toolbox-0.1.0/gvar/spec/rules.py +91 -0
  114. gvar_toolbox-0.1.0/gvar/spec/sentences.py +29 -0
  115. gvar_toolbox-0.1.0/gvar/spec/spec_schema.json +1739 -0
  116. gvar_toolbox-0.1.0/gvar/spec/strip.py +931 -0
  117. gvar_toolbox-0.1.0/gvar/spec/validate.py +2091 -0
  118. gvar_toolbox-0.1.0/gvar/spec/workbook.py +1398 -0
  119. gvar_toolbox-0.1.0/gvar/spec/xlsx.py +283 -0
  120. gvar_toolbox-0.1.0/gvar/wording.py +57 -0
  121. gvar_toolbox-0.1.0/gvar_toolbox.egg-info/PKG-INFO +37 -0
  122. gvar_toolbox-0.1.0/gvar_toolbox.egg-info/SOURCES.txt +126 -0
  123. gvar_toolbox-0.1.0/gvar_toolbox.egg-info/dependency_links.txt +1 -0
  124. gvar_toolbox-0.1.0/gvar_toolbox.egg-info/entry_points.txt +3 -0
  125. gvar_toolbox-0.1.0/gvar_toolbox.egg-info/requires.txt +37 -0
  126. gvar_toolbox-0.1.0/gvar_toolbox.egg-info/top_level.txt +1 -0
  127. gvar_toolbox-0.1.0/pyproject.toml +148 -0
  128. gvar_toolbox-0.1.0/setup.cfg +4 -0
@@ -0,0 +1,9 @@
1
+ prune tests
2
+ prune journal
3
+ prune docs
4
+ prune tools
5
+ prune app
6
+ prune space
7
+ prune ops
8
+ prune oracle
9
+ prune testdata
@@ -0,0 +1,37 @@
1
+ Metadata-Version: 2.4
2
+ Name: gvar-toolbox
3
+ Version: 0.1.0
4
+ Summary: Global VAR toolbox, ported from Pesaran's GVAR Toolbox 2.0 (MATLAB)
5
+ Requires-Python: >=3.10
6
+ Requires-Dist: numpy>=1.24
7
+ Requires-Dist: pandas>=2.0
8
+ Requires-Dist: xlrd>=2.0
9
+ Requires-Dist: jsonschema>=4
10
+ Requires-Dist: certifi
11
+ Requires-Dist: scipy>=1.10
12
+ Provides-Extra: plots
13
+ Requires-Dist: matplotlib>=3.5; extra == "plots"
14
+ Provides-Extra: auggvar-package
15
+ Requires-Dist: pypdfium2>=5.0; extra == "auggvar-package"
16
+ Provides-Extra: mcp
17
+ Requires-Dist: mcp<2,>=1.2; extra == "mcp"
18
+ Provides-Extra: legacy
19
+ Requires-Dist: xlrd>=2.0; extra == "legacy"
20
+ Requires-Dist: openpyxl>=3.1; extra == "legacy"
21
+ Provides-Extra: dev
22
+ Requires-Dist: pandas; extra == "dev"
23
+ Requires-Dist: pytest>=7; extra == "dev"
24
+ Requires-Dist: pytest-xdist>=3; extra == "dev"
25
+ Requires-Dist: openpyxl>=3.1; extra == "dev"
26
+ Requires-Dist: xlrd>=2.0; extra == "dev"
27
+ Requires-Dist: scipy>=1.10; extra == "dev"
28
+ Requires-Dist: streamlit<1.63,>=1.51; extra == "dev"
29
+ Requires-Dist: radon>=6; extra == "dev"
30
+ Requires-Dist: mcp<2,>=1.2; extra == "dev"
31
+ Requires-Dist: matplotlib>=3.5; extra == "dev"
32
+ Requires-Dist: pyyaml>=6; extra == "dev"
33
+ Requires-Dist: playwright==1.64.0; extra == "dev"
34
+ Requires-Dist: statsmodels>=0.15.0; extra == "dev"
35
+ Requires-Dist: reportlab; extra == "dev"
36
+ Requires-Dist: import-linter==2.15; extra == "dev"
37
+ Requires-Dist: lxml; extra == "dev"
@@ -0,0 +1,126 @@
1
+ # gvar
2
+
3
+ A Python port of Professor M. Hashem Pesaran's GVAR Toolbox 2.0 (MATLAB, 2014),
4
+ reproducing its estimation, solution, forecasting and impulse response analysis
5
+ — and validated against the toolbox's own output at every stage.
6
+
7
+ ```bash
8
+ python bootstrap.py # install, find your data, print what can be run
9
+ ```
10
+
11
+ ## Status
12
+
13
+ Fifteen checkpoints against MATLAB. The largest disagreement anywhere is
14
+ 4.5e-07, on quantities of order one.
15
+
16
+ | stage | values compared | agreement |
17
+ |---|---|---|
18
+ | trade weight matrix | 676 | 5.6e-16 |
19
+ | foreign variables | 1,092 | 6.8e-14 |
20
+ | VECMX\* coefficients | 3,611 | 6.2e-10 |
21
+ | unit root tests | 1,348 | 5.7e-11 |
22
+ | lag selection, rank statistics | 78 | 9.9e-10 |
23
+ | solved system eigenvalues | 408 | 1.5e-08 |
24
+ | forecasts | 5,320 | 9.6e-11 |
25
+ | oil-shock GIRFs | 5,576 | 5.3e-12 |
26
+ | oil-shock FEVDs | 5,576 | 2.8e-12 |
27
+ | persistence profiles | 2,706 | 5.8e-11 |
28
+ | pairwise correlations | 399 | 1.3e-12 |
29
+ | weak exogeneity tests | 206 | 3.1e-10 |
30
+ | conditional forecasts | 532 | 1.2e-11 |
31
+ | structural stability | 1,330 | 4.5e-07 |
32
+ | residual statistics | 1,197 | 5.5e-08 |
33
+
34
+ Validated against **two independent MATLAB runs**: the 2013 demonstrations, and
35
+ Kamiar Mohaddes' 2025Q4 run on data neither implementation's author prepared.
36
+ That second comparison found a real defect in this port that the first fifteen
37
+ checkpoints had missed.
38
+
39
+ 1,354 tests. `pytest -q`.
40
+
41
+ The figures above (checkpoint agreements, test count) move in the third
42
+ digit across library and platform versions — different BLAS, different
43
+ NumPy/SciPy point releases, a different OS. Anything quoted outside this
44
+ repo should be stated to one significant figure (e.g. "agreement of
45
+ order 1e-10 to 1e-7", not the exact digits above).
46
+
47
+ ## Beyond the toolbox
48
+
49
+ **Rolling-window forecast evaluation.** The toolbox computes forecasts; it has
50
+ no facility for asking how well a specification forecasts out of sample.
51
+
52
+ ```python
53
+ from gvar.evaluate import rolling, compare
54
+ compare(rolling(data), rolling(variant)) # ratio below 1: the variant wins
55
+ ```
56
+
57
+ **Specification sweeps.** Ingestion is 36 times faster and free on repeat, so a
58
+ full run takes 142 milliseconds. Perturbing every country's cointegrating rank
59
+ is 69 runs in ten seconds — about twenty-three hours of MATLAB — and on the
60
+ 2013 demo it shows the US oil-shock response moving by 1070% under a single
61
+ rank change. Point estimates are harder to defend once that is cheap to check.
62
+
63
+ ## Running it
64
+
65
+ ```bash
66
+ python -m gvar.cli <workbook>.xls --flows <flows>.xls --report
67
+ python -m gvar.cli <workbook>.xls --weights-sheet wmat2 \
68
+ --girf poil --graphs out/ --pp --evaluate rmsfe.csv
69
+ ```
70
+
71
+ One of `--flows` or `--weights-sheet` is required. `--help` lists the rest:
72
+ impulse responses, variance decompositions, persistence profiles, conditional
73
+ forecasts, weak exogeneity, structural stability, residual statistics, charts,
74
+ and comparison against a MATLAB `output.xls`.
75
+
76
+ For variations without writing code:
77
+
78
+ ```python
79
+ from gvar.explore import run, compare
80
+ base = run(workbook, flows=flows)
81
+ alt = run(workbook, flows=flows, rank={"can": 3}, drop_last=1)
82
+ compare(base, alt, "usa", "y")
83
+ ```
84
+
85
+ ## Why it refuses things
86
+
87
+ Not one defect found during this port raised an exception. Every one produced
88
+ plausible numbers: a euro column summing to 0.407, an oil equation fitted with
89
+ eleven regressors where MATLAB uses nine, persistence profiles that began at
90
+ exactly 1.0 and were wrong from the first horizon.
91
+
92
+ So the engine stops rather than returning something that looks reasonable —
93
+ spectral radius, collinearity, forecasts leaving their historical range, rank
94
+ or lag out of range, ingestion canaries. Each guard caught something real. **A
95
+ refusal is a finding, not an obstacle.**
96
+
97
+ ## Documentation
98
+
99
+ | file | for |
100
+ |---|---|
101
+ | `START_HERE.md` | **the bootstrap — read this first, whether you are an agent or a person** |
102
+ | `CLAUDE.md` | auto-loaded by Claude Code; points at `START_HERE.md` |
103
+ | `AI_HANDOFF_WORKFLOW.md` | how code gets from a sandbox into this repo, and MCP cross-validation |
104
+ | `HANDOVER.md` | orientation to the port itself |
105
+ | `HANDOVER_YYYY_MM_DD.md` | session handovers; read the most recent |
106
+ | `reference/correspondence/` | every note sent to Professor Pesaran, indexed |
107
+ | `reference/papers/` | the academic sources, indexed |
108
+ | `CODE_MAP.md` | module by module, and where the awkward parts live |
109
+ | `CHANGELOG.md` | what changed, what it hinged on, and why |
110
+ | `REMAINING_WORK.md` | what is left, ranked, with what can validate each |
111
+ | `QUICKSTART.md` | running it |
112
+ | `COLAB_DEMO.md` | paste-and-run demonstration |
113
+ | `EXPLORING_WITH_CLAUDE.md` | setting up a Claude project; running variations |
114
+ | `GIRF_METHOD.md` | how impulse responses are computed |
115
+ | `MEMO.md` | written for Professor Pesaran |
116
+ | `DATABRICKS_SKETCH.md` | a deployment shape, written to be argued with |
117
+
118
+ ## Attribution
119
+
120
+ GVAR Toolbox 2.0 is the work of **M. Hashem Pesaran, L. Vanessa Smith and
121
+ Alessandro Galesi**. This is a port, not a new model. Any public release
122
+ requires their agreement and correct credit.
123
+
124
+ Methodology: Pesaran, Schuermann and Weiner (2004); Dees, di Mauro, Pesaran and
125
+ Smith (2007); Chudik and Pesaran (2016), *The Theory and Practice of GVAR
126
+ Modelling*, Journal of Economic Surveys 30, 165-197.
@@ -0,0 +1,28 @@
1
+ """GVAR Toolbox 2.0, ported to Python.
2
+
3
+ Validated against the MATLAB Brief and Full Demo outputs across ten
4
+ checkpoints, from trade weights through to 40-quarter forecasts.
5
+
6
+ from gvar.io import legacy_adapter
7
+ from gvar import models, pipeline
8
+
9
+ data = legacy_adapter.load("gvar.xls", flows="flows.xls")
10
+ result = pipeline.run(data)
11
+ """
12
+ def _resolve_version() -> str:
13
+ """Single source of truth: the exact same chain gvar.provenance uses
14
+ for the MCP gvar_version tool and every exported workbook's About
15
+ sheet (deploy-time stamp, then installed package metadata, then
16
+ pyproject.toml's own `version =` line -- see
17
+ gvar.provenance.engine_version_info's docstring for why each rung
18
+ exists), so this attribute cannot drift from what production
19
+ reports the way it just did: pyproject.toml moved to "0.27.1" in
20
+ e696a28 (a real gvar/core/exogeneity.py fix), on the same commit
21
+ this hardcoded literal was left at "0.27.0" -- nothing re-synced it,
22
+ and nothing would have caught a second one-line release bump doing
23
+ the same thing again."""
24
+ from . import provenance
25
+ return provenance.engine_version()
26
+
27
+
28
+ __version__ = _resolve_version()
@@ -0,0 +1,19 @@
1
+ """`python -m gvar`: `doctor` goes to gvar.doctor.cli, anything else to gvar.cli.main."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import sys
6
+
7
+
8
+ def _run() -> int:
9
+ if sys.argv[1:2] == ["doctor"]:
10
+ from .doctor.cli import main as doctor_main
11
+
12
+ return doctor_main(sys.argv[2:])
13
+ from .cli import main
14
+
15
+ return main()
16
+
17
+
18
+ if __name__ == "__main__":
19
+ raise SystemExit(_run())
@@ -0,0 +1,15 @@
1
+ """Placeholder. Overwritten by `.github/workflows/deploy-space.yml`'s
2
+ "Generate build stamp" step right before it uploads `gvar/` to the
3
+ Hugging Face Space, so the built container carries real values without
4
+ needing `.git` or a `pip install` of this package (neither is present
5
+ there -- see `gvar/provenance.py`'s module docstring for why).
6
+
7
+ In any OTHER checkout -- local dev, CI, a sandbox -- these stay `None`
8
+ and `gvar.provenance` falls through to its runtime-read layer (git,
9
+ then pyproject.toml) instead. Do not hand-edit these values; edit the
10
+ workflow step that generates them.
11
+ """
12
+ COMMIT_SHA = None
13
+ COMMIT_TIME = None
14
+ ENGINE_VERSION = None
15
+ BUILD_TIME = None