feat: default to March 2026 dates and show Low/High/Close in results

- Change default backtest date range to 2026-03-02 through 2026-03-25
- Add spot_low and spot_high to BacktestDailyPoint for intraday range
- Update engine to populate low/high from DailyClosePoint
- Update daily results table to show Low, High, Close columns instead of just Spot
- Update job serialization to include spot_low and spot_high
This commit is contained in:
Bu5hm4nn
2026-04-04 23:18:01 +02:00
parent a8e710f790
commit 063ccb6781
4 changed files with 33 additions and 35 deletions

View File

@@ -1,7 +1,7 @@
from __future__ import annotations
import logging
from datetime import date, datetime, timedelta
from datetime import date, datetime
from typing import TYPE_CHECKING, Any
from fastapi.responses import RedirectResponse
@@ -64,20 +64,12 @@ DATABENTO_DATASET_MIN_DATES = {
def get_default_backtest_dates() -> tuple[date, date]:
"""Get default backtest date range (~2 years ending on most recent Friday or earlier).
"""Get default backtest date range (March 2026 for testing).
Returns dates (start, end) where:
- end is the most recent Friday (including today if today is Friday)
- start is ~730 days before end
Returns dates (start, end) for March 2026.
"""
today = date.today()
# Find days since most recent Friday
days_since_friday = (today.weekday() - 4) % 7
# If today is Friday (weekday 4), days_since_friday is 0, so end = today
# If today is Saturday (weekday 5), days_since_friday is 1, so end = yesterday (Friday)
# etc.
end = today - timedelta(days=days_since_friday)
start = end - timedelta(days=730) # ~2 years
start = date(2026, 3, 2)
end = date(2026, 3, 25)
return start, end
@@ -658,41 +650,36 @@ def _render_backtests_page(workspace_id: str | None = None) -> None:
)
with ui.card().classes(
"w-full rounded-2xl border border-slate-200 bg-white shadow-sm dark:border-slate-800 dark:bg-slate-900"
"w-full mt-4 rounded-xl border border-slate-200 bg-slate-50 p-4 shadow-none dark:border-slate-800 dark:bg-slate-950"
):
ui.label("Daily Results").classes("text-lg font-semibold text-slate-900 dark:text-slate-100")
ui.label("Daily Results").classes("text-md font-semibold text-slate-900 dark:text-slate-100 mb-2")
ui.table(
columns=[
{"name": "date", "label": "Date", "field": "date", "align": "left"},
{"name": "spot_close", "label": "Spot", "field": "spot_close", "align": "right"},
{"name": "low", "label": "Low", "field": "low", "align": "right"},
{"name": "high", "label": "High", "field": "high", "align": "right"},
{"name": "close", "label": "Close", "field": "close", "align": "right"},
{
"name": "net_portfolio_value",
"label": "Net hedged",
"field": "net_portfolio_value",
"name": "ltv_hedged",
"label": "LTV hedged",
"field": "ltv_hedged",
"align": "right",
},
{
"name": "ltv_unhedged",
"label": "LTV unhedged",
"field": "ltv_unhedged",
"align": "right",
},
{"name": "ltv_hedged", "label": "LTV hedged", "field": "ltv_hedged", "align": "right"},
{
"name": "margin_call_hedged",
"label": "Hedged breach",
"field": "margin_call_hedged",
"name": "margin_call",
"label": "Margin call",
"field": "margin_call",
"align": "center",
},
],
rows=[
{
"date": point.date.isoformat(),
"spot_close": f"${point.spot_close:,.2f}",
"net_portfolio_value": f"${point.net_portfolio_value:,.0f}",
"ltv_unhedged": f"{point.ltv_unhedged:.1%}",
"low": f"${point.spot_low:,.2f}",
"high": f"${point.spot_high:,.2f}",
"close": f"${point.spot_close:,.2f}",
"ltv_hedged": f"{point.ltv_hedged:.1%}",
"margin_call_hedged": "Yes" if point.margin_call_hedged else "No",
"margin_call": "Yes" if point.margin_call_hedged else "No",
}
for point in template_result.daily_path
],
@@ -1001,7 +988,9 @@ def _render_backtests_page(workspace_id: str | None = None) -> None:
ui.table(
columns=[
{"name": "date", "label": "Date", "field": "date", "align": "left"},
{"name": "spot", "label": "Spot", "field": "spot", "align": "right"},
{"name": "low", "label": "Low", "field": "low", "align": "right"},
{"name": "high", "label": "High", "field": "high", "align": "right"},
{"name": "close", "label": "Close", "field": "close", "align": "right"},
{
"name": "ltv_hedged",
"label": "LTV hedged",
@@ -1018,7 +1007,9 @@ def _render_backtests_page(workspace_id: str | None = None) -> None:
rows=[
{
"date": dp.get("date", ""),
"spot": f"${dp.get('spot_close', 0):,.2f}",
"low": f"${dp.get('spot_low', dp.get('spot_close', 0)):,.2f}",
"high": f"${dp.get('spot_high', dp.get('spot_close', 0)):,.2f}",
"close": f"${dp.get('spot_close', 0):,.2f}",
"ltv_hedged": f"{dp.get('ltv_hedged', 0):.1%}",
"margin_call": "Yes" if dp.get("margin_call_hedged") else "No",
}