refactor(BT-001C): share historical fixture provider

This commit is contained in:
Bu5hm4nn
2026-03-27 21:41:50 +01:00
parent 477514f838
commit 554a41a060
8 changed files with 236 additions and 110 deletions

View File

@@ -282,3 +282,39 @@ def test_backtest_page_service_uses_injected_provider_identity_in_provider_ref()
assert result.scenario.provider_ref.provider_id == "custom_v1"
assert result.scenario.provider_ref.pricing_mode == "custom_mode"
def test_backtest_page_service_preserves_injected_provider_behavior_beyond_history_loading() -> None:
class CustomProvider(SyntheticHistoricalProvider):
provider_id = "custom_v2"
pricing_mode = "custom_mode"
def price_option_by_type(self, **kwargs: object):
quote = super().price_option_by_type(**kwargs)
return quote.__class__(
position_id=quote.position_id,
leg_id=quote.leg_id,
spot=quote.spot,
strike=quote.strike,
expiry=quote.expiry,
quantity=quote.quantity,
mark=42.0,
)
provider = CustomProvider(source=StaticBacktestSource(), implied_volatility=0.2, risk_free_rate=0.01)
injected_service = BacktestService(provider=provider)
page_service = BacktestPageService(backtest_service=injected_service)
result = page_service.run_read_only_scenario(
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,
)
template_result = result.run_result.template_results[0]
assert template_result.daily_path[0].option_market_value == 42000.0
assert template_result.summary_metrics.total_hedge_cost == 42000.0