gendesign/backend/app/services/forecasting/__init__.py
Light1YT a5e887ae32 feat(forecasting): §9.5 macro coefficient (#951e, advisory)
Deterministic composite demand multiplier (centered 1.0, clamped [0.6,1.3]),
corrects a forecast for the macro regime, directional by market segment.
Heuristic named-constant weights over 4 backed sub-factors (rate / mortgage
rate / issuance / overdue) with weight renormalization over available inputs
(degraded gov/income/cpi/confidence drop out of num AND denom, not silently 0).
Segment-steepness modifier on rate-driven channels (expensive/large/investment
steeper-negative on rate↑; family/compact/liquid steeper-positive on rate↓).
Graceful empty -> 1.0/low. Pure, no LLM, no new SQL (reuses PR2 get_monthly_macro).
ADVISORY: not wired into any endpoint. 50 unit tests (forecasting/ total 191).

PR6/wiring follow-ups: gate lone-survivor renorm leverage under low confidence;
reconsider asymmetric favored-segment steepness (resilient on rate↑).
2026-06-03 11:19:59 +05:00

83 lines
2.6 KiB
Python

"""Forecasting services — детерминированный форсайт-слой Site Finder v2.
#951 (Site Finder v2 / «GG-форсайт», EPIC 7 «Чувствительность к ключевой ставке»).
Этот пакет — фундамент data-independent логики прогноза: monthly макро-ряды,
классификатор режима ставки, лаговые помощники. Всё ДЕТЕРМИНИРОВАННО, БЕЗ LLM.
Слои (по PR):
• macro_series (#951b) — monthly макро-ряд + классификатор режима ставки (X-ось §9.6).
• sales_series (#951c) — monthly ряд продаж по сегменту (Y-ось §9.6).
• rate_sensitivity (#951d) — §9.6 чувствительность продаж к key_rate (CORE, ADVISORY).
• macro_coefficient (#951e) — §9.5 макро-коэффициент (композитный множитель, ADVISORY).
Источники данных:
• макро — таблица macro_indicator через reader site_finder/macro.py (reuse).
• продажи — objective_corpus_room_month / objective_lots (см. sales_series).
"""
from __future__ import annotations
from app.services.forecasting.macro_coefficient import (
MacroCoefficient,
assemble_coefficient,
compute_macro_coefficient,
f_issuance,
f_mortgage_rate,
f_overdue,
f_rate,
renormalize_contributions,
segment_steepness,
)
from app.services.forecasting.macro_series import (
MonthlyMacro,
classify_regime,
get_monthly_macro,
is_confounded_window,
macro_at_lag,
)
from app.services.forecasting.rate_sensitivity import (
RateSensitivity,
best_lag,
compute_rate_sensitivity,
ols_slope_r2,
shrink,
)
from app.services.forecasting.sales_series import (
SalesSeries,
SegmentSpec,
build_sales_series,
fill_month_grid,
log_diff,
price_bucket_of,
room_area_bucket_of,
)
__all__ = [
"MacroCoefficient",
"MonthlyMacro",
"RateSensitivity",
"SalesSeries",
"SegmentSpec",
"assemble_coefficient",
"best_lag",
"build_sales_series",
"classify_regime",
"compute_macro_coefficient",
"compute_rate_sensitivity",
"f_issuance",
"f_mortgage_rate",
"f_overdue",
"f_rate",
"fill_month_grid",
"get_monthly_macro",
"is_confounded_window",
"log_diff",
"macro_at_lag",
"ols_slope_r2",
"price_bucket_of",
"renormalize_contributions",
"room_area_bucket_of",
"segment_steepness",
"shrink",
]