fix(forecasting): cap trend_ratio by v_rec magnitude when v_prior==0 (#1508) #1679

Merged
lekss361 merged 1 commit from fix/trend-ratio-vprior-zero-1508 into main 2026-06-17 17:45:14 +00:00
Owner

Проблема (#1508)

09_macro_and_trend.py: при v_prior==0 присваивался фиксированный trend_ratio=2.0 независимо от величины v_rec → искусственный 2× скачок даже при крошечном v_rec.

Решение (кап по величине v_rec — выбран пользователем)

ratio = 1.0 + min(1.0, v_rec / _REF_VELOCITY) * (_TREND_CAP_VPRIOR_ZERO - 1.0)
  • _REF_VELOCITY=10.0 (порог high-activity, flats/corpus/мес по EKB)
  • _TREND_CAP_VPRIOR_ZERO=1.5 (ниже downstream hard-cap 2.0)
  • v_rec=1→≈1.05; v_rec=5→≈1.25; v_rec≥10→1.5. Ветка v_prior>0 не тронута.

Verify

  • ruff clean (+ попутно 5 pre-existing нарушений в файле), py_compile ok; backend suite 241 passed.

Closes #1508

## Проблема (#1508) `09_macro_and_trend.py`: при `v_prior==0` присваивался фиксированный `trend_ratio=2.0` независимо от величины `v_rec` → искусственный 2× скачок даже при крошечном v_rec. ## Решение (кап по величине v_rec — выбран пользователем) ```python ratio = 1.0 + min(1.0, v_rec / _REF_VELOCITY) * (_TREND_CAP_VPRIOR_ZERO - 1.0) ``` - `_REF_VELOCITY=10.0` (порог high-activity, flats/corpus/мес по EKB) - `_TREND_CAP_VPRIOR_ZERO=1.5` (ниже downstream hard-cap 2.0) - v_rec=1→≈1.05; v_rec=5→≈1.25; v_rec≥10→1.5. Ветка `v_prior>0` не тронута. ## Verify - `ruff` clean (+ попутно 5 pre-existing нарушений в файле), `py_compile` ok; backend suite **241 passed**. Closes #1508
lekss361 added 1 commit 2026-06-17 17:31:26 +00:00
fix(forecasting): cap trend_ratio by v_rec magnitude when v_prior==0 (#1508)
All checks were successful
CI / changes (push) Successful in 10s
CI / changes (pull_request) Successful in 7s
CI / backend-tests (push) Has been skipped
CI / frontend-tests (push) Has been skipped
CI / openapi-codegen-check (push) Has been skipped
CI / backend-tests (pull_request) Has been skipped
CI / frontend-tests (pull_request) Has been skipped
CI / openapi-codegen-check (pull_request) Has been skipped
cf36151dbc
When v_prior == 0 and v_rec > 0, the old code unconditionally assigned
trend_ratio = 2.0, producing an artificial 2x jump even for districts
with negligible recent velocity.

New formula:
  ratio = 1.0 + min(1.0, v_rec / _REF_VELOCITY) * (_TREND_CAP_VPRIOR_ZERO - 1.0)

Where:
  _REF_VELOCITY = 10.0   (monthly flats/corpus — EKB "well-performing" benchmark)
  _TREND_CAP_VPRIOR_ZERO = 1.5  (max ratio for the v_prior==0 case)

Tiny v_rec (e.g. 1 flat/month) → ratio ≈ 1.05 (near neutral)
Large v_rec (≥ 10 flat/month) → ratio → 1.5 (capped, below old hard 2.0)

v_prior > 0 branch is unchanged.

Also fixes pre-existing ruff violations in the same file (E401 multi-import,
E701 inline colon, E722 bare except, F401 unused import) so ruff check passes clean.
lekss361 merged commit cf21ff76a9 into main 2026-06-17 17:45:14 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: lekss361/gendesign#1679
No description provided.