macrofit 0.1.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.
macrofit/__init__.py ADDED
@@ -0,0 +1,3 @@
1
+ __version__ = "0.1.0"
2
+
3
+ from macrofit.search import search_arima
macrofit/search.py ADDED
@@ -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,7 @@
1
+ macrofit/__init__.py,sha256=6rh1YpLXPd8YNRN24fEk0BJnKCMBG19Lin9sXHltEE8,65
2
+ macrofit/search.py,sha256=f9ssxdL6ai1cXB5Zj6xMv558z-rFzkzqCrYnQJj8AZw,1313
3
+ macrofit-0.1.0.dist-info/licenses/LICENSE,sha256=-vUflB3BWZfXg_G2ISGGfCMMXEaAVdB5UOcACkq-P2M,1094
4
+ macrofit-0.1.0.dist-info/METADATA,sha256=fdVf8gnyIiv4dNqpbS7aSgFBnSPtUadTEyQGyfJBJq4,2115
5
+ macrofit-0.1.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
6
+ macrofit-0.1.0.dist-info/top_level.txt,sha256=KlomzMKKSxp2Ds_0s_Hfn0wk_oqN5VrDJ6FlupJzpe0,9
7
+ macrofit-0.1.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 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.
@@ -0,0 +1 @@
1
+ macrofit