feat(CORE-001C): type historical unit materialization
This commit is contained in:
@@ -2,6 +2,7 @@ from __future__ import annotations
|
||||
|
||||
from datetime import timedelta
|
||||
|
||||
from app.domain.backtesting_math import materialize_backtest_portfolio_state
|
||||
from app.models.backtest import (
|
||||
BacktestPortfolioState,
|
||||
BacktestScenario,
|
||||
@@ -93,12 +94,13 @@ class EventComparisonService:
|
||||
preset = self.event_preset_service.get_preset(preset_slug)
|
||||
history = self._load_preset_history(preset)
|
||||
entry_spot = history[0].close
|
||||
initial_portfolio = BacktestPortfolioState(
|
||||
currency=currency,
|
||||
initial_portfolio = materialize_backtest_portfolio_state(
|
||||
symbol=preset.symbol,
|
||||
underlying_units=underlying_units,
|
||||
entry_spot=entry_spot,
|
||||
loan_amount=loan_amount,
|
||||
margin_call_ltv=margin_call_ltv,
|
||||
currency=currency,
|
||||
cash_balance=cash_balance,
|
||||
financing_rate=financing_rate,
|
||||
)
|
||||
@@ -124,12 +126,13 @@ class EventComparisonService:
|
||||
raise ValueError("Event comparison requires at least one template slug")
|
||||
|
||||
resolved_history = history or self._load_preset_history(preset)
|
||||
scenario_portfolio = BacktestPortfolioState(
|
||||
currency=initial_portfolio.currency,
|
||||
scenario_portfolio = materialize_backtest_portfolio_state(
|
||||
symbol=preset.symbol,
|
||||
underlying_units=initial_portfolio.underlying_units,
|
||||
entry_spot=resolved_history[0].close,
|
||||
loan_amount=initial_portfolio.loan_amount,
|
||||
margin_call_ltv=initial_portfolio.margin_call_ltv,
|
||||
currency=initial_portfolio.currency,
|
||||
cash_balance=initial_portfolio.cash_balance,
|
||||
financing_rate=initial_portfolio.financing_rate,
|
||||
)
|
||||
|
||||
@@ -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"),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user