feat(CORE-001C): type historical unit materialization

This commit is contained in:
Bu5hm4nn
2026-03-24 22:30:36 +01:00
parent 7c2729485c
commit c7c8654be7
8 changed files with 309 additions and 19 deletions

View File

@@ -3,8 +3,8 @@ from __future__ import annotations
from dataclasses import dataclass
from datetime import date
from app.domain.backtesting_math import materialize_backtest_portfolio_state
from app.models.backtest import (
BacktestPortfolioState,
BacktestRunResult,
BacktestScenario,
ProviderRef,
@@ -116,6 +116,13 @@ class BacktestPageService:
template = self.template_service.get_template(template_slug)
entry_spot = self.derive_entry_spot(normalized_symbol, start_date, end_date)
initial_portfolio = materialize_backtest_portfolio_state(
symbol=normalized_symbol,
underlying_units=underlying_units,
entry_spot=entry_spot,
loan_amount=loan_amount,
margin_call_ltv=margin_call_ltv,
)
scenario = BacktestScenario(
scenario_id=(
f"{normalized_symbol.lower()}-{start_date.isoformat()}-{end_date.isoformat()}-{template.slug}"
@@ -124,13 +131,7 @@ class BacktestPageService:
symbol=normalized_symbol,
start_date=start_date,
end_date=end_date,
initial_portfolio=BacktestPortfolioState(
currency="USD",
underlying_units=underlying_units,
entry_spot=entry_spot,
loan_amount=loan_amount,
margin_call_ltv=margin_call_ltv,
),
initial_portfolio=initial_portfolio,
template_refs=(TemplateRef(slug=template.slug, version=template.version),),
provider_ref=ProviderRef(provider_id="synthetic_v1", pricing_mode="synthetic_bs_mid"),
)