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

@@ -260,6 +260,7 @@ def _render_backtests_page(workspace_id: str | None = None) -> None:
"GLD",
date.fromisoformat(DEFAULT_BACKTEST_START),
date.fromisoformat(DEFAULT_BACKTEST_END),
data_source="databento", # Use databento for default dates
)
except ValueError:
# Fixture source may not support the default date range
@@ -510,6 +511,7 @@ def _render_backtests_page(workspace_id: str | None = None) -> None:
symbol,
parse_iso_date(start_input.value, "Start date"),
parse_iso_date(end_input.value, "End date"),
data_source=str(data_source_select.value),
)
except (ValueError, KeyError) as exc:
return None, str(exc)

View File

@@ -230,7 +230,7 @@ class BacktestPageService:
for template in self.template_service.list_active_templates(symbol)
]
def derive_entry_spot(self, symbol: str, start_date: date, end_date: date, data_source: str = "synthetic") -> float:
def derive_entry_spot(self, symbol: str, start_date: date, end_date: date, data_source: str) -> float:
history = self.get_historical_prices(symbol, start_date, end_date, data_source)
if not history:
raise ValueError("No historical prices found for scenario window")
@@ -251,7 +251,7 @@ class BacktestPageService:
loan_amount: float,
margin_call_ltv: float,
entry_spot: float | None = None,
data_source: str = "synthetic",
data_source: str,
) -> float:
normalized_symbol = symbol.strip().upper()
if not normalized_symbol: