D16b: месячная доля recurring по frequency и учёт start_date/end_date
amount — итог за период frequency: daily /30.4, weekly /4.33, monthly /1, yearly /12 (делители — именованные константы domain/recurring.py). Платёж учитывается в месяце сетки прогноза, если start_date <= конец месяца и end_date >= начало месяца; сравнение по ISO-строкам, пустые даты — без границ. Сетка прогноза привязана к start_month (по умолчанию текущий календарный месяц), округление — только в точке отображения.
This commit is contained in:
1 parent
abcd84c0fa
commit
f50106ca96
6 files changed
+259
-32
No files matched your search
@@ -1,4 +1,5 @@
|
||||
from copy import deepcopy
|
||||
from datetime import date
|
||||
from decimal import Decimal
|
||||
|
||||
from application.forecast import ForecastService
|
||||
@@ -30,8 +31,10 @@ DEFAULT_SCENARIOS = {
|
||||
|
||||
|
||||
class ScenarioService:
|
||||
def __init__(self, model: FinancialModel):
|
||||
def __init__(self, model: FinancialModel, start_month: str | date | None = None):
|
||||
self.model = deepcopy(model)
|
||||
# Месяц старта сетки прогноза (D16b) — тот же для всех сценариев.
|
||||
self.start_month = start_month
|
||||
|
||||
def apply(self, scenario: ForecastScenario, months: int = 12) -> dict:
|
||||
model = deepcopy(self.model)
|
||||
@@ -53,7 +56,7 @@ class ScenarioService:
|
||||
for a in model.assets:
|
||||
a.growth_rate = a.growth_rate * scenario.growth_multiplier
|
||||
|
||||
service = ForecastService(model)
|
||||
service = ForecastService(model, start_month=self.start_month)
|
||||
result = service.summary(months)
|
||||
result["scenario"] = scenario.name
|
||||
result["scenario_description"] = scenario.description
|
||||
|
||||
Reference in new issue
Block a user