gendesign/backend/app/services/forecasting/__init__.py
Light1YT 5d1260c6fb feat(forecasting): §15 report-level confidence engine v2 (#990, 955-A4)
Add confidence_engine.py — deterministic, advisory, DB-free aggregator folding
per-component confidences + raw data-quality counts (deal/analog count,
domrf↔objective coverage, history months, confounded window) into one
High/Medium/Low via weakest-link MIN, capped at medium while advisory. Builds a
structural RU rationale naming the dragging factors with real numbers ("Low
потому что 7 сделок / 1 ЖК / покрытие 2.5%"). Fills the ReportConfidence slot of
#987 SiteFinderReport. 33 unit tests.
2026-06-03 13:41:02 +05:00

180 lines
6.2 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""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).
• demand_normalization (#951f) — §9.4 нормализация спроса под смену режима ставки (ADVISORY).
• demand_supply_forecast (#952a) — §9.8 центральный движок: спрос (§9.4×§9.5) vs
предложение (§9.3) по горизонтам → баланс/индекс дефицита (СБОРКА, ADVISORY).
• what_to_build (#981/952-B) — §9.7 ранкер сетки сегментов по deficit_index
(прогон #980 per-cell → DESC «что строить»; СБОРКА, ADVISORY).
• affordability (#981/952-B) — §7.9 MAI: ДЕГРАДИРОВАННЫЙ прокси платёжной
нагрузки (субсид. ставка, дохода нет → low-confidence; СБОРКА, ADVISORY).
• scenarios (#984/954-A) — §11 три макро-сценария (conservative/base/
aggressive) прогоном #952 под тремя конвертами ставки (СБОРКА, ADVISORY).
• product_scoring (#985/954-B) — §14.2 десять продуктовых скоров ∈ [0,1] (выше=
лучше) + взвешенный overall (renorm над доступными) + §16 причина на скор;
сводит #950…#984 + live-стек, graceful-None, ADVISORY.
• special_indices (#986/954-C) — §25 шесть специальных индексов (Launch Window,
Product Void, Cannibalization, Competitor Strength, Artificial Demand, Cost-of-
Error); сборка над #980/#981/§9.1/§9.2/§7.9, per-index graceful-None, 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.affordability import (
MortgageAffordabilityIndex,
compute_affordability,
)
from app.services.forecasting.confidence_engine import (
ConfidenceFactor,
ReportConfidenceResult,
compute_report_confidence,
)
from app.services.forecasting.demand_normalization import (
DemandNormalization,
compute_demand_normalization,
normalization_factor,
)
from app.services.forecasting.demand_supply_forecast import (
DemandSupplyForecast,
compute_demand_supply_forecast,
hold_last_rate,
)
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.product_scoring import (
ProductScore,
ProductScoreCard,
compute_score_card,
)
from app.services.forecasting.rate_sensitivity import (
RateSensitivity,
best_lag,
compute_rate_sensitivity,
ols_slope_r2,
shrink,
)
from app.services.forecasting.report import (
ReportConfidence,
ReportExecSummary,
ReportFutureMarket,
ReportMarketNow,
ReportMeta,
ReportProductTz,
ReportScenarios,
ReportScoring,
SiteFinderReport,
)
from app.services.forecasting.sales_series import (
SalesSeries,
SegmentSpec,
build_sales_series,
fill_month_grid,
log_diff,
price_bucket_of,
room_area_bucket_of,
)
from app.services.forecasting.scenarios import (
ScenarioForecast,
build_rate_envelopes,
compute_scenarios,
)
from app.services.forecasting.special_indices import (
SpecialIndex,
SpecialIndices,
compute_special_indices,
)
from app.services.forecasting.what_to_build import (
RankedSegment,
WhatToBuildRanking,
rank_segments,
)
__all__ = [
"ConfidenceFactor",
"DemandNormalization",
"DemandSupplyForecast",
"MacroCoefficient",
"MonthlyMacro",
"MortgageAffordabilityIndex",
"ProductScore",
"ProductScoreCard",
"RankedSegment",
"RateSensitivity",
"ReportConfidence",
"ReportConfidenceResult",
"ReportExecSummary",
"ReportFutureMarket",
"ReportMarketNow",
"ReportMeta",
"ReportProductTz",
"ReportScenarios",
"ReportScoring",
"SalesSeries",
"ScenarioForecast",
"SegmentSpec",
"SiteFinderReport",
"SpecialIndex",
"SpecialIndices",
"WhatToBuildRanking",
"assemble_coefficient",
"best_lag",
"build_rate_envelopes",
"build_sales_series",
"classify_regime",
"compute_affordability",
"compute_demand_normalization",
"compute_demand_supply_forecast",
"compute_macro_coefficient",
"compute_rate_sensitivity",
"compute_report_confidence",
"compute_scenarios",
"compute_score_card",
"compute_special_indices",
"f_issuance",
"f_mortgage_rate",
"f_overdue",
"f_rate",
"fill_month_grid",
"get_monthly_macro",
"hold_last_rate",
"is_confounded_window",
"log_diff",
"macro_at_lag",
"normalization_factor",
"ols_slope_r2",
"price_bucket_of",
"rank_segments",
"renormalize_contributions",
"room_area_bucket_of",
"segment_steepness",
"shrink",
]