How to backtest a crypto trading strategy without fooling yourself
Updated Nov 12, 2026 · 12 min read
A step-by-step way to backtest a crypto strategy on Hyperliquid data: the costs that kill small edges (fees, funding, slippage), lookahead and survivorship bias, overfitting, out-of-sample, walk-forward and Monte Carlo tests, with order-book and funding numbers from Nov 10, 2026.
How do you backtest a crypto trading strategy? Write the rules down so precisely that a computer can follow them, run them over past prices, and charge every simulated trade what it would have cost: exchange fees, funding for every hour a position was open, and slippage on each fill. Then test the same rules on data you didn’t use to build them. Most backtests that look good fail one of those steps: they peek at data the strategy couldn’t have known, test only the coins that survived, leave out costs, or tune the rules until they fit the past.
Key takeaways
- A backtest is only as honest as its costs. On Hyperliquid, taker fees are 0.045% a side at the base tier on crypto perps, so a round trip costs 0.09% before slippage and funding.
- Slippage depends on the market: at 23:27 UTC on Nov 10, 2026, a $10,000 market buy cost 0.2 bps on BTC but 11.3 bps on CC.
- Survivorship bias is real on Hyperliquid: 56 of the 235 markets in its main perp listing are delisted. A test on today’s list skips them.
- Split the history: build the rules on one part, test them on a part you never touched, then run them small before you run size.
- One backtest is one path. Monte Carlo resampling shows the range: BTC’s actual 44.7% drawdown over the last year was milder than 59% of 10,000 reshuffled versions of the same year.
Backtest a crypto strategy, step by step
- 01Write the rules. Entry, exit, stop, size and the markets it trades, with no room for judgement. If you can’t write it in a sentence or two, a script can’t run it either.
- 02Get the data. Hyperliquid’s free info API returns candles (the most recent 5,000 per market and interval: about 208 days of hourly candles, or every daily candle since the market listed) and hourly funding history. Include markets that have since been delisted, if you can get their history.
- 03Model the costs. Fees at the tier you will actually trade, funding for every hour held, and slippage from the order book for your size (tables below).
- 04Simulate fills honestly. Act on the next candle after a signal, not the candle that produced it, and when a stop and a target fall inside the same candle, assume the stop filled first.
- 05Split the data. Build on the first part (in-sample), then run the finished rules once on the rest (out-of-sample). Better still, walk forward: re-fit on a rolling window and test on the period after it.
- 06Judge the result on profit factor, max drawdown, the Calmar ratio and the number of trades, against simply holding the market.
- 07Run it small. Live trading adds what a backtest can’t: queue position, partial fills and your own reactions. Start with a size you can afford to be wrong with.
Where Senpi fits
Senpi doesn’t run backtests for you; Simulations, paper trading with simulated money, are coming. Until then, you can write and run one with an AI coding assistant such as Claude or ChatGPT; How to use AI for quant trading strategies walks through it, including the checks above. Some templates in the open-source senpi-skills library cite a historical replay in their notes; read that as the author’s evidence, and test it yourself.
When the rules hold up, describe them to your Senpi agent, in the app or from Claude or ChatGPT through Senpi Connectors. The agent asks about one decision at a time and reads the full rules back to you to confirm before it writes any code. Entries go maker-first, with a taker fallback; stops fill as market orders and pay the taker fee, so charge every stop-out at the taker rate in your test. On Senpi, a strategy you confirm runs as code on Senpi’s runtime, and by default no AI model makes live trading decisions. Strategies built from a rule or a template carry the Dynamic Stop-Loss (DSL) from the first fill, and each can have its own daily-loss halt, which lifts at the next UTC midnight, or a drawdown halt, which waits until you resume it. Copy strategies carry at most a flat stop. Each strategy trades from its own strategy wallet; the agent holds no key and cannot withdraw.
The costs to put in every backtest
| Cost | On Hyperliquid | How to model it |
|---|---|---|
| Exchange fee | 0.015% maker and 0.045% taker at the base tier on crypto perps; lower at higher volume tiers | Charge every simulated fill, at the fee for the order type the rule would use |
| App fee | Senpi: 0% on paid plans, 0.03% on the free trial or without a paid plan | Add it to the exchange fee if you trade through an app that charges one |
| Funding | Paid every hour on the position’s size at the oracle price. BTC averaged 9.2% a year, paid by longs, over the 90 days to Nov 9, 2026 | Charge each open hour at that hour’s rate. At 9.2% a year, a BTC long held for a week pays about 0.18% of its size |
| Slippage | Depends on the market and your size (next table) | Walk the order book for your size, or add a fixed cost per fill per market |
| Spread | The gap between the best bid and ask | A market order pays half of it; a limit order may not fill |
Costs decide whether a small edge survives. A rule that makes two round trips a day with taker orders pays 4 × 0.045% = 0.18% of the position a day in fees alone, about 66% a year at 1x. On a market like CC, where a $10,000 market order cost 11.3 bps at the snapshot, the same rule gives away about 0.63% a day. The full fee schedule, with volume tiers and discounts, is in Hyperliquid fees explained.
Slippage: what a market buy cost at the snapshot
| Market | Open interest | Spread | $10K buy | $100K buy | $1M buy |
|---|---|---|---|---|---|
| BTC | $3.00B | 0.4 bps | 0.2 bps | 0.3 bps | 0.3 bps |
| ETH | $1.59B | 0.5 bps | 0.2 bps | 0.2 bps | 0.9 bps |
| SOL | $389M | 0.1 bps | under 0.1 bp | 0.9 bps | 2.8 bps |
| HYPE | $1.54B | 0.1 bps | 0.5 bps | 3.9 bps | 8.7 bps |
| XPL | $37M | 2.9 bps | 4.8 bps | more than the book showed | more than the book showed |
| CC | $5.2M | 2.7 bps | 11.3 bps | more than the book showed | more than the book showed |
Seven ways a backtest fools you
| Mistake | What it looks like | The fix |
|---|---|---|
| Lookahead bias | Entering at a candle’s close on a signal from that same close; using the day’s high to set an intraday stop | Act only on data available at the moment of the decision, usually from the next candle |
| Survivorship bias | Testing only the markets listed today, which skips the 56 Hyperliquid has delisted from its main market | Include delisted markets and test the rule on the whole universe it would have traded |
| Leaving out costs | Fees, funding and slippage set to zero | Charge all three, at the tier and size you will trade |
| Overfitting | Many tuned parameters; an equity curve that looks too smooth | Use few parameters, and check that nearby values work almost as well |
| Too few trades | A strong result from a couple of dozen trades | Get enough trades to tell skill from luck: hundreds are better than dozens |
| One market regime | Tested only in a bull market, or only in a range | Test across trends, ranges and crashes, and across several markets |
| Unrealistic fills | Every limit order filling; stops filling exactly at their trigger | Fill limit orders only when the price trades through them; add slippage to stops |
In-sample, out-of-sample and walk-forward testing
In-sample data is what you build and tune the rules on. Out-of-sample data is history you keep back and use once, at the end, to see whether the rules still work. If you go back and tune after looking at the out-of-sample result, it becomes in-sample. Walk-forward testing repeats the split: fit on a rolling window, such as a year, test on the next quarter, move forward and repeat. A rule that only works in-sample has learned the noise of the past.
- 01Pick the windows. For example, tune on 12 months and test on the 3 months that follow. Hyperliquid’s 5,000-candle limit gives about 208 days of hourly candles, so hourly strategies need shorter windows or data you collect yourself.
- 02Tune, then freeze. Choose the parameters on the in-sample window only, and don’t touch them during the test window.
- 03Roll forward. Move both windows on by the length of the test window and repeat until you reach today.
- 04Judge the stitched result. Join the out-of-sample pieces into one equity curve. That curve, not the in-sample one, is your backtest.
- 05Compare the two. If the out-of-sample results are far worse than the in-sample ones, the tuning found noise.
Monte Carlo: how bad could the drawdown have been?
A backtest gives you one equity curve, but the same trades in a different order would have produced a different drawdown. A Monte Carlo test resamples your trades, or daily returns, thousands of times and records the max drawdown of each version. The spread of results is a better guide to what you might sit through than the single number your backtest printed. Plan for the bad tail, not the median.
| Market (buy and hold) | Actual max drawdown | Median of 10,000 runs | Worst 5% of runs | Best 5% of runs | Runs worse than actual |
|---|---|---|---|---|---|
| BTC | −44.7% | −48.0% | −71.1% | −26.1% | 59% |
| ETH | −56.1% | −60.6% | −82.4% | −34.7% | 61% |
| SOL | −62.8% | −65.2% | −85.3% | −38.1% | 56% |
| HYPE | −49.3% | −53.9% | −78.6% | −34.0% | 62% |
BTC’s actual path fell 44.7% from its peak, but in the worst 5% of reshuffled years the same daily moves produced a drawdown of 71.1% or more. Simple resampling treats every day or trade as independent, which breaks up losing streaks and calm and wild spells; resampling blocks of consecutive days or trades keeps more of that structure.
import numpy as np
def monte_carlo_drawdowns(trade_returns, runs=10_000, seed=42):
"""Resample per-trade returns (fractions of equity, after costs) to see the range of max drawdowns."""
rng = np.random.default_rng(seed)
r = np.asarray(trade_returns, dtype=float)
sims = rng.choice(r, size=(runs, len(r)), replace=True) # draw trades with replacement
equity = np.hstack([np.ones((runs, 1)), np.cumprod(1 + sims, axis=1)])
max_dd = (equity / np.maximum.accumulate(equity, axis=1) - 1).min(axis=1)
worst_5, median, best_5 = np.percentile(max_dd, [5, 50, 95])
return {"worst 5%": round(float(worst_5), 3), "median": round(float(median), 3), "best 5%": round(float(best_5), 3)}
# trades = your backtest's trade log, e.g. [0.012, -0.006, 0.031, -0.009, ...]
# print(monte_carlo_drawdowns(trades))How to judge the result
- Profit factor above 1 means the winners outweigh the losers after costs; profit factor explained.
- Max drawdown is the deepest fall from a peak; decide in advance the drawdown you would actually sit through (max drawdown explained).
- Calmar ratio divides the yearly return by the max drawdown, so you can compare strategies with different risk (Calmar ratio explained).
- Against buy-and-hold: a strategy that makes less than holding the market, with a deeper drawdown, isn’t worth running.
- Stability: small changes to the parameters should change the result a little, not flip it.
What is backtesting in crypto trading?
Running a fixed set of trading rules over past price data to see how they would have performed, with every simulated trade charged its fees, funding and slippage. It tests whether a rule had an edge in the past; it can’t promise the edge continues.
How much historical data do you need to backtest?
Enough to produce many trades across different market conditions: trends, ranges and at least one sharp fall. Hyperliquid’s API returns the most recent 5,000 candles per market and interval, which is about 208 days of hourly candles or every daily candle since a market listed.
What is overfitting in backtesting?
Tuning a rule so closely to past data that it captures the noise rather than a real pattern. Signs are many parameters, a very smooth equity curve, and results that collapse when a parameter changes slightly or when the rule runs on new data.
What is walk-forward testing?
Repeatedly building the rules on one window of history and testing them on the period right after it, then moving both windows forward. It shows whether the rule keeps working on data it wasn’t built on.
What is a Monte Carlo backtest?
A test that reshuffles or resamples a strategy’s trades, or its daily returns, thousands of times to see the range of results the same edge could have produced. It shows how deep a drawdown you should plan for, instead of trusting the single equity curve the backtest printed.
How many Monte Carlo simulations do you need?
Usually 1,000 to 10,000. Run it twice with different seeds: if the 5th-percentile drawdown barely moves, you have enough runs. More runs can’t fix a short trade history, though; with few trades, the range itself is unreliable.
Can ChatGPT or Claude backtest a trading strategy?
They can write and run the code for a backtest if you give them the rules and the data, which is a fast way to test an idea. Check the code for lookahead bias and missing costs, because those are the mistakes it most often makes, and test on data the rules weren’t built on.
Does Senpi backtest strategies?
Senpi doesn’t run backtests for you; Simulations, paper trading with simulated money, are coming. Some templates in the open-source senpi-skills library cite a historical replay in their notes. Senpi runs the rules you confirm live, each strategy in its own strategy wallet, so a common route is to test elsewhere and then run small on Senpi.
Does a good backtest mean a strategy will make money?
No. It means the rules would have made money on that history with those cost assumptions. Markets change, edges fade as more traders find them, and live fills differ from simulated ones, so start small.
This page explains how to test a trading strategy on historical data. It is not financial advice, and the market readings are data, not trade signals. Leveraged perps can lose money quickly.
Run your tested rules with an AI agent
Describe the rules in a sentence. Senpi reads them back to you to confirm before anything runs, then trades them in a separate strategy wallet with the stop attached from the first fill. Simulations, paper trading with simulated money, are coming.
Related articles
What is revenge trading, and how do you stop it?
Revenge trading is trading bigger or faster to win back a loss. Why it happens, the recovery maths that makes it costly, what Hyperliquid data shows, and rules that stop it.
What is the Calmar ratio, and what is a good one?
The Calmar ratio divides annual return by max drawdown. Formula, how to read it, and the one-year Calmar ratio of BTC, ETH, SOL, HYPE, XRP and DOGE on Nov 9, 2026.
17 crypto trading strategies explained: momentum, mean reversion, breakout, carry, DCA, grid and more
17 crypto trading strategies, from the five core families (momentum, mean reversion, breakout, carry, market making) to day trading, DCA, grid and copy trading: the edge each trades, when it fails, the Senpi templates that run them, and live Hyperliquid readings on Nov 9, 2026.
How to read Hyperliquid market data: open interest, long/short ratio, funding and liquidations
What open interest, the long/short ratio, funding and liquidations tell you on Hyperliquid, where each number comes from, and how to read them together, with the ten largest perps on Nov 10, 2026.