fix(backtest): ensure data_source is passed through all validation calls

- Pass data_source to derive_entry_spot in backtests.py
- Remove default 'synthetic' value for data_source in derive_entry_spot and validate_preview_inputs
- Update all tests to explicitly pass data_source parameter
- Improve error message with helpful suggestion for Databento/Yahoo Finance
This commit is contained in:
Bu5hm4nn
2026-03-30 09:21:49 +02:00
parent eaaf78cd12
commit 2d1ecc2fcf
3 changed files with 12 additions and 6 deletions

View File

@@ -32,7 +32,7 @@ def test_backtest_page_service_accepts_decimal_boundary_values() -> None:
def test_backtest_page_service_uses_fixture_window_for_deterministic_run() -> None:
service = BacktestPageService()
entry_spot = service.derive_entry_spot("GLD", date(2024, 1, 2), date(2024, 1, 8))
entry_spot = service.derive_entry_spot("GLD", date(2024, 1, 2), date(2024, 1, 8), data_source="synthetic")
result = service.run_read_only_scenario(
symbol="GLD",
start_date=date(2024, 1, 2),
@@ -41,6 +41,7 @@ def test_backtest_page_service_uses_fixture_window_for_deterministic_run() -> No
underlying_units=1000.0,
loan_amount=68000.0,
margin_call_ltv=0.75,
data_source="synthetic",
)
assert entry_spot == 100.0
@@ -180,15 +181,15 @@ def test_backtest_page_service_fails_closed_outside_seeded_fixture_window() -> N
# Wrong symbol raises error (fixture only supports GLD)
with pytest.raises(ValueError, match="deterministic fixture data only supports GLD"):
service.derive_entry_spot("AAPL", date(2024, 1, 2), date(2024, 1, 8))
service.derive_entry_spot("AAPL", date(2024, 1, 2), date(2024, 1, 8), data_source="synthetic")
# Dates before window start raises error
with pytest.raises(ValueError, match="deterministic fixture data only supports the seeded"):
service.derive_entry_spot("GLD", date(2024, 1, 1), date(2024, 1, 5))
service.derive_entry_spot("GLD", date(2024, 1, 1), date(2024, 1, 5), data_source="synthetic")
# Dates after window end raises error
with pytest.raises(ValueError, match="deterministic fixture data only supports the seeded"):
service.derive_entry_spot("GLD", date(2024, 1, 5), date(2024, 1, 10))
service.derive_entry_spot("GLD", date(2024, 1, 5), date(2024, 1, 10), data_source="synthetic")
def test_backtest_preview_validation_requires_supported_fixture_window_even_with_supplied_entry_spot() -> None:
@@ -206,6 +207,7 @@ def test_backtest_preview_validation_requires_supported_fixture_window_even_with
loan_amount=68000.0,
margin_call_ltv=0.75,
entry_spot=100.0,
data_source="synthetic",
)
@@ -221,6 +223,7 @@ def test_backtest_preview_validation_accepts_close_supplied_entry_spot() -> None
loan_amount=68000.0,
margin_call_ltv=0.75,
entry_spot=100.005,
data_source="synthetic",
)
assert entry_spot == 100.0
@@ -239,6 +242,7 @@ def test_backtest_preview_validation_rejects_mismatched_supplied_entry_spot() ->
loan_amount=68000.0,
margin_call_ltv=0.75,
entry_spot=99.0,
data_source="synthetic",
)