feat(CORE-001C): type historical unit materialization
This commit is contained in:
@@ -4,6 +4,7 @@ from fastapi import Request
|
||||
from fastapi.responses import RedirectResponse
|
||||
from nicegui import ui
|
||||
|
||||
from app.domain.backtesting_math import asset_quantity_from_floats
|
||||
from app.models.workspace import WORKSPACE_COOKIE, get_workspace_repository
|
||||
from app.pages.common import dashboard_page, render_workspace_recovery
|
||||
from app.services.event_comparison_ui import EventComparisonPageService
|
||||
@@ -64,7 +65,7 @@ def _render_event_comparison_page(workspace_id: str | None = None) -> None:
|
||||
)
|
||||
default_entry_spot = default_preview.initial_portfolio.entry_spot
|
||||
default_units = (
|
||||
float(config.gold_value or 0.0) / default_entry_spot
|
||||
asset_quantity_from_floats(float(config.gold_value or 0.0), default_entry_spot, "GLD")
|
||||
if config and config.gold_value is not None and default_entry_spot > 0
|
||||
else 1000.0
|
||||
)
|
||||
@@ -138,10 +139,25 @@ def _render_event_comparison_page(workspace_id: str | None = None) -> None:
|
||||
return
|
||||
template_select.value = list(service.default_template_selection(str(option["slug"])))
|
||||
try:
|
||||
preview_units = float(units_input.value or 0.0)
|
||||
if workspace_id and config is not None and config.gold_value is not None:
|
||||
preview_scenario = service.preview_scenario(
|
||||
preset_slug=str(option["slug"]),
|
||||
template_slugs=selected_template_slugs(),
|
||||
underlying_units=1.0,
|
||||
loan_amount=float(loan_input.value or 0.0),
|
||||
margin_call_ltv=float(ltv_input.value or 0.0),
|
||||
)
|
||||
preview_units = asset_quantity_from_floats(
|
||||
float(config.gold_value),
|
||||
float(preview_scenario.initial_portfolio.entry_spot),
|
||||
"GLD",
|
||||
)
|
||||
units_input.value = preview_units
|
||||
scenario = service.preview_scenario(
|
||||
preset_slug=str(option["slug"]),
|
||||
template_slugs=selected_template_slugs(),
|
||||
underlying_units=float(units_input.value or 0.0),
|
||||
underlying_units=preview_units,
|
||||
loan_amount=float(loan_input.value or 0.0),
|
||||
margin_call_ltv=float(ltv_input.value or 0.0),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user