diff --git a/CHANGELOG.md b/CHANGELOG.md index bf52a8b..e857b20 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,17 @@ Exact maximum-likelihood estimation, forecasting and diagnostics of multivariate VARMA models (Mauricio 1995 JASA / 1997 AS 311), pure-Python with an optional compiled C engine. +## 0.3.4 — 2026-11-16 + +**The HTML forecast page says a percentage only with logs (BUG-0026).** +`write_forecast_report` wrote the variations, their standard deviations, the +ERR column and the charts as 100·Δ/scale under "(%)" whatever lambda was: in +levels, 100 times the change. It now follows the `.forecast` (BUG-0025), fue's +page (fue BUG-0028) and atsw-gui's gui/sim: `(100 if lambda = 0 else 1)/scale`, +and "(%)" only with logs. With logs the page does not change. + +The `test` extra declares pandas, which one of the tests imports. + ## 0.3.3 — 2026-11-15 **The forecast table says a percentage only with logs (BUG-0025).** The diff --git a/bugs/BUG-0026-repro/repro.py b/bugs/BUG-0026-repro/repro.py new file mode 100644 index 0000000..632753b --- /dev/null +++ b/bugs/BUG-0026-repro/repro.py @@ -0,0 +1,56 @@ +#!/usr/bin/env python3 +"""BUG-0026: the HTML forecast page multiplies the variations by 100/scale +whatever lambda: in levels it prints 100 times the change. + +`report_forecast` (write_forecast_report, the SPS page per series) writes the +period and annual variations, their standard deviations, the ERR column and +the chart as 100 * delta / scale, and labels them "(%)". With lambda = 0 that is +a percentage; with lambda = 1 it is the change of the level times 100. The +page says it matches the .forecast, which since 0.3.3 (BUG-0025) uses +(100 if lambda = 0 else 1)/scale, as fue's page (fue BUG-0028) and atsw-gui's +gui/sim forecast do. + +Two synthetic monthly AR(1) series about 100, in levels, scale = 100. Exits 1 +while the first forecast's monthly change on the page is 100 times the change +of the level; 0 when it is the change and the labels drop the "(%)". +""" +import os +import re +import sys +import tempfile +import warnings + +import numpy as np + +from drvarma import Model +from drvarma import report_forecast as rf +from drvarma.datasets import simulate_varma + +warnings.filterwarnings("ignore") + + +def main(): + sim = simulate_varma(phi=[np.diag([0.5, 0.4])], sigma=np.eye(2), n=120, + mu=[100.0, 50.0], seed=1, freq=12, start=(2010, 1), + names=["A", "B"]) + mdl = Model(sim, lam=1.0, d=0, D=0, scale=100.0, p=1, q=0, + include_mean=True).fit() + arr = rf._forecast_arrays(mdl, 12) + level = arr["level"][:, 0] + last = float(np.asarray(sim.data)[-1, 0]) + change = level[0] - last # the change, in the series' units + shown = arr["diff1"][0, 0] + with tempfile.TemporaryDirectory() as d: + html = open(rf.write_forecast_report(mdl, os.path.join(d, "fc"), L=12)[0], + encoding="utf-8").read() + pct = len(re.findall(r"\(%\)", html)) + print(f"level {last:.4f} -> {level[0]:.4f}: change {change:.4f}; page shows " + f"{shown:.4f}; '(%)' labels on the page: {pct}") + ok = abs(shown - change) < 1e-6 * max(1.0, abs(change)) and pct == 0 + print("FIXED" if ok else "OPEN: in levels the page shows 100 x the change, " + "labelled as a percentage") + return 0 if ok else 1 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/bugs/BUG-0026-the-html-forecast-page-multiplies-the-variations-by-100-in-levels.md b/bugs/BUG-0026-the-html-forecast-page-multiplies-the-variations-by-100-in-levels.md new file mode 100644 index 0000000..7f00b36 --- /dev/null +++ b/bugs/BUG-0026-the-html-forecast-page-multiplies-the-variations-by-100-in-levels.md @@ -0,0 +1,59 @@ +--- +id: BUG-0026 +title: The HTML forecast page multiplies the variations by 100/scale whatever lambda — in levels it prints 100 times the change, labelled "(%)" +status: fixed +severity: medium +component: report_forecast +found_in: 0.3.3 +fixed_in: 0.3.4 +reported: 2026-11-16 +reporter: David / Claude — what was left of the scale round (atsw-gui docs/ESTUDIO-escala.md) +tags: [forecast, scale, lambda-1, report] +references: + - src/drvarma/report_forecast.py (_forecast_arrays sc = 100.0 / scale; _table_data; _make_charts_svg) + - BUG-0025 (the .forecast, fixed in 0.3.3; its text said the page followed it, and it did not) + - fue BUG-0028 (fue's page, of which this one is the multivariate port; fixed in fue 0.1.22) + - atsw-gui gui/sim/src/prevision.c (the C forecast chart of the VARMA, by the rule since atsw-gui #177) + - bugs/BUG-0026-repro/repro.py +--- + +## Summary + +`write_forecast_report` — the SPS page per series — wrote the period and +annual variations, their standard deviations, the ERR column, the annual chart +and the ERR bands as `100 * delta / scale`, under "(%)" headings, whatever +lambda was. With lambda = 0 that is a percentage. With lambda = 1 it is the +change of the level times 100: + +``` +level 100.4529 -> 100.2198: change -0.2331; page shows -23.3112; '(%)' labels on the page: 9 +``` + +The page says its numbers are the `.forecast`'s, and since 0.3.3 (BUG-0025) +the `.forecast` uses `(100 if lambda = 0 else 1)/scale`. BUG-0025 listed this +page as following the same rule; it had not been changed. + +## Impact + +Medium. In levels the page shows variations 100 times too large, labelled as +percentages, and disagrees with the `.forecast`, with fue's page and with +atsw-gui's gui/sim for the same model. Logs (the usual case) are unaffected: +the page is the same, byte for byte apart from the chart's timestamp. + +## Reproduction + +`bugs/BUG-0026-repro/repro.py`: two synthetic monthly AR(1) series about 100, +lambda = 1, scale = 100. Exits 1 while the first forecast's monthly change on +the page is 100 times the change of the level, or the page says "(%)". + +## Root cause + +The page was ported from fue's before fue BUG-0028 was fixed, with fue's +`100.0 / refactor`. + +## Fix + +`_pct(lam)`: 100 with logs, 1 otherwise, for the table, the chart and the ERR +bands; the headings say "(%)" only with logs ("Monthly change", "Annual +change", "Value" otherwise), as fue's page. A history row with no datum a year +before shows "—" instead of a level passed off as a variation. diff --git a/bugs/README.md b/bugs/README.md index 329cee4..f0576a0 100644 --- a/bugs/README.md +++ b/bugs/README.md @@ -29,6 +29,7 @@ New report: `art-bug new` (or copy `TEMPLATE.md`). Validate: `art-bug check`. | [BUG-0023](BUG-0023-la-suite-entera-corre-sin-el-motor.md) | fixed | medium | tests | A full pytest run computes with the pure-Python port — collecting test_regression_bugs.py sets DRVARMA_NO_ENGINE for the whole session | 0.3.0 | | [BUG-0024](BUG-0024-una-ruta-larga-en-windows-tira-el-motor.md) | fixed | high | packaging | Built on Windows from pip's temp directory (a git URL or an sdist), the engine's object path passes 260 characters and the optional extension is dropped in silence | 0.3.0 | | [BUG-0025](BUG-0025-the-ladder-forecast-table-multiplies-the-variations-by-100-in-levels.md) | fixed | medium | ladder | The ladder's forecast table multiplies the variations by 100/refactor whatever lambda — in levels it prints 100 times the change | 0.3.3 | +| [BUG-0026](BUG-0026-the-html-forecast-page-multiplies-the-variations-by-100-in-levels.md) | fixed | medium | report_forecast | The HTML forecast page multiplies the variations by 100/scale whatever lambda — in levels it prints 100 times the change, labelled "(%)" | 0.3.4 | | [BUG-0009](BUG-0009-load-data-toma-la-columna-de-fecha-como-serie.md) | wontfix | medium | mcp | load_data takes a date column as a series, and the sample start is not read from it | — | | [BUG-0011](BUG-0011-el-consenso-impone-un-lambda-y-el-d-maximo.md) | wontfix | low | mcp | The consensus imposes one lambda and d = max(d_i), which over-differences an I(0) series | — | | [BUG-0012](BUG-0012-los-coeficientes-armonicos-no-cuentan.md) | wontfix | low | deseason | The harmonic seasonal coefficients are not counted in degrees of freedom, k or forecast uncertainty | — | diff --git a/pyproject.toml b/pyproject.toml index 45b904f..72f41fe 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "drvarma" -version = "0.3.3" +version = "0.3.4" description = "Multivariate VARMA modelling — exact maximum-likelihood estimation, forecasting and diagnostics; the engine of the sima assistant (sima-tseries)" readme = "README.md" requires-python = ">=3.10" @@ -69,7 +69,7 @@ c-engine = ["cffi>=1.15"] plots = ["matplotlib>=3.6", "pyfug>=2.0"] # HTML forecast reports (SPS / fuf format); add weasyprint for optional PDF. forecast-report = ["jinja2>=3.0", "matplotlib>=3.6"] -test = ["pytest>=7"] +test = ["pytest>=7", "pandas"] [tool.setuptools.packages.find] where = ["src"] diff --git a/src/drvarma/report_forecast.py b/src/drvarma/report_forecast.py index fce87cf..669e5ad 100644 --- a/src/drvarma/report_forecast.py +++ b/src/drvarma/report_forecast.py @@ -133,13 +133,13 @@