Files
fxhnt/tests/integration/test_dashboard_service.py
jgrusewski d7a9c32690 feat(0b): retire crypto_tstrend standalone track + stablecoin_rotation (not tradeable on Bybit); book sleeve unchanged
Neither is tradeable on Bybit: crypto_tstrend as a standalone Binance-perp forward
track was a -0.21 marginal-Sharpe drag/crash-amplifier, and stablecoin_rotation's
FDUSD/USDP pairs aren't listed on Bybit. Removes the two *_nav assets, their
registry entries, the orphaned migration_builders builders, and the
Binance-only StableRotationForward wrapper (stablecoin_runner.py's
StableReversionRunner stays -- it's still live via the Bybit stablecoin eval
paths). The crypto_tstrend SLEEVE inside the bybit_4edge deploy book
(_DEFAULT_BYBIT_SLEEVES, Bybit data) is untouched.

Updates dependent tests: deletes 5 whose subject (the retired asset/registry
entry/module) no longer exists, and swaps the retired sid for a still-registered
one (unlock/xsfunding/sixtyforty) in tests that only used crypto_tstrend as a
generic example sid.
2026-07-13 21:56:23 +02:00

93 lines
4.1 KiB
Python

"""DashboardService turns DB rows into view-models: a fleet overview (registry joined to summary) and a
per-strategy detail (summary + nav history)."""
from __future__ import annotations
import datetime as dt
from fxhnt.adapters.persistence.forward_nav import ForwardNavRepo
from fxhnt.application.dashboard_service import DashboardService
from fxhnt.application.forward_models import BacktestSummary
from fxhnt.application.forward_models import ForwardNavRow as Row
from fxhnt.application.forward_models import ForwardSummary
def _seeded() -> ForwardNavRepo:
repo = ForwardNavRepo("sqlite://")
repo.migrate()
at = dt.datetime(2026, 6, 14, 23, 30)
repo.upsert_rows([Row("unlock", "2026-06-05", 0.01, 1.01),
Row("unlock", "2026-06-06", 0.0099, 1.0201)], at)
repo.upsert_summary(ForwardSummary("unlock", "2026-06-06", 2, 1.0201, 0.0201, 1.2, -0.01),
"WAIT", "2/20 forward days", at)
# a surviving track (xsfunding) carries a backtest verdict; a RETIRED one (eqfactor_long) has a
# leftover backtest-summary DB row but must NOT surface (fleet is registry-driven).
repo.upsert_backtest_summary(BacktestSummary(
"xsfunding", "2026-05-30", cagr=0.12, ann_vol=0.18, sharpe=0.85, max_drawdown=-0.22,
passed=True, dsr=0.61, is_sharpe=0.9, oos_sharpe=0.7, pvalue=0.03), at)
repo.upsert_backtest_summary(BacktestSummary(
"eqfactor_long", "2026-05-30", cagr=-0.01, ann_vol=0.11, sharpe=-0.05, max_drawdown=-0.31,
passed=False, dsr=-0.2, is_sharpe=0.1, oos_sharpe=-0.3, pvalue=0.6), at)
return repo
def test_fleet_joins_registry_to_summary() -> None:
svc = DashboardService(_seeded())
fleet = svc.fleet()
unlock = next(f for f in fleet if f.strategy_id == "unlock")
assert unlock.display_name.startswith("Token-unlock dilution shorts")
assert unlock.days == 2 and unlock.gate_status == "WAIT"
assert round(unlock.total_return_pct, 2) == 2.01
def test_fleet_includes_registry_entries_without_data() -> None:
svc = DashboardService(_seeded())
fleet = svc.fleet()
funding = next(f for f in fleet if f.strategy_id == "xsfunding")
assert funding.days == 0 and funding.gate_status == "WAIT" # no data yet -> shown, not errored
def test_detail_returns_summary_and_history() -> None:
svc = DashboardService(_seeded())
detail = svc.detail("unlock")
assert detail is not None
assert detail.display_name.startswith("Token-unlock dilution shorts")
assert [p.date for p in detail.history] == ["2026-06-05", "2026-06-06"]
def test_detail_includes_raw_period_aggregations() -> None:
svc = DashboardService(_seeded())
detail = svc.detail("unlock")
assert set(detail.periods) == {"daily", "weekly", "monthly"}
assert [p.label for p in detail.periods["daily"]] == ["2026-06-05", "2026-06-06"]
assert abs(detail.periods["daily"][0].ret - 0.01) < 1e-9 # raw, not normalized
assert all(p.label.startswith("2026") for p in detail.periods["monthly"])
def test_detail_unknown_strategy_is_none() -> None:
svc = DashboardService(_seeded())
assert svc.detail("does-not-exist") is None
def test_fleet_surfaces_backtest_verdict() -> None:
fleet = DashboardService(_seeded()).fleet()
el = next(f for f in fleet if f.strategy_id == "xsfunding")
assert el.bt_status == "PASS"
assert abs(el.bt_sharpe - 0.85) < 1e-9
assert abs(el.bt_dsr - 0.61) < 1e-9
assert abs(el.bt_cagr - 0.12) < 1e-9
assert abs(el.bt_maxdd - (-0.22)) < 1e-9
assert el.bt_as_of == "2026-05-30"
# eqfactor_long is retired from the registry (unproven); even though a backtest-summary row still
# exists in the DB, the fleet is registry-driven so the retired track is no longer surfaced.
assert all(f.strategy_id != "eqfactor_long" for f in fleet)
def test_fleet_no_backtest_renders_blank() -> None:
fleet = DashboardService(_seeded()).fleet()
unlock = next(f for f in fleet if f.strategy_id == "unlock")
assert unlock.bt_status == ""
assert unlock.bt_sharpe is None and unlock.bt_dsr is None
assert unlock.bt_cagr is None and unlock.bt_maxdd is None
assert unlock.bt_as_of == ""