macrofit 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.
- macrofit-0.1.0/LICENSE +21 -0
- macrofit-0.1.0/PKG-INFO +80 -0
- macrofit-0.1.0/README.md +54 -0
- macrofit-0.1.0/macrofit/__init__.py +3 -0
- macrofit-0.1.0/macrofit/search.py +34 -0
- macrofit-0.1.0/macrofit.egg-info/PKG-INFO +80 -0
- macrofit-0.1.0/macrofit.egg-info/SOURCES.txt +11 -0
- macrofit-0.1.0/macrofit.egg-info/dependency_links.txt +1 -0
- macrofit-0.1.0/macrofit.egg-info/requires.txt +3 -0
- macrofit-0.1.0/macrofit.egg-info/top_level.txt +1 -0
- macrofit-0.1.0/setup.cfg +4 -0
- macrofit-0.1.0/setup.py +26 -0
- macrofit-0.1.0/tests/test_search.py +22 -0
macrofit-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Sahil Raaj Kapur
|
|
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.
|
macrofit-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: macrofit
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Search for significant ARIMA models on a time series
|
|
5
|
+
Home-page: https://github.com/srkapur/macrofit
|
|
6
|
+
Author: Sahil Raaj Kapur
|
|
7
|
+
License: MIT
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: Topic :: Scientific/Engineering :: Mathematics
|
|
10
|
+
Requires-Python: >=3.10
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
Requires-Dist: statsmodels>=0.14.0
|
|
14
|
+
Requires-Dist: pandas>=1.5.0
|
|
15
|
+
Requires-Dist: numpy>=1.23.0
|
|
16
|
+
Dynamic: author
|
|
17
|
+
Dynamic: classifier
|
|
18
|
+
Dynamic: description
|
|
19
|
+
Dynamic: description-content-type
|
|
20
|
+
Dynamic: home-page
|
|
21
|
+
Dynamic: license
|
|
22
|
+
Dynamic: license-file
|
|
23
|
+
Dynamic: requires-dist
|
|
24
|
+
Dynamic: requires-python
|
|
25
|
+
Dynamic: summary
|
|
26
|
+
|
|
27
|
+
# macrofit
|
|
28
|
+
|
|
29
|
+
Find which ARIMA models are significant on a time series.
|
|
30
|
+
|
|
31
|
+
## The problem
|
|
32
|
+
|
|
33
|
+
Choosing (p, q) for an ARIMA by hand means fitting many models and
|
|
34
|
+
checking every coefficient. macrofit does this in one call.
|
|
35
|
+
|
|
36
|
+
## Install
|
|
37
|
+
|
|
38
|
+
pip install -e .
|
|
39
|
+
|
|
40
|
+
## Usage
|
|
41
|
+
|
|
42
|
+
from macrofit import search_arima
|
|
43
|
+
|
|
44
|
+
results = search_arima(series, d=0, alpha=0.05, max_p=3, max_q=3)
|
|
45
|
+
print(results)
|
|
46
|
+
|
|
47
|
+
Example output:
|
|
48
|
+
|
|
49
|
+
p q aic
|
|
50
|
+
0 0 1 529.453252
|
|
51
|
+
1 2 1 532.035018
|
|
52
|
+
2 2 0 532.299916
|
|
53
|
+
3 1 0 534.245774
|
|
54
|
+
|
|
55
|
+
## How it works
|
|
56
|
+
|
|
57
|
+
1. Tries every (p, q) up to `max_p` and `max_q`, with `d` fixed by you.
|
|
58
|
+
2. Keeps only models where every AR and MA coefficient is significant.
|
|
59
|
+
The intercept and the noise variance are ignored.
|
|
60
|
+
3. Returns them sorted by AIC, lowest first.
|
|
61
|
+
|
|
62
|
+
## Notes
|
|
63
|
+
|
|
64
|
+
- You choose `d`, the number of times the series is differenced.
|
|
65
|
+
Either pass raw data and set `d` (for example `d=1`), or difference
|
|
66
|
+
it yourself and keep `d=0`. Don't do both.
|
|
67
|
+
- A model that passes the filter and ranks first fits this sample best.
|
|
68
|
+
It is not guaranteed to be the "true" model.
|
|
69
|
+
- If nothing passes, you get a warning and an empty table. Try a higher
|
|
70
|
+
alpha or larger `max_p` / `max_q`.
|
|
71
|
+
- Models that fail to converge are skipped.
|
|
72
|
+
|
|
73
|
+
## Roadmap
|
|
74
|
+
|
|
75
|
+
- VAR variable-combination search
|
|
76
|
+
- VECM, ECM, ARIMAX
|
|
77
|
+
|
|
78
|
+
## License
|
|
79
|
+
|
|
80
|
+
MIT
|
macrofit-0.1.0/README.md
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# macrofit
|
|
2
|
+
|
|
3
|
+
Find which ARIMA models are significant on a time series.
|
|
4
|
+
|
|
5
|
+
## The problem
|
|
6
|
+
|
|
7
|
+
Choosing (p, q) for an ARIMA by hand means fitting many models and
|
|
8
|
+
checking every coefficient. macrofit does this in one call.
|
|
9
|
+
|
|
10
|
+
## Install
|
|
11
|
+
|
|
12
|
+
pip install -e .
|
|
13
|
+
|
|
14
|
+
## Usage
|
|
15
|
+
|
|
16
|
+
from macrofit import search_arima
|
|
17
|
+
|
|
18
|
+
results = search_arima(series, d=0, alpha=0.05, max_p=3, max_q=3)
|
|
19
|
+
print(results)
|
|
20
|
+
|
|
21
|
+
Example output:
|
|
22
|
+
|
|
23
|
+
p q aic
|
|
24
|
+
0 0 1 529.453252
|
|
25
|
+
1 2 1 532.035018
|
|
26
|
+
2 2 0 532.299916
|
|
27
|
+
3 1 0 534.245774
|
|
28
|
+
|
|
29
|
+
## How it works
|
|
30
|
+
|
|
31
|
+
1. Tries every (p, q) up to `max_p` and `max_q`, with `d` fixed by you.
|
|
32
|
+
2. Keeps only models where every AR and MA coefficient is significant.
|
|
33
|
+
The intercept and the noise variance are ignored.
|
|
34
|
+
3. Returns them sorted by AIC, lowest first.
|
|
35
|
+
|
|
36
|
+
## Notes
|
|
37
|
+
|
|
38
|
+
- You choose `d`, the number of times the series is differenced.
|
|
39
|
+
Either pass raw data and set `d` (for example `d=1`), or difference
|
|
40
|
+
it yourself and keep `d=0`. Don't do both.
|
|
41
|
+
- A model that passes the filter and ranks first fits this sample best.
|
|
42
|
+
It is not guaranteed to be the "true" model.
|
|
43
|
+
- If nothing passes, you get a warning and an empty table. Try a higher
|
|
44
|
+
alpha or larger `max_p` / `max_q`.
|
|
45
|
+
- Models that fail to converge are skipped.
|
|
46
|
+
|
|
47
|
+
## Roadmap
|
|
48
|
+
|
|
49
|
+
- VAR variable-combination search
|
|
50
|
+
- VECM, ECM, ARIMAX
|
|
51
|
+
|
|
52
|
+
## License
|
|
53
|
+
|
|
54
|
+
MIT
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import warnings
|
|
2
|
+
import pandas as pd
|
|
3
|
+
from statsmodels.tsa.arima.model import ARIMA
|
|
4
|
+
from statsmodels.tools.sm_exceptions import ConvergenceWarning
|
|
5
|
+
|
|
6
|
+
def search_arima(series, d=0, alpha=0.05, max_p=3, max_q=3):
|
|
7
|
+
rows = []
|
|
8
|
+
for p_order in range(0, max_p + 1):
|
|
9
|
+
for q_order in range(0, max_q + 1):
|
|
10
|
+
if p_order == 0 and q_order == 0:
|
|
11
|
+
continue
|
|
12
|
+
try:
|
|
13
|
+
with warnings.catch_warnings(record=True) as caught:
|
|
14
|
+
warnings.simplefilter("always")
|
|
15
|
+
r = ARIMA(series, order=(p_order, d, q_order)).fit()
|
|
16
|
+
except Exception:
|
|
17
|
+
continue
|
|
18
|
+
|
|
19
|
+
if any(issubclass(w.category, ConvergenceWarning) for w in caught):
|
|
20
|
+
continue
|
|
21
|
+
|
|
22
|
+
pv = r.pvalues.drop("sigma2")
|
|
23
|
+
pv = pv[pv.index.str.startswith(("ar.", "ma."))]
|
|
24
|
+
if (pv < alpha).all():
|
|
25
|
+
rows.append({"p": p_order, "q": q_order, "aic": r.aic})
|
|
26
|
+
|
|
27
|
+
if not rows:
|
|
28
|
+
warnings.warn(
|
|
29
|
+
f"No model found at alpha={alpha} with max_p={max_p}, max_q={max_q}. "
|
|
30
|
+
"Try a higher alpha or a larger max_p / max_q."
|
|
31
|
+
)
|
|
32
|
+
return pd.DataFrame(columns=["p", "q", "aic"])
|
|
33
|
+
|
|
34
|
+
return pd.DataFrame(rows).sort_values("aic").reset_index(drop=True)
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: macrofit
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Search for significant ARIMA models on a time series
|
|
5
|
+
Home-page: https://github.com/srkapur/macrofit
|
|
6
|
+
Author: Sahil Raaj Kapur
|
|
7
|
+
License: MIT
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: Topic :: Scientific/Engineering :: Mathematics
|
|
10
|
+
Requires-Python: >=3.10
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
Requires-Dist: statsmodels>=0.14.0
|
|
14
|
+
Requires-Dist: pandas>=1.5.0
|
|
15
|
+
Requires-Dist: numpy>=1.23.0
|
|
16
|
+
Dynamic: author
|
|
17
|
+
Dynamic: classifier
|
|
18
|
+
Dynamic: description
|
|
19
|
+
Dynamic: description-content-type
|
|
20
|
+
Dynamic: home-page
|
|
21
|
+
Dynamic: license
|
|
22
|
+
Dynamic: license-file
|
|
23
|
+
Dynamic: requires-dist
|
|
24
|
+
Dynamic: requires-python
|
|
25
|
+
Dynamic: summary
|
|
26
|
+
|
|
27
|
+
# macrofit
|
|
28
|
+
|
|
29
|
+
Find which ARIMA models are significant on a time series.
|
|
30
|
+
|
|
31
|
+
## The problem
|
|
32
|
+
|
|
33
|
+
Choosing (p, q) for an ARIMA by hand means fitting many models and
|
|
34
|
+
checking every coefficient. macrofit does this in one call.
|
|
35
|
+
|
|
36
|
+
## Install
|
|
37
|
+
|
|
38
|
+
pip install -e .
|
|
39
|
+
|
|
40
|
+
## Usage
|
|
41
|
+
|
|
42
|
+
from macrofit import search_arima
|
|
43
|
+
|
|
44
|
+
results = search_arima(series, d=0, alpha=0.05, max_p=3, max_q=3)
|
|
45
|
+
print(results)
|
|
46
|
+
|
|
47
|
+
Example output:
|
|
48
|
+
|
|
49
|
+
p q aic
|
|
50
|
+
0 0 1 529.453252
|
|
51
|
+
1 2 1 532.035018
|
|
52
|
+
2 2 0 532.299916
|
|
53
|
+
3 1 0 534.245774
|
|
54
|
+
|
|
55
|
+
## How it works
|
|
56
|
+
|
|
57
|
+
1. Tries every (p, q) up to `max_p` and `max_q`, with `d` fixed by you.
|
|
58
|
+
2. Keeps only models where every AR and MA coefficient is significant.
|
|
59
|
+
The intercept and the noise variance are ignored.
|
|
60
|
+
3. Returns them sorted by AIC, lowest first.
|
|
61
|
+
|
|
62
|
+
## Notes
|
|
63
|
+
|
|
64
|
+
- You choose `d`, the number of times the series is differenced.
|
|
65
|
+
Either pass raw data and set `d` (for example `d=1`), or difference
|
|
66
|
+
it yourself and keep `d=0`. Don't do both.
|
|
67
|
+
- A model that passes the filter and ranks first fits this sample best.
|
|
68
|
+
It is not guaranteed to be the "true" model.
|
|
69
|
+
- If nothing passes, you get a warning and an empty table. Try a higher
|
|
70
|
+
alpha or larger `max_p` / `max_q`.
|
|
71
|
+
- Models that fail to converge are skipped.
|
|
72
|
+
|
|
73
|
+
## Roadmap
|
|
74
|
+
|
|
75
|
+
- VAR variable-combination search
|
|
76
|
+
- VECM, ECM, ARIMAX
|
|
77
|
+
|
|
78
|
+
## License
|
|
79
|
+
|
|
80
|
+
MIT
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
setup.py
|
|
4
|
+
macrofit/__init__.py
|
|
5
|
+
macrofit/search.py
|
|
6
|
+
macrofit.egg-info/PKG-INFO
|
|
7
|
+
macrofit.egg-info/SOURCES.txt
|
|
8
|
+
macrofit.egg-info/dependency_links.txt
|
|
9
|
+
macrofit.egg-info/requires.txt
|
|
10
|
+
macrofit.egg-info/top_level.txt
|
|
11
|
+
tests/test_search.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
macrofit
|
macrofit-0.1.0/setup.cfg
ADDED
macrofit-0.1.0/setup.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
from pathlib import Path
|
|
2
|
+
from setuptools import setup, find_packages
|
|
3
|
+
|
|
4
|
+
long_description = Path("README.md").read_text(encoding="utf-8")
|
|
5
|
+
|
|
6
|
+
setup(
|
|
7
|
+
name="macrofit",
|
|
8
|
+
version="0.1.0",
|
|
9
|
+
author="Sahil Raaj Kapur",
|
|
10
|
+
description="Search for significant ARIMA models on a time series",
|
|
11
|
+
long_description=long_description,
|
|
12
|
+
long_description_content_type="text/markdown",
|
|
13
|
+
url="https://github.com/srkapur/macrofit",
|
|
14
|
+
license="MIT",
|
|
15
|
+
packages=find_packages(exclude=["tests*"]),
|
|
16
|
+
python_requires=">=3.10",
|
|
17
|
+
install_requires=[
|
|
18
|
+
"statsmodels>=0.14.0",
|
|
19
|
+
"pandas>=1.5.0",
|
|
20
|
+
"numpy>=1.23.0",
|
|
21
|
+
],
|
|
22
|
+
classifiers=[
|
|
23
|
+
"Programming Language :: Python :: 3",
|
|
24
|
+
"Topic :: Scientific/Engineering :: Mathematics",
|
|
25
|
+
],
|
|
26
|
+
)
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
import pandas as pd
|
|
3
|
+
from macrofit import search_arima
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def make_ar1(n=200, phi=0.6, seed=1):
|
|
7
|
+
rng = np.random.default_rng(seed)
|
|
8
|
+
y = np.zeros(n)
|
|
9
|
+
for t in range(1, n):
|
|
10
|
+
y[t] = phi * y[t - 1] + rng.standard_normal()
|
|
11
|
+
return pd.Series(y, name="GDP")
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def test_returns_sorted_results():
|
|
15
|
+
out = search_arima(make_ar1())
|
|
16
|
+
assert list(out.columns) == ["p", "q", "aic"]
|
|
17
|
+
assert out["aic"].is_monotonic_increasing
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def test_empty_when_nothing_passes():
|
|
21
|
+
out = search_arima(make_ar1(), alpha=1e-30)
|
|
22
|
+
assert out.empty
|