volatility-gamm 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.
- volatility_gamm-0.1.0/CITATION.cff +27 -0
- volatility_gamm-0.1.0/CONTRIBUTING.md +22 -0
- volatility_gamm-0.1.0/LICENSE +21 -0
- volatility_gamm-0.1.0/MANIFEST.in +8 -0
- volatility_gamm-0.1.0/PKG-INFO +261 -0
- volatility_gamm-0.1.0/PYPI_README.md +218 -0
- volatility_gamm-0.1.0/README.md +202 -0
- volatility_gamm-0.1.0/docs/index.rst +24 -0
- volatility_gamm-0.1.0/examples/run_synthetic_benchmark.py +10 -0
- volatility_gamm-0.1.0/examples/synthetic_5m.py +17 -0
- volatility_gamm-0.1.0/pyproject.toml +76 -0
- volatility_gamm-0.1.0/requirements.txt +2 -0
- volatility_gamm-0.1.0/setup.cfg +4 -0
- volatility_gamm-0.1.0/setup.py +3 -0
- volatility_gamm-0.1.0/src/gamm/__init__.py +43 -0
- volatility_gamm-0.1.0/src/gamm/data.py +211 -0
- volatility_gamm-0.1.0/src/gamm/experiment.py +122 -0
- volatility_gamm-0.1.0/src/gamm/garch.py +38 -0
- volatility_gamm-0.1.0/src/gamm/metrics.py +46 -0
- volatility_gamm-0.1.0/src/gamm/model.py +73 -0
- volatility_gamm-0.1.0/src/gamm/tuning.py +154 -0
- volatility_gamm-0.1.0/src/volatility_gamm.egg-info/PKG-INFO +261 -0
- volatility_gamm-0.1.0/src/volatility_gamm.egg-info/SOURCES.txt +28 -0
- volatility_gamm-0.1.0/src/volatility_gamm.egg-info/dependency_links.txt +1 -0
- volatility_gamm-0.1.0/src/volatility_gamm.egg-info/requires.txt +25 -0
- volatility_gamm-0.1.0/src/volatility_gamm.egg-info/top_level.txt +1 -0
- volatility_gamm-0.1.0/tests/test_data.py +54 -0
- volatility_gamm-0.1.0/tests/test_imports.py +4 -0
- volatility_gamm-0.1.0/tests/test_metrics.py +18 -0
- volatility_gamm-0.1.0/tests/test_tuning_space.py +15 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
cff-version: 1.2.0
|
|
2
|
+
message: "If you use GaMM in academic work, please cite this software and the associated paper."
|
|
3
|
+
title: "GaMM"
|
|
4
|
+
version: "0.1.0"
|
|
5
|
+
date-released: "2026-06-25"
|
|
6
|
+
authors:
|
|
7
|
+
- family-names: "Bhambu"
|
|
8
|
+
given-names: "Aryan"
|
|
9
|
+
license: "MIT"
|
|
10
|
+
repository-code: "https://github.com/statsdl/GaMM"
|
|
11
|
+
preferred-citation:
|
|
12
|
+
type: article
|
|
13
|
+
title: "High frequency volatility forecasting and risk assessment using neural networks-based heteroscedasticity model"
|
|
14
|
+
authors:
|
|
15
|
+
- family-names: "Bhambu"
|
|
16
|
+
given-names: "Aryan"
|
|
17
|
+
- family-names: "Bera"
|
|
18
|
+
given-names: "Koushik"
|
|
19
|
+
- family-names: "Natarajan"
|
|
20
|
+
given-names: "Selvaraju"
|
|
21
|
+
- family-names: "Suganthan"
|
|
22
|
+
given-names: "Ponnuthurai Nagaratnam"
|
|
23
|
+
journal: "Engineering Applications of Artificial Intelligence"
|
|
24
|
+
volume: "149"
|
|
25
|
+
year: 2025
|
|
26
|
+
start: "110397"
|
|
27
|
+
doi: "10.1016/j.engappai.2025.110397"
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# Contributing to GaMM
|
|
2
|
+
|
|
3
|
+
Contributions are welcome.
|
|
4
|
+
|
|
5
|
+
## Development setup
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
git clone https://github.com/statsdl/GaMM.git
|
|
9
|
+
cd GaMM
|
|
10
|
+
python -m venv .venv
|
|
11
|
+
source .venv/bin/activate
|
|
12
|
+
pip install -e ".[dev]"
|
|
13
|
+
python -m pytest
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Pull requests
|
|
17
|
+
|
|
18
|
+
Please keep changes focused, add tests for behavioral changes, and make sure the test suite passes before opening a pull request.
|
|
19
|
+
|
|
20
|
+
## Issues
|
|
21
|
+
|
|
22
|
+
Use GitHub Issues for bugs, feature requests, and questions about package behavior.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Aryan Bhambu
|
|
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,261 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: volatility-gamm
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: GARCH-based MLP Mixer for high-frequency volatility forecasting and risk assessment.
|
|
5
|
+
Author: Aryan Bhambu
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/statsdl/GaMM
|
|
8
|
+
Project-URL: Issues, https://github.com/statsdl/GaMM/issues
|
|
9
|
+
Keywords: gamm,garch,mlp-mixer,volatility,finance,high-frequency
|
|
10
|
+
Classifier: Development Status :: 3 - Alpha
|
|
11
|
+
Classifier: Intended Audience :: Science/Research
|
|
12
|
+
Classifier: Operating System :: OS Independent
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Topic :: Office/Business :: Financial
|
|
18
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
19
|
+
Requires-Python: >=3.10
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
License-File: LICENSE
|
|
22
|
+
Requires-Dist: numpy>=1.21
|
|
23
|
+
Requires-Dist: pandas>=1.3
|
|
24
|
+
Provides-Extra: model
|
|
25
|
+
Requires-Dist: tensorflow>=2.12; extra == "model"
|
|
26
|
+
Provides-Extra: tuning
|
|
27
|
+
Requires-Dist: hyperopt>=0.2.7; extra == "tuning"
|
|
28
|
+
Requires-Dist: setuptools<81; extra == "tuning"
|
|
29
|
+
Provides-Extra: arch
|
|
30
|
+
Requires-Dist: arch>=6.0; extra == "arch"
|
|
31
|
+
Provides-Extra: dev
|
|
32
|
+
Requires-Dist: build; extra == "dev"
|
|
33
|
+
Requires-Dist: hyperopt>=0.2.7; extra == "dev"
|
|
34
|
+
Requires-Dist: pytest; extra == "dev"
|
|
35
|
+
Requires-Dist: setuptools<81; extra == "dev"
|
|
36
|
+
Requires-Dist: twine; extra == "dev"
|
|
37
|
+
Provides-Extra: full
|
|
38
|
+
Requires-Dist: arch>=6.0; extra == "full"
|
|
39
|
+
Requires-Dist: hyperopt>=0.2.7; extra == "full"
|
|
40
|
+
Requires-Dist: setuptools<81; extra == "full"
|
|
41
|
+
Requires-Dist: tensorflow>=2.12; extra == "full"
|
|
42
|
+
Dynamic: license-file
|
|
43
|
+
|
|
44
|
+
# Project description
|
|
45
|
+
|
|
46
|
+
[](https://github.com/statsdl/GaMM)
|
|
47
|
+
[](https://github.com/statsdl/GaMM/commits/main)
|
|
48
|
+
[](https://github.com/statsdl/GaMM/issues)
|
|
49
|
+
[](https://github.com/statsdl/GaMM/stargazers)
|
|
50
|
+
[](https://pypi.org/project/volatility-gamm/)
|
|
51
|
+
[](https://github.com/statsdl/GaMM/blob/main/LICENSE)
|
|
52
|
+
|
|
53
|
+
A rich documentation is available in the GitHub repository.
|
|
54
|
+
|
|
55
|
+
# volatility-gamm
|
|
56
|
+
|
|
57
|
+
GARCH-based MLP Mixer for high-frequency volatility forecasting and risk assessment.
|
|
58
|
+
|
|
59
|
+
volatility-gamm is a Python package for volatility forecasting using GARCH-based MLP Mixer models. The package is designed for high-frequency financial time-series experiments where volatility dynamics, risk estimation, and nonlinear temporal structure are important.
|
|
60
|
+
|
|
61
|
+
The package combines GARCH-family volatility information with MLP-Mixer style neural feature learning. This allows volatility forecasts to benefit from both econometric conditional-volatility modeling and neural nonlinear representation learning.
|
|
62
|
+
|
|
63
|
+
This package provides two primary components:
|
|
64
|
+
|
|
65
|
+
* GARCH-based volatility features: utilities for using GARCH, GJR-GARCH, Threshold GARCH, AVGARCH, and FIGARCH conditional-volatility estimates as model inputs.
|
|
66
|
+
|
|
67
|
+
* GaMM neural model: a configurable MLP-Mixer style architecture for volatility forecasting with normalization, activation, dropout, feed-forward dimension, and mixer-block controls.
|
|
68
|
+
|
|
69
|
+
Both components are useful for volatility forecasting and risk assessment because financial time series often contain volatility clustering, nonlinear temporal dependence, and heavy-tailed risk behavior.
|
|
70
|
+
|
|
71
|
+
# Key Features
|
|
72
|
+
|
|
73
|
+
* GARCH-based MLP Mixer: Combines GARCH-family volatility features with neural MLP-Mixer modeling.
|
|
74
|
+
|
|
75
|
+
* High-Frequency Volatility Forecasting: Designed for intraday financial volatility forecasting tasks.
|
|
76
|
+
|
|
77
|
+
* Econometric Feature Integration: Supports GARCH, GJR-GARCH, Threshold GARCH, AVGARCH, and FIGARCH-style volatility features.
|
|
78
|
+
|
|
79
|
+
* Neural Forecasting Model: Provides Keras-based GaMM model construction and compilation utilities.
|
|
80
|
+
|
|
81
|
+
* Hyperparameter Tuning: Includes Hyperopt/TPE-based tuning helpers for reproducible model selection.
|
|
82
|
+
|
|
83
|
+
* Risk Assessment: Includes Value-at-Risk utilities for volatility-based financial risk evaluation.
|
|
84
|
+
|
|
85
|
+
* Forecasting Metrics: Provides RMSE, MAE, MAPE, NMAE, and QLIKE.
|
|
86
|
+
|
|
87
|
+
* Research-Oriented Design: Suitable for reproducible academic experiments in volatility forecasting and financial risk modeling.
|
|
88
|
+
|
|
89
|
+
# Installation
|
|
90
|
+
|
|
91
|
+
Downloading locally and installing
|
|
92
|
+
|
|
93
|
+
git clone https://github.com/statsdl/GaMM.git
|
|
94
|
+
cd GaMM
|
|
95
|
+
|
|
96
|
+
Install dependencies:
|
|
97
|
+
|
|
98
|
+
pip install -r requirements.txt
|
|
99
|
+
|
|
100
|
+
Install the package:
|
|
101
|
+
|
|
102
|
+
pip install -e .
|
|
103
|
+
|
|
104
|
+
Using pip install from GitHub
|
|
105
|
+
|
|
106
|
+
pip install git+https://github.com/statsdl/GaMM.git
|
|
107
|
+
|
|
108
|
+
Using pip install from PyPI
|
|
109
|
+
|
|
110
|
+
pip install volatility-gamm
|
|
111
|
+
|
|
112
|
+
Optional full installation
|
|
113
|
+
|
|
114
|
+
pip install "volatility-gamm[full]"
|
|
115
|
+
|
|
116
|
+
Development installation
|
|
117
|
+
|
|
118
|
+
pip install -e ".[dev]"
|
|
119
|
+
|
|
120
|
+
# Usage
|
|
121
|
+
|
|
122
|
+
## 1. GaMM model
|
|
123
|
+
|
|
124
|
+
Example
|
|
125
|
+
|
|
126
|
+
import numpy as np
|
|
127
|
+
from gamm.model import compile_gamm_model
|
|
128
|
+
|
|
129
|
+
X_train = np.random.randn(200, 20, 6).astype("float32")
|
|
130
|
+
y_train = np.random.rand(200).astype("float32")
|
|
131
|
+
|
|
132
|
+
model = compile_gamm_model(
|
|
133
|
+
input_shape=(X_train.shape[1], X_train.shape[2]),
|
|
134
|
+
learning_rate=0.001,
|
|
135
|
+
activation="relu",
|
|
136
|
+
n_block=2,
|
|
137
|
+
dropout=0.1,
|
|
138
|
+
ff_dim=64,
|
|
139
|
+
)
|
|
140
|
+
|
|
141
|
+
model.fit(X_train, y_train, epochs=5, batch_size=32, verbose=0)
|
|
142
|
+
|
|
143
|
+
predictions = model.predict(X_train[:10], verbose=0)
|
|
144
|
+
print("Volatility forecasts:", predictions.reshape(-1))
|
|
145
|
+
|
|
146
|
+
## 2. Volatility forecasting metrics
|
|
147
|
+
|
|
148
|
+
Example
|
|
149
|
+
|
|
150
|
+
import numpy as np
|
|
151
|
+
from gamm.metrics import (
|
|
152
|
+
root_mean_squared_error,
|
|
153
|
+
mean_absolute_error,
|
|
154
|
+
mean_absolute_percentage_error,
|
|
155
|
+
normalized_mean_absolute_error,
|
|
156
|
+
quasi_likelihood,
|
|
157
|
+
value_at_risk,
|
|
158
|
+
)
|
|
159
|
+
|
|
160
|
+
y_true = np.array([0.12, 0.15, 0.09, 0.18])
|
|
161
|
+
y_pred = np.array([0.11, 0.14, 0.10, 0.17])
|
|
162
|
+
|
|
163
|
+
print("RMSE:", root_mean_squared_error(y_true, y_pred))
|
|
164
|
+
print("MAE:", mean_absolute_error(y_true, y_pred))
|
|
165
|
+
print("MAPE:", mean_absolute_percentage_error(y_true, y_pred))
|
|
166
|
+
print("NMAE:", normalized_mean_absolute_error(y_true, y_pred))
|
|
167
|
+
print("QLIKE:", quasi_likelihood(y_true, y_pred))
|
|
168
|
+
print("VaR:", value_at_risk(0.05, y_pred))
|
|
169
|
+
|
|
170
|
+
## 3. Synthetic benchmark
|
|
171
|
+
|
|
172
|
+
Example
|
|
173
|
+
|
|
174
|
+
python examples/run_synthetic_benchmark.py
|
|
175
|
+
|
|
176
|
+
The benchmark compares GaMM with GARCH-family volatility estimates and reports volatility forecasting and risk metrics.
|
|
177
|
+
|
|
178
|
+
# API Reference
|
|
179
|
+
|
|
180
|
+
## Model utilities
|
|
181
|
+
|
|
182
|
+
`build_gamm_model`: Builds a GARCH-based MLP Mixer model.
|
|
183
|
+
|
|
184
|
+
`compile_gamm_model`: Builds and compiles the GaMM model with Adam optimizer and MSE loss.
|
|
185
|
+
|
|
186
|
+
## Tuning utilities
|
|
187
|
+
|
|
188
|
+
`gamm_tuning_space`: Returns the default Hyperopt/TPE search space.
|
|
189
|
+
|
|
190
|
+
`tune_gamm`: Tunes GaMM hyperparameters.
|
|
191
|
+
|
|
192
|
+
## GARCH utilities
|
|
193
|
+
|
|
194
|
+
`append_garch_features`: Adds GARCH-family conditional-volatility features when optional dependencies are installed.
|
|
195
|
+
|
|
196
|
+
## Metrics
|
|
197
|
+
|
|
198
|
+
`root_mean_squared_error`: Computes RMSE.
|
|
199
|
+
|
|
200
|
+
`mean_absolute_error`: Computes MAE.
|
|
201
|
+
|
|
202
|
+
`mean_absolute_percentage_error`: Computes MAPE.
|
|
203
|
+
|
|
204
|
+
`normalized_mean_absolute_error`: Computes range-normalized MAE.
|
|
205
|
+
|
|
206
|
+
`quasi_likelihood`: Computes QLIKE.
|
|
207
|
+
|
|
208
|
+
`value_at_risk`: Computes normal Value-at-Risk from volatility forecasts.
|
|
209
|
+
|
|
210
|
+
# How It Works
|
|
211
|
+
|
|
212
|
+
GaMM:
|
|
213
|
+
|
|
214
|
+
The model receives a lagged volatility feature tensor with lagged return and standard deviation-based volatility measure.
|
|
215
|
+
|
|
216
|
+
Mixer blocks learn interactions across time steps and variables.
|
|
217
|
+
|
|
218
|
+
The final dense output layer produces the volatility forecast.
|
|
219
|
+
|
|
220
|
+
GARCH-based features:
|
|
221
|
+
|
|
222
|
+
Conditional-volatility estimates are generated from GARCH-family models.
|
|
223
|
+
|
|
224
|
+
These features provide the neural model with econometric volatility information.
|
|
225
|
+
|
|
226
|
+
Risk assessment:
|
|
227
|
+
|
|
228
|
+
Forecasted volatility can be converted into Value-at-Risk estimates.
|
|
229
|
+
|
|
230
|
+
Forecast quality is evaluated using volatility-specific metrics such as QLIKE.
|
|
231
|
+
|
|
232
|
+
# Dataset Details
|
|
233
|
+
|
|
234
|
+
| Component | Description |
|
|
235
|
+
|---|---|
|
|
236
|
+
| Input type | High-frequency financial time-series features |
|
|
237
|
+
| Forecasting target | Volatility / realized volatility |
|
|
238
|
+
| Optional features | GARCH-family conditional volatilities |
|
|
239
|
+
| Model type | GARCH-based MLP Mixer |
|
|
240
|
+
| Split type | Chronological train-validation-test split |
|
|
241
|
+
| Metrics | RMSE, MAE, MAPE, NMAE, QLIKE, VaR |
|
|
242
|
+
|
|
243
|
+
# License
|
|
244
|
+
|
|
245
|
+
This project is licensed under the MIT License. See the LICENSE file for details.
|
|
246
|
+
|
|
247
|
+
# Citation
|
|
248
|
+
|
|
249
|
+
If you are using this package in your research, please cite the following paper:
|
|
250
|
+
|
|
251
|
+
@article{bhambu2025highfrequency,
|
|
252
|
+
title={High frequency volatility forecasting and risk assessment using neural networks-based heteroscedasticity model},
|
|
253
|
+
author={Bhambu, Aryan and Bera, Koushik and Natarajan, Selvaraju and Suganthan, Ponnuthurai Nagaratnam},
|
|
254
|
+
journal={Engineering Applications of Artificial Intelligence},
|
|
255
|
+
volume={149},
|
|
256
|
+
pages={110397},
|
|
257
|
+
year={2025},
|
|
258
|
+
doi={10.1016/j.engappai.2025.110397}
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
# Project description
|
|
2
|
+
|
|
3
|
+
[](https://github.com/statsdl/GaMM)
|
|
4
|
+
[](https://github.com/statsdl/GaMM/commits/main)
|
|
5
|
+
[](https://github.com/statsdl/GaMM/issues)
|
|
6
|
+
[](https://github.com/statsdl/GaMM/stargazers)
|
|
7
|
+
[](https://pypi.org/project/volatility-gamm/)
|
|
8
|
+
[](https://github.com/statsdl/GaMM/blob/main/LICENSE)
|
|
9
|
+
|
|
10
|
+
A rich documentation is available in the GitHub repository.
|
|
11
|
+
|
|
12
|
+
# volatility-gamm
|
|
13
|
+
|
|
14
|
+
GARCH-based MLP Mixer for high-frequency volatility forecasting and risk assessment.
|
|
15
|
+
|
|
16
|
+
volatility-gamm is a Python package for volatility forecasting using GARCH-based MLP Mixer models. The package is designed for high-frequency financial time-series experiments where volatility dynamics, risk estimation, and nonlinear temporal structure are important.
|
|
17
|
+
|
|
18
|
+
The package combines GARCH-family volatility information with MLP-Mixer style neural feature learning. This allows volatility forecasts to benefit from both econometric conditional-volatility modeling and neural nonlinear representation learning.
|
|
19
|
+
|
|
20
|
+
This package provides two primary components:
|
|
21
|
+
|
|
22
|
+
* GARCH-based volatility features: utilities for using GARCH, GJR-GARCH, Threshold GARCH, AVGARCH, and FIGARCH conditional-volatility estimates as model inputs.
|
|
23
|
+
|
|
24
|
+
* GaMM neural model: a configurable MLP-Mixer style architecture for volatility forecasting with normalization, activation, dropout, feed-forward dimension, and mixer-block controls.
|
|
25
|
+
|
|
26
|
+
Both components are useful for volatility forecasting and risk assessment because financial time series often contain volatility clustering, nonlinear temporal dependence, and heavy-tailed risk behavior.
|
|
27
|
+
|
|
28
|
+
# Key Features
|
|
29
|
+
|
|
30
|
+
* GARCH-based MLP Mixer: Combines GARCH-family volatility features with neural MLP-Mixer modeling.
|
|
31
|
+
|
|
32
|
+
* High-Frequency Volatility Forecasting: Designed for intraday financial volatility forecasting tasks.
|
|
33
|
+
|
|
34
|
+
* Econometric Feature Integration: Supports GARCH, GJR-GARCH, Threshold GARCH, AVGARCH, and FIGARCH-style volatility features.
|
|
35
|
+
|
|
36
|
+
* Neural Forecasting Model: Provides Keras-based GaMM model construction and compilation utilities.
|
|
37
|
+
|
|
38
|
+
* Hyperparameter Tuning: Includes Hyperopt/TPE-based tuning helpers for reproducible model selection.
|
|
39
|
+
|
|
40
|
+
* Risk Assessment: Includes Value-at-Risk utilities for volatility-based financial risk evaluation.
|
|
41
|
+
|
|
42
|
+
* Forecasting Metrics: Provides RMSE, MAE, MAPE, NMAE, and QLIKE.
|
|
43
|
+
|
|
44
|
+
* Research-Oriented Design: Suitable for reproducible academic experiments in volatility forecasting and financial risk modeling.
|
|
45
|
+
|
|
46
|
+
# Installation
|
|
47
|
+
|
|
48
|
+
Downloading locally and installing
|
|
49
|
+
|
|
50
|
+
git clone https://github.com/statsdl/GaMM.git
|
|
51
|
+
cd GaMM
|
|
52
|
+
|
|
53
|
+
Install dependencies:
|
|
54
|
+
|
|
55
|
+
pip install -r requirements.txt
|
|
56
|
+
|
|
57
|
+
Install the package:
|
|
58
|
+
|
|
59
|
+
pip install -e .
|
|
60
|
+
|
|
61
|
+
Using pip install from GitHub
|
|
62
|
+
|
|
63
|
+
pip install git+https://github.com/statsdl/GaMM.git
|
|
64
|
+
|
|
65
|
+
Using pip install from PyPI
|
|
66
|
+
|
|
67
|
+
pip install volatility-gamm
|
|
68
|
+
|
|
69
|
+
Optional full installation
|
|
70
|
+
|
|
71
|
+
pip install "volatility-gamm[full]"
|
|
72
|
+
|
|
73
|
+
Development installation
|
|
74
|
+
|
|
75
|
+
pip install -e ".[dev]"
|
|
76
|
+
|
|
77
|
+
# Usage
|
|
78
|
+
|
|
79
|
+
## 1. GaMM model
|
|
80
|
+
|
|
81
|
+
Example
|
|
82
|
+
|
|
83
|
+
import numpy as np
|
|
84
|
+
from gamm.model import compile_gamm_model
|
|
85
|
+
|
|
86
|
+
X_train = np.random.randn(200, 20, 6).astype("float32")
|
|
87
|
+
y_train = np.random.rand(200).astype("float32")
|
|
88
|
+
|
|
89
|
+
model = compile_gamm_model(
|
|
90
|
+
input_shape=(X_train.shape[1], X_train.shape[2]),
|
|
91
|
+
learning_rate=0.001,
|
|
92
|
+
activation="relu",
|
|
93
|
+
n_block=2,
|
|
94
|
+
dropout=0.1,
|
|
95
|
+
ff_dim=64,
|
|
96
|
+
)
|
|
97
|
+
|
|
98
|
+
model.fit(X_train, y_train, epochs=5, batch_size=32, verbose=0)
|
|
99
|
+
|
|
100
|
+
predictions = model.predict(X_train[:10], verbose=0)
|
|
101
|
+
print("Volatility forecasts:", predictions.reshape(-1))
|
|
102
|
+
|
|
103
|
+
## 2. Volatility forecasting metrics
|
|
104
|
+
|
|
105
|
+
Example
|
|
106
|
+
|
|
107
|
+
import numpy as np
|
|
108
|
+
from gamm.metrics import (
|
|
109
|
+
root_mean_squared_error,
|
|
110
|
+
mean_absolute_error,
|
|
111
|
+
mean_absolute_percentage_error,
|
|
112
|
+
normalized_mean_absolute_error,
|
|
113
|
+
quasi_likelihood,
|
|
114
|
+
value_at_risk,
|
|
115
|
+
)
|
|
116
|
+
|
|
117
|
+
y_true = np.array([0.12, 0.15, 0.09, 0.18])
|
|
118
|
+
y_pred = np.array([0.11, 0.14, 0.10, 0.17])
|
|
119
|
+
|
|
120
|
+
print("RMSE:", root_mean_squared_error(y_true, y_pred))
|
|
121
|
+
print("MAE:", mean_absolute_error(y_true, y_pred))
|
|
122
|
+
print("MAPE:", mean_absolute_percentage_error(y_true, y_pred))
|
|
123
|
+
print("NMAE:", normalized_mean_absolute_error(y_true, y_pred))
|
|
124
|
+
print("QLIKE:", quasi_likelihood(y_true, y_pred))
|
|
125
|
+
print("VaR:", value_at_risk(0.05, y_pred))
|
|
126
|
+
|
|
127
|
+
## 3. Synthetic benchmark
|
|
128
|
+
|
|
129
|
+
Example
|
|
130
|
+
|
|
131
|
+
python examples/run_synthetic_benchmark.py
|
|
132
|
+
|
|
133
|
+
The benchmark compares GaMM with GARCH-family volatility estimates and reports volatility forecasting and risk metrics.
|
|
134
|
+
|
|
135
|
+
# API Reference
|
|
136
|
+
|
|
137
|
+
## Model utilities
|
|
138
|
+
|
|
139
|
+
`build_gamm_model`: Builds a GARCH-based MLP Mixer model.
|
|
140
|
+
|
|
141
|
+
`compile_gamm_model`: Builds and compiles the GaMM model with Adam optimizer and MSE loss.
|
|
142
|
+
|
|
143
|
+
## Tuning utilities
|
|
144
|
+
|
|
145
|
+
`gamm_tuning_space`: Returns the default Hyperopt/TPE search space.
|
|
146
|
+
|
|
147
|
+
`tune_gamm`: Tunes GaMM hyperparameters.
|
|
148
|
+
|
|
149
|
+
## GARCH utilities
|
|
150
|
+
|
|
151
|
+
`append_garch_features`: Adds GARCH-family conditional-volatility features when optional dependencies are installed.
|
|
152
|
+
|
|
153
|
+
## Metrics
|
|
154
|
+
|
|
155
|
+
`root_mean_squared_error`: Computes RMSE.
|
|
156
|
+
|
|
157
|
+
`mean_absolute_error`: Computes MAE.
|
|
158
|
+
|
|
159
|
+
`mean_absolute_percentage_error`: Computes MAPE.
|
|
160
|
+
|
|
161
|
+
`normalized_mean_absolute_error`: Computes range-normalized MAE.
|
|
162
|
+
|
|
163
|
+
`quasi_likelihood`: Computes QLIKE.
|
|
164
|
+
|
|
165
|
+
`value_at_risk`: Computes normal Value-at-Risk from volatility forecasts.
|
|
166
|
+
|
|
167
|
+
# How It Works
|
|
168
|
+
|
|
169
|
+
GaMM:
|
|
170
|
+
|
|
171
|
+
The model receives a lagged volatility feature tensor with lagged return and standard deviation-based volatility measure.
|
|
172
|
+
|
|
173
|
+
Mixer blocks learn interactions across time steps and variables.
|
|
174
|
+
|
|
175
|
+
The final dense output layer produces the volatility forecast.
|
|
176
|
+
|
|
177
|
+
GARCH-based features:
|
|
178
|
+
|
|
179
|
+
Conditional-volatility estimates are generated from GARCH-family models.
|
|
180
|
+
|
|
181
|
+
These features provide the neural model with econometric volatility information.
|
|
182
|
+
|
|
183
|
+
Risk assessment:
|
|
184
|
+
|
|
185
|
+
Forecasted volatility can be converted into Value-at-Risk estimates.
|
|
186
|
+
|
|
187
|
+
Forecast quality is evaluated using volatility-specific metrics such as QLIKE.
|
|
188
|
+
|
|
189
|
+
# Dataset Details
|
|
190
|
+
|
|
191
|
+
| Component | Description |
|
|
192
|
+
|---|---|
|
|
193
|
+
| Input type | High-frequency financial time-series features |
|
|
194
|
+
| Forecasting target | Volatility / realized volatility |
|
|
195
|
+
| Optional features | GARCH-family conditional volatilities |
|
|
196
|
+
| Model type | GARCH-based MLP Mixer |
|
|
197
|
+
| Split type | Chronological train-validation-test split |
|
|
198
|
+
| Metrics | RMSE, MAE, MAPE, NMAE, QLIKE, VaR |
|
|
199
|
+
|
|
200
|
+
# License
|
|
201
|
+
|
|
202
|
+
This project is licensed under the MIT License. See the LICENSE file for details.
|
|
203
|
+
|
|
204
|
+
# Citation
|
|
205
|
+
|
|
206
|
+
If you are using this package in your research, please cite the following paper:
|
|
207
|
+
|
|
208
|
+
@article{bhambu2025highfrequency,
|
|
209
|
+
title={High frequency volatility forecasting and risk assessment using neural networks-based heteroscedasticity model},
|
|
210
|
+
author={Bhambu, Aryan and Bera, Koushik and Natarajan, Selvaraju and Suganthan, Ponnuthurai Nagaratnam},
|
|
211
|
+
journal={Engineering Applications of Artificial Intelligence},
|
|
212
|
+
volume={149},
|
|
213
|
+
pages={110397},
|
|
214
|
+
year={2025},
|
|
215
|
+
doi={10.1016/j.engappai.2025.110397}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
|