strategy-fitness-heatmap
Skill3 starsChanged 4 months agoMITView on GitHub
Cross-strategy x ticker backtest fitness heatmap. By default reads the nightly backtest-pipeline's fitness_matrix.json + runs.jsonl (~instant, zero network) and emits one Sharpe-ratio matrix per interval (1d, 4h). Pass --fresh to instead recompute the grid live: every L3 strategy (from analysis.registry.l3_strategies) against every T1+T2 ticker (from the market-watchlist tier_1 / tier_2 baskets) through the backtest-engine walk-forward replay + deterministic FillSimulator. Rows=tickers, cols=strategies, cells=Sharpe. Use it to pick which strategy to run on which ticker, and to spot strategy/ticker mismatches.
In this repository47 other files it gives its agents.
- AGENTS.mdAGENTS.md
- beadsSkill
- backtest-engineSkill
- backtest-pipelineSkill
- backtest-trend-minerSkill
- bug-scanSkill
- daily-trade-pickSkill
- execution-kraken-perpsSkill
- execution-kraken-spotSkill
- l3-conviction-scanSkill
- market-accumulationSkill
- market-basisSkill
- market-breadthSkill
- market-breakoutSkill
- market-emaSkill
- market-exhaustionSkill
- market-fibonacciSkill
- market-liquidity-sweepSkill
- market-macdSkill
- market-macroSkill
- market-moversSkill
- market-notesSkill
- market-overviewSkill
- market-rsiSkill
- market-snapshotSkill
- market-squeezeSkill
- market-s-rSkill
- market-stateSkill
- market-trend-qualitySkill
- market-trendSkill
- market-valuationSkill
- market-volatilitySkill
- market-volumeSkill
- market-watchlistSkill
- portfolio-mgmtSkill
- position-watchdogSkill
- risk-engineSkill
- run-all-l2Skill
- run-all-l3Skill
- run-watchlistSkill
- strategy-accumulation-swingSkill
- strategy-breakout-confirmSkill
- strategy-exhaustion-fadeSkill
- strategy-funding-carrySkill
- strategy-liquidity-sweepSkill
- strategy-mean-reversionSkill
- strategy-trend-followSkill
The file
We split this skill into the rules it gives an agent
5 rules. About 0 are common, 1 is distinctive, and 4 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
4
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 99
No positional arguments - the skill loops over the full grid, it does not take a single ticker.
- Very specific: line 179
If fitness_matrix.json or runs.jsonl is absent or unreadable in the resolved artifact directory, the skill does not crash: it degrades to …
- Very specific: line 218
Check trade_count before trusting a Sharpe.
- Very specific: line 244
Add it to the tier_1 or tier_2 basket in the market-watchlist (skills/market-watchlist/data/watchlist.json).
- Very specific: line 278
When the artifacts are missing there, the skill falls back to the fresh grid and says so in errors / help rather than crashing.
≈ “Common” is an estimate: at least 1 in 5 of the 372,429 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
strategy-fitness-heatmap
Cross-strategy x ticker backtest fitness heatmap. One Sharpe matrix per
interval (1d, 4h), rows=tickers, cols=strategies.
Two sources, one output shape:
- Default — nightly artifacts. Reads the backtest-pipeline's
fitness_matrix.json(the precomputed Sharpe matrix; its own tickers/strategies lists and cell values — including JSONnullcells — are emitted verbatim) and enriches each combo'sdetailsfrom the latest run inruns.jsonl. ~instant, zero network. --fresh— live recompute. For every L3 strategy inanalysis.registry.l3_strategies()x every T1+T2 ticker from the market-watchlist basketstier_1andtier_2, runs thebacktest-enginewalk-forward replay + deterministicFillSimulator+computemetrics. Explicit--tickers/--strategiesoverrides also force a fresh run.
The matrix answers two questions at once:
- Which strategy fits which ticker? A row's highest cell is the strategy that back-tested best on that ticker for that interval.
- Which strategies are robust vs one-trick? A strategy with positive Sharpe across most tickers is robust; one that only wins on a single ticker is a specialist (and likely overfit).
Purpose
Pick a strategy for a ticker on evidence, not vibes. By default the heatmap
reads the nightly backtest-pipeline output (~instant, zero network) so the
agent (or the user) can read off the best (strategy, ticker, interval) combo
at a glance and then drill into the per-combo details for the stored
metrics (profit factor, max drawdown, trade count) plus the benchmark. Pass
--fresh to recompute the full L3 x T1+T2 grid live when the nightly
artifacts are stale, absent, or you need a custom ticker/strategy set.
When to use
- Choosing which L3 strategy to run live on a given ticker.
- Spotting tickers where every strategy underperforms buy-and-hold (don't trade there, or hold).
- Sanity-checking a newly shipped L3 strategy across the watchlist before
trusting it live (the nightly matrix only covers strategies the
backtest-pipeline runs — use
--freshfor anything newer). - Comparing 1d vs 4h fitness for the same (strategy, ticker) - a strategy that wins on 1d but loses on 4h (or vice versa) is timeframe-sensitive.
NOT to use
- Live signal generation - use the strategy skill's own
scripts/run.py. - Real execution -
FillSimulatoris a deterministic model, not a venue adapter; useexecution-kraken-spot/execution-kraken-perpsfor fills. - Drawing conclusions from a single Sharpe cell without checking
trade_countin the details - a Sharpe on 1-2 trades is small-sample noise (see the backtest-engine pitfalls doc). - Comparing absolute Sharpes across intervals without reading the
periods_per_yearnote below - 1d and 4h use different annualization factors so their Sharpes are directly comparable, but a 4h run on a thin alt may have far fewer bars than a 1d run on a major.
Quick Start
# Read the nightly matrix (default: ~instant, zero network). Reads
# $MARKET_SKILLS_BACKTEST_PIPELINE_OUT_DIR, falling back to ./data/backtest-nightly/:
uv run skills/strategy-fitness-heatmap/scripts/run.py --json
# Recompute the full grid live (all L3 strategies x tier_1 + tier_2, 1d + 4h):
uv run skills/strategy-fitness-heatmap/scripts/run.py --json --fresh
# Narrow the fresh grid for a quick check (implies --fresh):
uv run skills/strategy-fitness-heatmap/scripts/run.py --json --fresh \
--tickers BTCUSD ETHUSD --strategies strategy-trend-follow strategy-mean-reversion
# Human-readable matrix print (no --json):
uv run skills/strategy-fitness-heatmap/scripts/run.pyFlags
| Flag | Default | Notes |
--json | off | Emit the AXI envelope {"data", "count", "errors", "help"} instead of the human-readable matrix print. |
--fresh | off | Recompute the grid live (walk-forward + FillSimulator + network fetch) instead of reading the nightly artifacts. |
--tickers TICKER ... | tier_1 + tier_2 | Override the ticker list. Implies --fresh. Supports provider:ticker notation (e.g. hl:LIT). Pass once with multiple values. |
--strategies NAME ... | all L3 strategies | Override the strategy list (from analysis.registry.l3_strategies()). Implies --fresh. Useful for narrowing a slow run. |
No positional arguments - the skill loops over the full grid, it does not take a single ticker.
Output shape
The AXI envelope data payload (same shape both modes):
{
"intervals": {
"1d": {
"matrix": {"tickers": [...], "strategies": [...], "values": [[sharpe, ...], ...]},
"details": [{ticker, strategy, interval, sharpe, metrics, benchmark, trade_count, bars, error}, ...]
},
"4h": { "matrix": {...}, "details": [...] }
},
"strategies": [...],
"tickers": [...],
"config": {...mode-specific, see below...}
}matrix.valuesisrows=tickers, cols=strategies, cells=Sharpe-values[i][j]is the Sharpe oftickers[i]understrategies[j]. Cells can be JSONnullin both modes — the nightly mode emits them exactly as stored infitness_matrix.json, and the--freshpath emitsnullfor a bankrupted combo (equity curve went non-positive → its Sharpe isnull). In neither mode are they coerced to0.0.detailshas one entry per (ticker, strategy) combo per interval, carryingticker/strategy/interval/sharpe/trade_count/barsand anerrorfield that isnullon success. The rest depends on the mode:--fresh: the fullcomputemetrics dict (Sharpe, Sortino, max drawdown, profit factor, average trade, trade count, total/annualized return), the buy-and-holdbenchmarkmetrics, and anerrorcarrying the exception text / "fetch_ohlc returned no candles" / "insufficient candles" on failure.- default (nightly): the metrics stored in the latest
runs.jsonlrun, mapped onto the same field names —trades,strategy_sharpe,profit_factor,max_dd,benchmark_sharpe,bars,provider,insufficient_data, plusasof/ideas/windows/ total returns and themetrics/benchmarkdicts with the keys the nightly stores.erroris"insufficient_data"when the nightly flagged the combo, and"no result in latest nightly run"when the combo has no record in that run (then the enrichment fields arenull).
configis mode-specific and states its source truthfully:--freshemits{base_capital, fee_bps, slippage_bps, qty, intervals: {1d: {period, warmup, periods_per_year}, 4h: {...}}}; the default nightly mode emits{source: "nightly", env_var, generated_at, run_ts}(the pipeline's own backtest config is not fabricated here).
count at the envelope level is len(strategies) * len(tickers) * 2
(total combos across both intervals). errors carries the deduped per-combo
error strings (e.g. one "fetch_ohlc returned no candles" per missing ticker;
in nightly mode e.g. "insufficient_data" / "no result in latest nightly
run"), plus the fallback note when the nightly artifacts are missing and the
fresh grid was used instead.
Nightly vs fresh: expect different numbers
The default matrix comes from the nightly backtest-pipeline, which computes
each night's Sharpe with its own period/warmup and tracks it against a
rolling 7-night baseline. --fresh recomputes with the heatmap's own config
(1d = 2y lookback / 200-bar warmup, 4h = 1y / 500). A --fresh cell can
therefore legitimately differ from the nightly matrix cell for the same
(strategy, ticker, interval) — that is expected, not a bug.
The nightly strategies list can also differ from the registry: the
pipeline runs the whole L3 registry minus the declared
UNMEASURABLE_STRATEGIES map — six strategies today, all seven registry
entries except strategy-funding-carry, which the backtest cannot measure
(no perp funding data) — while --fresh uses all seven from
analysis.registry.l3_strategies(). See
ADR 0005. In the
default mode the file's own ticker/strategy lists are the source of truth —
the registry and watchlist are not consulted.
Missing-artifact fallback
If fitness_matrix.json or runs.jsonl is absent or unreadable in the
resolved artifact directory, the skill does not crash: it degrades to the
--fresh grid automatically and surfaces a note (e.g. "nightly
fitness_matrix.json not found — falling back to fresh grid") in errors
plus a help line pointing at running the backtest-pipeline or setting
MARKET_SKILLS_BACKTEST_PIPELINE_OUT_DIR.
Interpretation guide
Per strategy
| Strategy | Tends to fit | Watch out for |
strategy-trend-follow | Tickers with sustained directional moves (BTC, ETH in trending regimes). Daily timeframe preferred. | Choppy / range-bound alts - whipsaw entries, stop-out streaks. |
strategy-mean-reversion | Range-bound or high-variance tickers where overshoots revert. 4h swings. | Strong trends - fades a runner and keeps fading. |
strategy-breakout-confirm | Tickers with clean consolidation->expansion cycles (BTC, liquid majors). 1d confirmation. | False breakouts on thin alts - low volume confirms nothing. |
strategy-accumulation-swing | Tickers with visible accumulation footprints before mark-ups. 1d structure. | Tickers that never accumulate (continuous drift). |
strategy-exhaustion-fade | Tickers prone to climax/flush moves (low-float, perp-DEX). 4h. | Trending majors - exhaustion calls fire early and keep fighting the trend. |
strategy-funding-carry | Perp tickers with persistently negative/positive funding. Interval-agnostic. | Spot tickers (PAXGUSD) - no funding signal, expect 0 trades. |
strategy-liquidity-sweep | Tickers with liquidity-grab / stop-hunt behavior (alts on perp DEXes). 4h. | Gold/stable majors - not the sweep regime. |
Per interval
- 1d - trend-follow suitability. Daily bars smooth out intraday noise,
so directional strategies (
strategy-trend-follow,strategy-breakout-confirm,strategy-accumulation-swing) get a cleaner signal. A ticker whose 1d row lights up on trend-follow but not on 4h is a trend candidate on the daily timeframe. - 4h - mean-reversion / breakout suitability. The 4h timeframe captures
swing cycles and intraday liquidity moves where mean-reversion
(
strategy-mean-reversion,strategy-exhaustion-fade) and sweep (strategy-liquidity-sweep) patterns are more visible. A ticker whose 4h row beats its 1d row on mean-reversion is a swing-trade candidate.
Reading a cell
- Compare the strategy Sharpe to the
benchmarkSharpe in the same detail entry. Beating buy-and-hold after fees + slippage is the real bar; a strategy Sharpe of 1.2 looks different when the benchmark Sharpe is 2.0. - Check
trade_countbefore trusting a Sharpe. A Sharpe of 2.0 on 2 trades is noise; a Sharpe of 1.0 on 30 trades is signal. Thebacktest-enginepitfalls doc has the full small-sample Sharpe warning. - A row of zeros across all strategies usually means
fetch_ohlcreturned no candles (check theerrorfield indetails) - the ticker may be delisted, the provider may be down, or the interval/period combo may be unsupported for that ticker's provider. In the default nightly mode anullcell plays the same role: the pipeline had no valid Sharpe for that combo (run error or insufficient data) - check theerrorfield indetails. - A single zero in an otherwise populated row means the strategy's
analyze()raised on that candle set - read theerrortext for the exception.
How to update
Add a new L3 strategy
Register it in analysis/registry.l3_strategies() (append to _l3_strategies).
A --fresh run picks it up automatically - no edit to this skill is needed;
it gets a new column in both interval matrices. The nightly matrix only
gains the column once the backtest-pipeline includes the strategy in its
runs.
Add a new ticker
Add it to the tier_1 or tier_2 basket in the market-watchlist
(skills/market-watchlist/data/watchlist.json). A --fresh run reads
by_category("tier_1") + by_category("tier_2") programmatically, so the new
ticker gets a new row in both interval matrices with no edit here. The
nightly matrix gains the row once the backtest-pipeline picks up the basket.
For one-off checks without editing the watchlist, pass --tickers:
uv run skills/strategy-fitness-heatmap/scripts/run.py --json --tickers hl:NEWCOIN SOLUSDDeterminism
The default (nightly) mode is fully deterministic: it re-reads the same files until the pipeline rewrites them.
For --fresh: the FillSimulator is deterministic (next-bar-open entry,
stop-first intrabar tie, fixed fee_bps=26 / slippage_bps=2, qty=1.0),
and the walk-forward runner is cache-free and stateless across calls. So two
runs over the same candles produce identical Sharpe values. The only
non-determinism is the data fetch - once fetch_ohlc returns a candle set,
every downstream metric is reproducible. The config block in the output
pins the exact warmup / period / fee / slippage / qty used per interval so a
run is auditable.
Config
Nightly artifacts (default source)
| Env var | Required | Purpose |
MARKET_SKILLS_BACKTEST_PIPELINE_OUT_DIR | No | Directory holding the backtest-pipeline's fitness_matrix.json + runs.jsonl (defaults to data/backtest-nightly/ under the repo root). |
When the artifacts are missing there, the skill falls back to the fresh grid
and says so in errors / help rather than crashing.
Fresh-grid knobs (--fresh)
| Knob | 1d | 4h | Notes |
period | 2y | 1y | Lookback for fetch_ohlc. |
warmup | 200 | 500 | Bars skipped before emitting ideas. |
periods_per_year | 365 | 2190 | Sharpe annualization factor (bars/year). |
fee_bps | 26 | 26 | Kraken taker 0.26%. |
slippage_bps | 2 | 2 | Per-side slippage floor. |
qty | 1.0 | 1.0 | Position size in base units. |
base_capital | 100000.0 | 100000.0 | Equity-curve anchor for compute. |
periods_per_year is bar-aware so 4h Sharpes are annualized against 2190
bars/year (6 bars/day x 365) and 1d against 365 - this keeps the two
intervals' Sharpes directly comparable in absolute terms. The backtest-engine
default of 365 (daily convention) is used only for the 1d interval.
Architecture
- Default path reads the nightly backtest-pipeline artifacts
(
fitness_matrix.json+ latestruns.jsonlrun) fromMARKET_SKILLS_BACKTEST_PIPELINE_OUT_DIR, defaulting to the repo-relativedata/backtest-nightly/- zero network, ~instant. The env-var resolution andruns.jsonlparsing mirrorbacktest-trend-miner. The file's own tickers/strategies lists and cell values (includingnulls) are emitted verbatim; the details are enriched from the stored run metrics. --fresh(and the missing-artifact fallback) loads the strategies fromanalysis.registry.l3_strategies()- single source of truth shared withrun-all-l3.- Tickers come from
analysis.watchlist.by_category("tier_1")+by_category("tier_2")- the same watchlist the batch runners use. - Backtest engine is loaded with
analysis.skill_loader.load_skill("backtest-engine")and driven viaWalkForwardRunner,FillSimulator,compute, andbuy_and_hold_benchmark- the same API documented in the backtest-engine SKILL.md. - Candles are fetched once per (ticker, interval) and reused across all strategies, so the per-ticker network cost is paid twice (one per interval), not once per combo. The benchmark is likewise computed once per (ticker, interval) and reused across strategies.
- Output rides the AXI envelope (
analysis.output.emit_envelope_json), matching every other skill's--jsoncontract.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

