Improve backtest lazy loading and test automation
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
from datetime import date
|
||||
from decimal import Decimal
|
||||
|
||||
@@ -175,6 +176,49 @@ def test_backtest_page_service_validation_errors_are_user_facing(kwargs: dict[st
|
||||
service.run_read_only_scenario(**kwargs)
|
||||
|
||||
|
||||
def test_backtest_page_service_fails_closed_for_unsupported_databento_gc_symbol() -> None:
|
||||
service = BacktestPageService()
|
||||
|
||||
with pytest.raises(ValueError, match="Databento backtests currently support GLD and XAU only"):
|
||||
service.validate_preview_inputs(
|
||||
symbol="GC",
|
||||
start_date=date(2024, 7, 1),
|
||||
end_date=date(2024, 7, 5),
|
||||
template_slug="protective-put-atm-12m",
|
||||
underlying_units=1000.0,
|
||||
loan_amount=68000.0,
|
||||
margin_call_ltv=0.75,
|
||||
data_source="databento",
|
||||
)
|
||||
|
||||
|
||||
def test_backtest_page_service_allows_databento_xau_proxy_symbol() -> None:
|
||||
service = BacktestPageService()
|
||||
|
||||
# Support validation should pass before the provider is consulted.
|
||||
service.validate_data_source_support("XAU", "databento")
|
||||
|
||||
|
||||
@pytest.mark.skipif(not os.getenv("DATABENTO_API_KEY"), reason="requires DATABENTO_API_KEY")
|
||||
def test_backtest_page_service_runs_live_databento_gld_scenario() -> None:
|
||||
service = BacktestPageService()
|
||||
|
||||
result = service.run_read_only_scenario(
|
||||
symbol="GLD",
|
||||
start_date=date(2024, 7, 1),
|
||||
end_date=date(2024, 7, 5),
|
||||
template_slug="protective-put-atm-12m",
|
||||
underlying_units=1000.0,
|
||||
loan_amount=68000.0,
|
||||
margin_call_ltv=0.75,
|
||||
data_source="databento",
|
||||
)
|
||||
|
||||
assert result.entry_spot > 0
|
||||
assert len(result.run_result.template_results[0].daily_path) >= 4
|
||||
assert result.data_cost_usd >= 0
|
||||
|
||||
|
||||
def test_backtest_page_service_fails_closed_outside_seeded_fixture_window() -> None:
|
||||
"""Test that fixture data fails for dates outside the seeded window."""
|
||||
service = BacktestPageService()
|
||||
|
||||
Reference in New Issue
Block a user