refactor(pre-alpha): fail closed on historical preview fallbacks
This commit is contained in:
@@ -98,7 +98,7 @@ class BacktestPageService:
|
||||
)
|
||||
return history[0].close
|
||||
|
||||
def run_read_only_scenario(
|
||||
def validate_preview_inputs(
|
||||
self,
|
||||
*,
|
||||
symbol: str,
|
||||
@@ -108,7 +108,8 @@ class BacktestPageService:
|
||||
underlying_units: float,
|
||||
loan_amount: float,
|
||||
margin_call_ltv: float,
|
||||
) -> BacktestPageRunResult:
|
||||
entry_spot: float | None = None,
|
||||
) -> float:
|
||||
normalized_symbol = symbol.strip().upper()
|
||||
if not normalized_symbol:
|
||||
raise ValueError("Symbol is required")
|
||||
@@ -125,9 +126,35 @@ class BacktestPageService:
|
||||
if not template_slug:
|
||||
raise ValueError("Template selection is required")
|
||||
|
||||
self.template_service.get_template(template_slug)
|
||||
resolved_entry_spot = (
|
||||
entry_spot if entry_spot is not None else self.derive_entry_spot(normalized_symbol, start_date, end_date)
|
||||
)
|
||||
_validate_initial_collateral(underlying_units, resolved_entry_spot, loan_amount)
|
||||
return resolved_entry_spot
|
||||
|
||||
def run_read_only_scenario(
|
||||
self,
|
||||
*,
|
||||
symbol: str,
|
||||
start_date: date,
|
||||
end_date: date,
|
||||
template_slug: str,
|
||||
underlying_units: float,
|
||||
loan_amount: float,
|
||||
margin_call_ltv: float,
|
||||
) -> BacktestPageRunResult:
|
||||
normalized_symbol = symbol.strip().upper()
|
||||
entry_spot = self.validate_preview_inputs(
|
||||
symbol=normalized_symbol,
|
||||
start_date=start_date,
|
||||
end_date=end_date,
|
||||
template_slug=template_slug,
|
||||
underlying_units=underlying_units,
|
||||
loan_amount=loan_amount,
|
||||
margin_call_ltv=margin_call_ltv,
|
||||
)
|
||||
template = self.template_service.get_template(template_slug)
|
||||
entry_spot = self.derive_entry_spot(normalized_symbol, start_date, end_date)
|
||||
_validate_initial_collateral(underlying_units, entry_spot, loan_amount)
|
||||
initial_portfolio = materialize_backtest_portfolio_state(
|
||||
symbol=normalized_symbol,
|
||||
underlying_units=underlying_units,
|
||||
|
||||
Reference in New Issue
Block a user