fix(CORE-002C): explain undercollateralized historical seeds
This commit is contained in:
@@ -20,6 +20,17 @@ from app.services.strategy_templates import StrategyTemplateService
|
||||
|
||||
SUPPORTED_BACKTEST_PAGE_SYMBOL = "GLD"
|
||||
|
||||
|
||||
def _validate_initial_collateral(underlying_units: float, entry_spot: float, loan_amount: float) -> None:
|
||||
initial_collateral_value = underlying_units * entry_spot
|
||||
if loan_amount >= initial_collateral_value:
|
||||
raise ValueError(
|
||||
"Historical scenario starts undercollateralized: "
|
||||
f"loan ${loan_amount:,.0f} exceeds initial collateral ${initial_collateral_value:,.0f} "
|
||||
f"at entry spot ${entry_spot:,.2f}. Reduce loan amount or increase underlying units."
|
||||
)
|
||||
|
||||
|
||||
DETERMINISTIC_UI_FIXTURE_HISTORY: tuple[DailyClosePoint, ...] = (
|
||||
DailyClosePoint(date=date(2024, 1, 2), close=100.0),
|
||||
DailyClosePoint(date=date(2024, 1, 3), close=96.0),
|
||||
@@ -116,6 +127,7 @@ class BacktestPageService:
|
||||
|
||||
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