From c2af363eef2ba9724559b387327597b5663d5cd0 Mon Sep 17 00:00:00 2001 From: Bu5hm4nn Date: Sun, 29 Mar 2026 17:53:03 +0200 Subject: [PATCH] feat(backtests): expand default date range to full Databento availability - Changed default date range from 5 days (Jan 2024) to 2 years (2022-2023) - Added SYMBOL_MIN_DATES constant documenting data availability per symbol - GLD minimum date: 2004-11-18 (ETF launch) - GC futures minimum date: 1974-01-01 - XAU index minimum date: 1970-01-01 - Added UI hint showing GLD data availability from ETF launch - Users can now run backtests across the full historical range --- app/pages/backtests.py | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/app/pages/backtests.py b/app/pages/backtests.py index 1674540..ba8be02 100644 --- a/app/pages/backtests.py +++ b/app/pages/backtests.py @@ -41,6 +41,17 @@ DATA_SOURCES = { "synthetic": "Synthetic", } +# Minimum dates for common symbols (ETF/futures inception) +SYMBOL_MIN_DATES = { + "GLD": date(2004, 11, 18), # GLD ETF launched November 18, 2004 + "GC": date(1974, 1, 1), # Gold futures have much longer history + "XAU": date(1970, 1, 1), # XAU index historical data +} + +# Reasonable default date range (2 years of data) +DEFAULT_BACKTEST_START = "2022-01-03" # First trading day of 2022 +DEFAULT_BACKTEST_END = "2023-12-29" # Last trading day of 2023 + def _chart_options(result: BacktestPageRunResult) -> dict: template_result = result.run_result.template_results[0] @@ -182,12 +193,17 @@ def _render_backtests_page(workspace_id: str | None = None) -> None: default_data_source = "databento" default_dataset = "XNAS.BASIC" default_schema = "ohlcv-1d" - default_start_date = "2024-01-02" - default_end_date = "2024-01-08" + default_start_date = DEFAULT_BACKTEST_START + default_end_date = DEFAULT_BACKTEST_END default_symbol = "GLD" default_start_price = 0.0 - default_entry_spot = service.derive_entry_spot("GLD", date(2024, 1, 2), date(2024, 1, 8)) + # Derive entry spot from default date range + default_entry_spot = service.derive_entry_spot( + "GLD", + date.fromisoformat(DEFAULT_BACKTEST_START), + date.fromisoformat(DEFAULT_BACKTEST_END), + ) default_units = ( asset_quantity_from_workspace_config(config, entry_spot=default_entry_spot, symbol="GLD") if config is not None and default_entry_spot > 0 @@ -291,6 +307,9 @@ def _render_backtests_page(workspace_id: str | None = None) -> None: .classes("w-full") .props("data-testid=end-date-input") ) + date_range_hint = ui.label( + f"GLD data available from {SYMBOL_MIN_DATES['GLD'].strftime('%Y-%m-%d')} (ETF launch)" + ).classes("text-xs text-slate-500 dark:text-slate-400") start_price_input = ( ui.number("Start price (0 = auto-derive)", value=default_start_price, min=0, step=0.01)