Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion scripts/run_walk_forward_backtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
)
DEFAULT_STORE_ROOT = Path("/tmp/crypto_wf_store")
DRIFT_BASELINE_HORIZON_DAYS = 126
CRYPTO_PERIODS_PER_YEAR = 365.25
CRYPTO_CALENDAR_ID = "CRYPTO_NATURAL_DAY"

PROFILE_DEFAULTS: dict[str, dict[str, Any]] = {
PROFILE_NAME: {"min_history_days": DEFAULT_MIN_HISTORY_DAYS, "top_n": 2, "rebalance_every": 7},
Expand Down Expand Up @@ -191,7 +193,12 @@ def _write_return_matrix(

def _baseline_from_return_tail(full_result: Any, returns: pd.Series) -> Any:
tail = returns.tail(DRIFT_BASELINE_HORIZON_DAYS)
metrics = compute_window_metrics(tail, window_days=DRIFT_BASELINE_HORIZON_DAYS)
metrics = compute_window_metrics(
tail,
window_days=DRIFT_BASELINE_HORIZON_DAYS,
periods_per_year=CRYPTO_PERIODS_PER_YEAR,
calendar_id=CRYPTO_CALENDAR_ID,
)
max_drawdown = float(metrics.max_drawdown)
cagr = float(metrics.cagr)
return replace(
Expand All @@ -206,6 +213,8 @@ def _baseline_from_return_tail(full_result: Any, returns: pd.Series) -> Any:
start_date=metrics.start_date,
end_date=metrics.end_date,
observation_count=metrics.observation_count,
periods_per_year=metrics.periods_per_year,
calendar_id=metrics.calendar_id,
)


Expand Down
4 changes: 4 additions & 0 deletions src/crypto_strategies/backtest/orchestrator_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
COMBO_DEFAULT_MIN_HISTORY_DAYS = 260
SUPPORTED_PROFILES = frozenset({PROFILE_NAME, CRYPTO_EQUITY_COMBO_PROFILE})
SYNTHETIC_PANEL_GENERATOR_VERSION = "crypto_live_pool_panel.v2"
CRYPTO_PERIODS_PER_YEAR = 365.25
CRYPTO_CALENDAR_ID = "CRYPTO_NATURAL_DAY"


def _synthetic_digest_int(*parts: str) -> int:
Expand Down Expand Up @@ -144,6 +146,8 @@ def _metrics_to_result(
source_script="crypto_strategies.backtest.orchestrator_runner",
computed_at=datetime.now(timezone.utc).isoformat(),
run_duration_seconds=run_duration_seconds,
periods_per_year=CRYPTO_PERIODS_PER_YEAR,
calendar_id=CRYPTO_CALENDAR_ID,
)


Expand Down
Loading