refactor(pre-alpha): align preview and runtime fixture validation
This commit is contained in:
@@ -170,18 +170,33 @@ def test_backtest_page_service_fails_closed_outside_seeded_fixture_window() -> N
|
||||
)
|
||||
|
||||
|
||||
def test_backtest_preview_validation_reuses_supplied_entry_spot() -> None:
|
||||
def test_backtest_preview_validation_requires_supported_fixture_window_even_with_supplied_entry_spot() -> None:
|
||||
service = BacktestPageService()
|
||||
|
||||
entry_spot = service.validate_preview_inputs(
|
||||
symbol="GLD",
|
||||
start_date=date(2024, 1, 2),
|
||||
end_date=date(2024, 1, 8),
|
||||
template_slug="protective-put-atm-12m",
|
||||
underlying_units=1000.0,
|
||||
loan_amount=68000.0,
|
||||
margin_call_ltv=0.75,
|
||||
entry_spot=100.0,
|
||||
)
|
||||
with pytest.raises(ValueError, match="deterministic fixture data only supports GLD"):
|
||||
service.validate_preview_inputs(
|
||||
symbol="GLD",
|
||||
start_date=date(2024, 1, 3),
|
||||
end_date=date(2024, 1, 8),
|
||||
template_slug="protective-put-atm-12m",
|
||||
underlying_units=1000.0,
|
||||
loan_amount=68000.0,
|
||||
margin_call_ltv=0.75,
|
||||
entry_spot=100.0,
|
||||
)
|
||||
|
||||
assert entry_spot == 100.0
|
||||
|
||||
def test_backtest_preview_validation_rejects_mismatched_supplied_entry_spot() -> None:
|
||||
service = BacktestPageService()
|
||||
|
||||
with pytest.raises(ValueError, match="does not match derived historical entry spot"):
|
||||
service.validate_preview_inputs(
|
||||
symbol="GLD",
|
||||
start_date=date(2024, 1, 2),
|
||||
end_date=date(2024, 1, 8),
|
||||
template_slug="protective-put-atm-12m",
|
||||
underlying_units=1000.0,
|
||||
loan_amount=68000.0,
|
||||
margin_call_ltv=0.75,
|
||||
entry_spot=99.0,
|
||||
)
|
||||
|
||||
@@ -315,3 +315,43 @@ def test_event_comparison_uses_preset_defaults_only_when_template_slugs_are_omit
|
||||
"protective-put-90pct-12m",
|
||||
"ladder-50-50-atm-95pct-12m",
|
||||
]
|
||||
|
||||
with pytest.raises(ValueError, match="at least one template slug"):
|
||||
service.materialize_scenario(
|
||||
service.event_preset_service.get_preset("gld-jan-2024-selloff"),
|
||||
initial_portfolio=BacktestPortfolioState(
|
||||
currency="USD",
|
||||
underlying_units=1000.0,
|
||||
entry_spot=100.0,
|
||||
loan_amount=68_000.0,
|
||||
margin_call_ltv=0.75,
|
||||
),
|
||||
template_slugs=(),
|
||||
)
|
||||
|
||||
|
||||
def test_event_comparison_materialize_scenario_rejects_explicit_empty_history() -> None:
|
||||
provider = SyntheticHistoricalProvider(
|
||||
source=FakeHistorySource(FIXTURE_HISTORY),
|
||||
implied_volatility=0.35,
|
||||
risk_free_rate=0.0,
|
||||
)
|
||||
service = EventComparisonService(
|
||||
provider=provider,
|
||||
template_service=StrategyTemplateService(),
|
||||
event_preset_service=EventPresetService(repository=FileEventPresetRepository()),
|
||||
)
|
||||
|
||||
with pytest.raises(ValueError, match="history must not be empty"):
|
||||
service.materialize_scenario(
|
||||
service.event_preset_service.get_preset("gld-jan-2024-selloff"),
|
||||
initial_portfolio=BacktestPortfolioState(
|
||||
currency="USD",
|
||||
underlying_units=1000.0,
|
||||
entry_spot=100.0,
|
||||
loan_amount=68_000.0,
|
||||
margin_call_ltv=0.75,
|
||||
),
|
||||
template_slugs=("protective-put-atm-12m",),
|
||||
history=[],
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user