forecast-realtime 0.5.3__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.
- forecast_realtime-0.5.3/LICENSE +21 -0
- forecast_realtime-0.5.3/PKG-INFO +166 -0
- forecast_realtime-0.5.3/README.md +115 -0
- forecast_realtime-0.5.3/pyproject.toml +131 -0
- forecast_realtime-0.5.3/setup.cfg +4 -0
- forecast_realtime-0.5.3/src/forecast_realtime/__init__.py +40 -0
- forecast_realtime-0.5.3/src/forecast_realtime/_realtime_forecasting.py +30 -0
- forecast_realtime-0.5.3/src/forecast_realtime/_utils.py +504 -0
- forecast_realtime-0.5.3/src/forecast_realtime/data_transformation.py +1255 -0
- forecast_realtime-0.5.3/src/forecast_realtime/external_model.py +679 -0
- forecast_realtime-0.5.3/src/forecast_realtime/forecast_model.py +1643 -0
- forecast_realtime-0.5.3/src/forecast_realtime/forecast_tree.py +870 -0
- forecast_realtime-0.5.3/src/forecast_realtime/formula.py +132 -0
- forecast_realtime-0.5.3/src/forecast_realtime/linear_regression.py +660 -0
- forecast_realtime-0.5.3/src/forecast_realtime/models/__init__.py +86 -0
- forecast_realtime-0.5.3/src/forecast_realtime/models/bridge_ols.py +171 -0
- forecast_realtime-0.5.3/src/forecast_realtime/models/elastic_net.py +121 -0
- forecast_realtime-0.5.3/src/forecast_realtime/models/fable.py +259 -0
- forecast_realtime-0.5.3/src/forecast_realtime/models/forecast_bvar.py +287 -0
- forecast_realtime-0.5.3/src/forecast_realtime/models/lasso.py +116 -0
- forecast_realtime-0.5.3/src/forecast_realtime/models/midas.py +298 -0
- forecast_realtime-0.5.3/src/forecast_realtime/models/midas_combo.py +256 -0
- forecast_realtime-0.5.3/src/forecast_realtime/models/multi_midas.py +303 -0
- forecast_realtime-0.5.3/src/forecast_realtime/models/ols.py +23 -0
- forecast_realtime-0.5.3/src/forecast_realtime/models/r_lm.py +34 -0
- forecast_realtime-0.5.3/src/forecast_realtime/models/r_scripts/fable.r +177 -0
- forecast_realtime-0.5.3/src/forecast_realtime/models/r_scripts/forecast_lm.r +84 -0
- forecast_realtime-0.5.3/src/forecast_realtime/models/random_forest.py +73 -0
- forecast_realtime-0.5.3/src/forecast_realtime/models/ridge.py +138 -0
- forecast_realtime-0.5.3/src/forecast_realtime/models/xg_boost.py +78 -0
- forecast_realtime-0.5.3/src/forecast_realtime/real_time_model.py +1896 -0
- forecast_realtime-0.5.3/src/forecast_realtime/runners/__init__.py +0 -0
- forecast_realtime-0.5.3/src/forecast_realtime/runners/runner.jl +45 -0
- forecast_realtime-0.5.3/src/forecast_realtime/runners/runner.m +53 -0
- forecast_realtime-0.5.3/src/forecast_realtime/runners/runner.r +61 -0
- forecast_realtime-0.5.3/src/forecast_realtime/sample_realtime_data.py +292 -0
- forecast_realtime-0.5.3/src/forecast_realtime/tree_regression.py +356 -0
- forecast_realtime-0.5.3/src/forecast_realtime.egg-info/PKG-INFO +166 -0
- forecast_realtime-0.5.3/src/forecast_realtime.egg-info/SOURCES.txt +55 -0
- forecast_realtime-0.5.3/src/forecast_realtime.egg-info/dependency_links.txt +1 -0
- forecast_realtime-0.5.3/src/forecast_realtime.egg-info/requires.txt +50 -0
- forecast_realtime-0.5.3/src/forecast_realtime.egg-info/top_level.txt +1 -0
- forecast_realtime-0.5.3/tests/test_data_transformation.py +259 -0
- forecast_realtime-0.5.3/tests/test_data_transformation_wide_inputs.py +1115 -0
- forecast_realtime-0.5.3/tests/test_demo_models.py +210 -0
- forecast_realtime-0.5.3/tests/test_external_model.py +403 -0
- forecast_realtime-0.5.3/tests/test_fitted_values_contract.py +40 -0
- forecast_realtime-0.5.3/tests/test_forecast_model_data_transformation.py +1031 -0
- forecast_realtime-0.5.3/tests/test_forecast_model_edge_cases.py +301 -0
- forecast_realtime-0.5.3/tests/test_forecast_tree.py +1675 -0
- forecast_realtime-0.5.3/tests/test_formula.py +274 -0
- forecast_realtime-0.5.3/tests/test_input_metric_selection.py +151 -0
- forecast_realtime-0.5.3/tests/test_lagged_realtime_datasets.py +693 -0
- forecast_realtime-0.5.3/tests/test_model_contract_forwarding.py +56 -0
- forecast_realtime-0.5.3/tests/test_real_time_model.py +4104 -0
- forecast_realtime-0.5.3/tests/test_sample_realtime_data.py +290 -0
- forecast_realtime-0.5.3/tests/test_sample_realtime_model_regressions.py +657 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Bank of England
|
|
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,166 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: forecast_realtime
|
|
3
|
+
Version: 0.5.3
|
|
4
|
+
Summary: A package for producing real-time forecasts
|
|
5
|
+
Author-email: Paul Labonne <paul.labonne@bankofengland.co.uk>, Sumer Singh <sumer.singh@bankofengland.co.uk>, Harry Li <Harry.Li@bankofengland.co.uk>, Nades Raviraj <Nades.Raviraj@bankofengland.co.uk>
|
|
6
|
+
Maintainer-email: Paul Labonne <paul.labonne@bankofengland.co.uk>, Sumer Singh <sumer.singh@bankofengland.co.uk>
|
|
7
|
+
License-Expression: MIT
|
|
8
|
+
Requires-Python: >=3.11
|
|
9
|
+
Description-Content-Type: text/markdown
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Requires-Dist: statsmodels<0.15.0,>=0.14.0
|
|
12
|
+
Requires-Dist: forecast_evaluation>=0.1.13
|
|
13
|
+
Requires-Dist: pandas>=3.0.3
|
|
14
|
+
Requires-Dist: scipy>=1.17.1
|
|
15
|
+
Requires-Dist: tqdm>=4.67.3
|
|
16
|
+
Requires-Dist: numpy>=2.4.5
|
|
17
|
+
Requires-Dist: pyarrow>=24.0.0
|
|
18
|
+
Provides-Extra: dev
|
|
19
|
+
Requires-Dist: pre_commit>=4.6.0; extra == "dev"
|
|
20
|
+
Requires-Dist: pytest>=9.0.3; extra == "dev"
|
|
21
|
+
Requires-Dist: pytest-xdist; extra == "dev"
|
|
22
|
+
Requires-Dist: pydoclint>=0.9.1; extra == "dev"
|
|
23
|
+
Requires-Dist: syrupy>=5.2.0; extra == "dev"
|
|
24
|
+
Requires-Dist: ruff>=0.15.13; extra == "dev"
|
|
25
|
+
Provides-Extra: docs
|
|
26
|
+
Requires-Dist: mkdocstrings[python]; extra == "docs"
|
|
27
|
+
Requires-Dist: zensical; extra == "docs"
|
|
28
|
+
Provides-Extra: notebooks
|
|
29
|
+
Requires-Dist: marimo==0.24.0; extra == "notebooks"
|
|
30
|
+
Requires-Dist: news_decomp>=0.0.7; extra == "notebooks"
|
|
31
|
+
Provides-Extra: models
|
|
32
|
+
Requires-Dist: bvar>=0.3.1; extra == "models"
|
|
33
|
+
Requires-Dist: nowcast-midas>=0.0.1; extra == "models"
|
|
34
|
+
Requires-Dist: scikit-learn>=1.8.0; extra == "models"
|
|
35
|
+
Requires-Dist: xgboost>=3.2.0; extra == "models"
|
|
36
|
+
Provides-Extra: ridge
|
|
37
|
+
Requires-Dist: scikit-learn>=1.8.0; extra == "ridge"
|
|
38
|
+
Provides-Extra: lasso
|
|
39
|
+
Requires-Dist: scikit-learn>=1.8.0; extra == "lasso"
|
|
40
|
+
Provides-Extra: elasticnet
|
|
41
|
+
Requires-Dist: scikit-learn>=1.8.0; extra == "elasticnet"
|
|
42
|
+
Provides-Extra: random-forest
|
|
43
|
+
Requires-Dist: scikit-learn>=1.8.0; extra == "random-forest"
|
|
44
|
+
Provides-Extra: xgboost
|
|
45
|
+
Requires-Dist: xgboost>=3.2.0; extra == "xgboost"
|
|
46
|
+
Provides-Extra: bvar
|
|
47
|
+
Requires-Dist: bvar>=0.3.1; extra == "bvar"
|
|
48
|
+
Provides-Extra: nowcast-midas
|
|
49
|
+
Requires-Dist: nowcast-midas>=0.0.1; extra == "nowcast-midas"
|
|
50
|
+
Dynamic: license-file
|
|
51
|
+
|
|
52
|
+
# Real-time Forecast Package
|
|
53
|
+
|
|
54
|
+
A Python package for real-time orchestration of forecasting models.
|
|
55
|
+
|
|
56
|
+
The main object, **RealTimeModel**, combines a **ForecastData** object (from the
|
|
57
|
+
`forecast_evaluation` package) with one or more **ForecastModel** objects.
|
|
58
|
+
`ForecastModel` is an abstract base class with
|
|
59
|
+
`_fit()`, `_forecast()` and an optional `_forecast_decomp()` method. All
|
|
60
|
+
built-in models inherit from it, and you can subclass it to wrap any Python (or
|
|
61
|
+
R, MATLAB, or Julia) forecasting model.
|
|
62
|
+
|
|
63
|
+
## Installation
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
pip install forecast_realtime[models]
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## Quick demo
|
|
70
|
+
|
|
71
|
+
```python
|
|
72
|
+
import forecast_evaluation as fe
|
|
73
|
+
import forecast_realtime as rt
|
|
74
|
+
|
|
75
|
+
forecast_data = fe.ForecastData(load_fer=True)
|
|
76
|
+
|
|
77
|
+
ridge = rt.models.ForecastRidge(label="Ridge", cv=5, scale=True)
|
|
78
|
+
lasso = rt.models.ForecastLasso(label="LASSO", cv=5, scale=True)
|
|
79
|
+
|
|
80
|
+
rt_model = rt.RealTimeModel(
|
|
81
|
+
data=forecast_data,
|
|
82
|
+
models=[ridge, lasso],
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
rt_model.forecast(
|
|
86
|
+
y_variables=["cpisa"],
|
|
87
|
+
X_variables=["gdpkp"],
|
|
88
|
+
data_transformation={"cpisa": "pop", "gdpkp": "pop"},
|
|
89
|
+
steps=12,
|
|
90
|
+
y_lags=4,
|
|
91
|
+
X_imputation="last",
|
|
92
|
+
)
|
|
93
|
+
|
|
94
|
+
# Optional interactive dashboard:
|
|
95
|
+
# rt_model.data.run_dashboard()
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### Marimo notebook
|
|
99
|
+
|
|
100
|
+
Install the notebook and model dependencies from the repository root:
|
|
101
|
+
|
|
102
|
+
```bash
|
|
103
|
+
pip install -e ".[models,notebooks]"
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
Open the demo as an editable notebook with visible code cells and outputs:
|
|
107
|
+
|
|
108
|
+
```bash
|
|
109
|
+
marimo edit notebooks/demo_models.py
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
## Add your own model
|
|
113
|
+
|
|
114
|
+
Subclass `ForecastModel` and implement `_fit()` and `_forecast()` (plus
|
|
115
|
+
`_forecast_decomp()` if you want news decompositions). `y` and `X` arrive as
|
|
116
|
+
pandas DataFrames, and the base class handles validation, lags, dummies and
|
|
117
|
+
forecast dates.
|
|
118
|
+
|
|
119
|
+
```python
|
|
120
|
+
import numpy as np
|
|
121
|
+
import pandas as pd
|
|
122
|
+
|
|
123
|
+
from forecast_realtime import ForecastModel
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
class MyOLS(ForecastModel):
|
|
127
|
+
"""Small OLS model showing the custom-model authoring pattern."""
|
|
128
|
+
|
|
129
|
+
def _fit(self, y, X=None, **kwargs):
|
|
130
|
+
# y and X are passed as pandas DataFrames
|
|
131
|
+
if X is None:
|
|
132
|
+
raise ValueError("MyOLS requires X")
|
|
133
|
+
X = X.to_numpy(dtype=float)
|
|
134
|
+
y = y.to_numpy(dtype=float)
|
|
135
|
+
|
|
136
|
+
# OLS estimate: beta = (X'X)^-1 X'y
|
|
137
|
+
self.beta = np.linalg.inv(X.T @ X) @ X.T @ y
|
|
138
|
+
|
|
139
|
+
return self
|
|
140
|
+
|
|
141
|
+
def _forecast(self, steps, X=None, y=None, **kwargs):
|
|
142
|
+
if X is None:
|
|
143
|
+
raise ValueError("MyOLS requires future X")
|
|
144
|
+
# ForecastModel passes the historical and future design rows.
|
|
145
|
+
future_X = X.loc[X.index > self.last_y_fit_date].iloc[:steps]
|
|
146
|
+
return future_X.to_numpy(dtype=float) @ self.beta
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
Pass it straight to `RealTimeModel`:
|
|
150
|
+
|
|
151
|
+
```python
|
|
152
|
+
rt_model = rt.RealTimeModel(data=forecast_data, models=[MyOLS()])
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
## Documentation
|
|
156
|
+
|
|
157
|
+
- [docs/index.md](docs/index.md) — how `ForecastModel` and `RealTimeModel` work.
|
|
158
|
+
- [docs/models.md](docs/models.md) — built-in models and R/MATLAB/Julia wrappers.
|
|
159
|
+
- [docs/usage.md](docs/usage.md) — lags, dummies, imputation, transformations,
|
|
160
|
+
news decomposition and parallel execution.
|
|
161
|
+
- [adding_a_model.md](docs/adding_a_model.md) — the full `ForecastModel` interface.
|
|
162
|
+
- [forecasting_strategy.md](docs/forecasting_strategy.md) — forecasting methodology.
|
|
163
|
+
- [CONTRIBUTING.md](CONTRIBUTING.md) — development setup and workflow.
|
|
164
|
+
|
|
165
|
+
## Data Classification
|
|
166
|
+
Bank of England Data Classification: OFFICIAL BLUE
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
# Real-time Forecast Package
|
|
2
|
+
|
|
3
|
+
A Python package for real-time orchestration of forecasting models.
|
|
4
|
+
|
|
5
|
+
The main object, **RealTimeModel**, combines a **ForecastData** object (from the
|
|
6
|
+
`forecast_evaluation` package) with one or more **ForecastModel** objects.
|
|
7
|
+
`ForecastModel` is an abstract base class with
|
|
8
|
+
`_fit()`, `_forecast()` and an optional `_forecast_decomp()` method. All
|
|
9
|
+
built-in models inherit from it, and you can subclass it to wrap any Python (or
|
|
10
|
+
R, MATLAB, or Julia) forecasting model.
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
pip install forecast_realtime[models]
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Quick demo
|
|
19
|
+
|
|
20
|
+
```python
|
|
21
|
+
import forecast_evaluation as fe
|
|
22
|
+
import forecast_realtime as rt
|
|
23
|
+
|
|
24
|
+
forecast_data = fe.ForecastData(load_fer=True)
|
|
25
|
+
|
|
26
|
+
ridge = rt.models.ForecastRidge(label="Ridge", cv=5, scale=True)
|
|
27
|
+
lasso = rt.models.ForecastLasso(label="LASSO", cv=5, scale=True)
|
|
28
|
+
|
|
29
|
+
rt_model = rt.RealTimeModel(
|
|
30
|
+
data=forecast_data,
|
|
31
|
+
models=[ridge, lasso],
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
rt_model.forecast(
|
|
35
|
+
y_variables=["cpisa"],
|
|
36
|
+
X_variables=["gdpkp"],
|
|
37
|
+
data_transformation={"cpisa": "pop", "gdpkp": "pop"},
|
|
38
|
+
steps=12,
|
|
39
|
+
y_lags=4,
|
|
40
|
+
X_imputation="last",
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
# Optional interactive dashboard:
|
|
44
|
+
# rt_model.data.run_dashboard()
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### Marimo notebook
|
|
48
|
+
|
|
49
|
+
Install the notebook and model dependencies from the repository root:
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
pip install -e ".[models,notebooks]"
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Open the demo as an editable notebook with visible code cells and outputs:
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
marimo edit notebooks/demo_models.py
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Add your own model
|
|
62
|
+
|
|
63
|
+
Subclass `ForecastModel` and implement `_fit()` and `_forecast()` (plus
|
|
64
|
+
`_forecast_decomp()` if you want news decompositions). `y` and `X` arrive as
|
|
65
|
+
pandas DataFrames, and the base class handles validation, lags, dummies and
|
|
66
|
+
forecast dates.
|
|
67
|
+
|
|
68
|
+
```python
|
|
69
|
+
import numpy as np
|
|
70
|
+
import pandas as pd
|
|
71
|
+
|
|
72
|
+
from forecast_realtime import ForecastModel
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
class MyOLS(ForecastModel):
|
|
76
|
+
"""Small OLS model showing the custom-model authoring pattern."""
|
|
77
|
+
|
|
78
|
+
def _fit(self, y, X=None, **kwargs):
|
|
79
|
+
# y and X are passed as pandas DataFrames
|
|
80
|
+
if X is None:
|
|
81
|
+
raise ValueError("MyOLS requires X")
|
|
82
|
+
X = X.to_numpy(dtype=float)
|
|
83
|
+
y = y.to_numpy(dtype=float)
|
|
84
|
+
|
|
85
|
+
# OLS estimate: beta = (X'X)^-1 X'y
|
|
86
|
+
self.beta = np.linalg.inv(X.T @ X) @ X.T @ y
|
|
87
|
+
|
|
88
|
+
return self
|
|
89
|
+
|
|
90
|
+
def _forecast(self, steps, X=None, y=None, **kwargs):
|
|
91
|
+
if X is None:
|
|
92
|
+
raise ValueError("MyOLS requires future X")
|
|
93
|
+
# ForecastModel passes the historical and future design rows.
|
|
94
|
+
future_X = X.loc[X.index > self.last_y_fit_date].iloc[:steps]
|
|
95
|
+
return future_X.to_numpy(dtype=float) @ self.beta
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
Pass it straight to `RealTimeModel`:
|
|
99
|
+
|
|
100
|
+
```python
|
|
101
|
+
rt_model = rt.RealTimeModel(data=forecast_data, models=[MyOLS()])
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
## Documentation
|
|
105
|
+
|
|
106
|
+
- [docs/index.md](docs/index.md) — how `ForecastModel` and `RealTimeModel` work.
|
|
107
|
+
- [docs/models.md](docs/models.md) — built-in models and R/MATLAB/Julia wrappers.
|
|
108
|
+
- [docs/usage.md](docs/usage.md) — lags, dummies, imputation, transformations,
|
|
109
|
+
news decomposition and parallel execution.
|
|
110
|
+
- [adding_a_model.md](docs/adding_a_model.md) — the full `ForecastModel` interface.
|
|
111
|
+
- [forecasting_strategy.md](docs/forecasting_strategy.md) — forecasting methodology.
|
|
112
|
+
- [CONTRIBUTING.md](CONTRIBUTING.md) — development setup and workflow.
|
|
113
|
+
|
|
114
|
+
## Data Classification
|
|
115
|
+
Bank of England Data Classification: OFFICIAL BLUE
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "forecast_realtime"
|
|
3
|
+
version = "0.5.3"
|
|
4
|
+
|
|
5
|
+
description = "A package for producing real-time forecasts"
|
|
6
|
+
|
|
7
|
+
authors = [
|
|
8
|
+
{name="Paul Labonne", email="paul.labonne@bankofengland.co.uk"},
|
|
9
|
+
{name="Sumer Singh", email = "sumer.singh@bankofengland.co.uk"},
|
|
10
|
+
{name="Harry Li", email = "Harry.Li@bankofengland.co.uk"},
|
|
11
|
+
{name="Nades Raviraj", email = "Nades.Raviraj@bankofengland.co.uk"},
|
|
12
|
+
]
|
|
13
|
+
|
|
14
|
+
maintainers = [
|
|
15
|
+
{name="Paul Labonne", email="paul.labonne@bankofengland.co.uk"},
|
|
16
|
+
{name="Sumer Singh", email = "sumer.singh@bankofengland.co.uk"},
|
|
17
|
+
]
|
|
18
|
+
|
|
19
|
+
license = "MIT"
|
|
20
|
+
|
|
21
|
+
readme = "README.md"
|
|
22
|
+
|
|
23
|
+
requires-python = ">=3.11"
|
|
24
|
+
|
|
25
|
+
dependencies = [
|
|
26
|
+
# forecast-evaluation depends on a compatible statsmodels version.
|
|
27
|
+
# Remove this constraint when forecast-evaluation resolves the compatibility issue.
|
|
28
|
+
"statsmodels>=0.14.0,<0.15.0",
|
|
29
|
+
"forecast_evaluation>=0.1.13",
|
|
30
|
+
"pandas >= 3.0.3",
|
|
31
|
+
"scipy >= 1.17.1",
|
|
32
|
+
"tqdm >= 4.67.3",
|
|
33
|
+
"numpy >= 2.4.5",
|
|
34
|
+
"pyarrow >= 24.0.0", # Required by external model wrappers.
|
|
35
|
+
]
|
|
36
|
+
|
|
37
|
+
[project.optional-dependencies]
|
|
38
|
+
dev = [
|
|
39
|
+
"pre_commit >= 4.6.0",
|
|
40
|
+
"pytest >= 9.0.3",
|
|
41
|
+
"pytest-xdist", # Enables parallel test runs with pytest -n auto.
|
|
42
|
+
"pydoclint >= 0.9.1",
|
|
43
|
+
"syrupy >= 5.2.0",
|
|
44
|
+
"ruff >= 0.15.13",
|
|
45
|
+
]
|
|
46
|
+
|
|
47
|
+
docs = [
|
|
48
|
+
"mkdocstrings[python]",
|
|
49
|
+
"zensical",
|
|
50
|
+
]
|
|
51
|
+
|
|
52
|
+
notebooks = [
|
|
53
|
+
"marimo==0.24.0",
|
|
54
|
+
"news_decomp>=0.0.7",
|
|
55
|
+
]
|
|
56
|
+
|
|
57
|
+
models = [
|
|
58
|
+
"bvar >= 0.3.1",
|
|
59
|
+
"nowcast-midas >= 0.0.1",
|
|
60
|
+
"scikit-learn >= 1.8.0",
|
|
61
|
+
"xgboost >= 3.2.0",
|
|
62
|
+
]
|
|
63
|
+
|
|
64
|
+
ridge = ["scikit-learn >= 1.8.0"]
|
|
65
|
+
lasso = ["scikit-learn >= 1.8.0"]
|
|
66
|
+
elasticnet = ["scikit-learn >= 1.8.0"]
|
|
67
|
+
random_forest = ["scikit-learn >= 1.8.0"]
|
|
68
|
+
xgboost = ["xgboost >= 3.2.0"]
|
|
69
|
+
bvar = ["bvar >= 0.3.1"]
|
|
70
|
+
nowcast_midas = ["nowcast-midas>=0.0.1"]
|
|
71
|
+
|
|
72
|
+
[build-system]
|
|
73
|
+
requires = ["setuptools"]
|
|
74
|
+
build-backend = "setuptools.build_meta"
|
|
75
|
+
|
|
76
|
+
[tool.setuptools.package-data]
|
|
77
|
+
forecast_realtime = [
|
|
78
|
+
"runners/*.r",
|
|
79
|
+
"runners/*.m",
|
|
80
|
+
"runners/*.jl",
|
|
81
|
+
"models/r_scripts/*.r",
|
|
82
|
+
]
|
|
83
|
+
|
|
84
|
+
[tool.ruff]
|
|
85
|
+
line-length = 90
|
|
86
|
+
target-version = "py311"
|
|
87
|
+
|
|
88
|
+
[tool.ruff.lint]
|
|
89
|
+
# Enable specific rules
|
|
90
|
+
select = [
|
|
91
|
+
"E", # pycodestyle
|
|
92
|
+
"F", # pyflakes
|
|
93
|
+
"I", # isort
|
|
94
|
+
"UP", # pyupgrade
|
|
95
|
+
]
|
|
96
|
+
|
|
97
|
+
# Ignore specific rules
|
|
98
|
+
ignore = [
|
|
99
|
+
"D100", # Missing docstring in public module
|
|
100
|
+
"D104", # Missing docstring in public package,
|
|
101
|
+
"D213",
|
|
102
|
+
"D211"
|
|
103
|
+
]
|
|
104
|
+
|
|
105
|
+
# Exclude files and directories
|
|
106
|
+
exclude = [
|
|
107
|
+
".git",
|
|
108
|
+
".ruff_cache",
|
|
109
|
+
"__pycache__",
|
|
110
|
+
"build",
|
|
111
|
+
"dist",
|
|
112
|
+
"*.png",
|
|
113
|
+
"examples/**",
|
|
114
|
+
]
|
|
115
|
+
|
|
116
|
+
[tool.ruff.lint.per-file-ignores]
|
|
117
|
+
"__init__.py" = ["F401"] # Ignore unused imports in __init__.py files
|
|
118
|
+
|
|
119
|
+
[tool.pydoclint]
|
|
120
|
+
style = "numpy"
|
|
121
|
+
arg-type-hints-in-signature = true
|
|
122
|
+
arg-type-hints-in-docstring = true
|
|
123
|
+
skip-checking-short-docstrings = true
|
|
124
|
+
skip-checking-private-functions = true
|
|
125
|
+
skip-checking-raises = true
|
|
126
|
+
allow-init-docstring = true
|
|
127
|
+
check-class-attributes = false
|
|
128
|
+
should-document-star-arguments = false
|
|
129
|
+
|
|
130
|
+
[tool.pytest.ini_options]
|
|
131
|
+
testpaths = ["tests"]
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
from .data_transformation import (
|
|
2
|
+
InputMetricMapping,
|
|
3
|
+
ModelInputRequirements,
|
|
4
|
+
PreparedModelInputs,
|
|
5
|
+
RawInputBundle,
|
|
6
|
+
ResolvedTransformationPlan,
|
|
7
|
+
)
|
|
8
|
+
from .external_model import ExternalModel, JuliaModel, MATLABModel, RModel
|
|
9
|
+
from .forecast_model import ForecastContext, ForecastModel, ForecastResult
|
|
10
|
+
from .forecast_tree import ForecastTree, TreeNode
|
|
11
|
+
from .formula import Formula
|
|
12
|
+
from .real_time_model import RealTimeModel
|
|
13
|
+
from .sample_realtime_data import generate_synthetic_data
|
|
14
|
+
|
|
15
|
+
# Optional import - only load models if available
|
|
16
|
+
try:
|
|
17
|
+
from . import models
|
|
18
|
+
except ImportError:
|
|
19
|
+
models = None
|
|
20
|
+
|
|
21
|
+
__all__ = [
|
|
22
|
+
"RealTimeModel",
|
|
23
|
+
"ForecastModel",
|
|
24
|
+
"ForecastContext",
|
|
25
|
+
"ForecastResult",
|
|
26
|
+
"ForecastTree",
|
|
27
|
+
"TreeNode",
|
|
28
|
+
"ExternalModel",
|
|
29
|
+
"Formula",
|
|
30
|
+
"RModel",
|
|
31
|
+
"MATLABModel",
|
|
32
|
+
"JuliaModel",
|
|
33
|
+
"generate_synthetic_data",
|
|
34
|
+
"ModelInputRequirements",
|
|
35
|
+
"InputMetricMapping",
|
|
36
|
+
"ResolvedTransformationPlan",
|
|
37
|
+
"RawInputBundle",
|
|
38
|
+
"PreparedModelInputs",
|
|
39
|
+
"models",
|
|
40
|
+
]
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"""Private containers for realtime forecast execution."""
|
|
2
|
+
|
|
3
|
+
from dataclasses import dataclass
|
|
4
|
+
|
|
5
|
+
import numpy as np
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
@dataclass(frozen=True)
|
|
9
|
+
class ForecastTask:
|
|
10
|
+
"""Pickleable work item submitted to a realtime forecast worker."""
|
|
11
|
+
|
|
12
|
+
model: object
|
|
13
|
+
data_transformation: object
|
|
14
|
+
vintages: np.ndarray
|
|
15
|
+
common: dict
|
|
16
|
+
input_metrics: dict[str, str] = None
|
|
17
|
+
y_input_metrics: dict[str, str] = None
|
|
18
|
+
X_input_metrics: dict[str, str] = None
|
|
19
|
+
y_conditioning_input_metrics: dict[str, str] = None
|
|
20
|
+
X_conditioning_input_metrics: dict[str, str] = None
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
@dataclass(frozen=True)
|
|
24
|
+
class ForecastRunResult:
|
|
25
|
+
"""Completed worker outputs before aggregation and storage."""
|
|
26
|
+
|
|
27
|
+
forecasts: object
|
|
28
|
+
decompositions: object
|
|
29
|
+
all_vintages_skipped: bool
|
|
30
|
+
native_forecasts: object = None
|