How to backtest Hyperliquid strategies with vectorbt

Updated Nov 18, 2026 · 5 min read

Load Hyperliquid candles into vectorbt, sweep 780 moving-average pairs with the 0.045% taker fee and slippage, then test the winners on unseen data. Tested with vectorbt 1.2.1 on Nov 18, 2026.

How do you backtest Hyperliquid strategies with vectorbt? Pull candles from Hyperliquid’s public info API, build signals for a whole parameter grid at once with vbt.MA.run_combs, and simulate them with vbt.Portfolio.from_signals using fees=0.00045 (the 0.045% base-tier taker fee on crypto perps) and a slippage assumption. Then test the best parameters on data the sweep never saw. The script below ran on Nov 18, 2026 with vectorbt 1.2.1, numba 0.68.1 and Python 3.12.

Key takeaways

  • vectorbt tested 780 moving-average pairs on 5,000 Hyperliquid 4h candles in one run.
  • Two of the five best in-sample pairs lost money on the held-out months.
  • vectorbt places no orders, and leverage and limit orders are VectorBT PRO features (from $25 a month).

The sweep script

Hyperliquid’s info endpoint answers a candleSnapshot request with up to the most recent 5,000 candles per interval (Hyperliquid historical data). The script tests every simple-moving-average pair from 5 to 200 candles in steps of 5, fast shorter than slow: 780 pairs. Each goes long at 1x when the fast average crosses above the slow one and exits on the cross back; signals shift one candle so fills happen at the next open. Winners are picked on the first two thirds of the candles and tested on the last third.

python
# Pull Hyperliquid BTC 4h candles (public info API, no key), sweep 780 moving-average pairs in vectorbt with fees and
# slippage, pick the best on the first two thirds of the data and test them on the last third.
import json, time, urllib.request
import numpy as np
import pandas as pd
import vectorbt as vbt

FEES = 0.00045      # 0.045% per fill: Hyperliquid base-tier taker fee, crypto perps
SLIPPAGE = 0.0005   # 0.05% per fill: our assumption, not a Hyperliquid number

def fetch_candles(coin="BTC", interval="4h", bar_ms=4 * 3600 * 1000):
    now = int(time.time() * 1000)
    body = {"type": "candleSnapshot",
            "req": {"coin": coin, "interval": interval, "startTime": now - 5000 * bar_ms, "endTime": now}}
    req = urllib.request.Request("https://api.hyperliquid.xyz/info", json.dumps(body).encode(),
                                 {"Content-Type": "application/json"})
    df = pd.DataFrame(json.load(urllib.request.urlopen(req)))[["t", "o", "c"]].astype(float)
    df.columns = ["time", "open", "close"]
    df["time"] = pd.to_datetime(df["time"], unit="ms")  # UTC
    closed = df["time"] + pd.Timedelta(interval) <= pd.Timestamp.now("UTC").tz_localize(None)
    return df[closed].set_index("time")  # drop the candle still open

df = fetch_candles()
close, open_ = df["close"], df["open"]

# every fast/slow pair from 5 to 200 candles in steps of 5, fast < slow: 780 pairs
fast, slow = vbt.MA.run_combs(close, window=np.arange(5, 205, 5), r=2, short_names=["fast", "slow"])
# signal on a closed candle, fill at the next candle's open
entries = fast.ma_crossed_above(slow).shift(1, fill_value=False)
exits = fast.ma_crossed_below(slow).shift(1, fill_value=False)

def backtest(part):
    pf = vbt.Portfolio.from_signals(close[part], entries[part], exits[part], price=open_[part],
                                    fees=FEES, slippage=SLIPPAGE, init_cash=10_000, freq="4h")
    return pf.total_return()

split = close.index[len(close) * 2 // 3]
ins, oos = close.index < split, close.index >= split
r_in, r_out = backtest(ins), backtest(oos)
hold = lambda m: close[m].iloc[-1] / close[m].iloc[0] - 1
rank = r_out.rank(ascending=False).astype(int)

print(f"vectorbt {vbt.__version__} | pulled {pd.Timestamp.now('UTC'):%Y-%m-%d %H:%M} UTC: {len(close)} closed 4h candles | "
      f"{r_in.size} pairs | in-sample {close.index[0]:%Y-%m-%d %H:%M} to {close[ins].index[-1]:%Y-%m-%d %H:%M}, "
      f"out-of-sample {split:%Y-%m-%d %H:%M} to {close.index[-1]:%Y-%m-%d %H:%M} UTC")
print(f"buy and hold: in {hold(ins):+.1%}, out {hold(oos):+.1%} | median pair: in {r_in.median():+.1%}, "
      f"out {r_out.median():+.1%} | pairs beating buy and hold out of sample: {(r_out > hold(oos)).sum()}")
for pair in r_in.sort_values(ascending=False).index[:5]:
    print(f"top in-sample {pair}: in {r_in[pair]:+.1%} | out {r_out[pair]:+.1%}, rank {rank[pair]} of {r_out.size}")
Fast / slowIn-sample returnOut-of-sample returnOut-of-sample rank (of 780)
25 / 90+62.4%+17.3%75
150 / 175+62.2%-2.9%641
125 / 200+60.4%-3.7%655
20 / 90+59.8%+17.1%80
25 / 95+59.3%+12.9%195
Median of all 780+24.2%+6.9%n/a
Buy and hold BTC+22.7%-9.0%n/a
vectorbt 1.2.1, run at 21:53 UTC on Nov 18, 2026: the five best in-sample pairs, long only, 1x, 0.045% fee and 0.05% slippage per fill, Hyperliquid BTC perp 4h candles. In-sample Aug 7, 2024 to Feb 13, 2026; out-of-sample Feb 14 to Nov 18, 2026 16:00 UTC. Funding not included. Market data only; not a forecast or a trade signal.

Why the best backtest overfits

Picking the best of 780 results rewards luck: two of the top five lost money out of sample, ranking 641st and 655th. BTC fell 9% in the held-out months and 738 of the 780 long-only pairs beat holding it, so beating buy and hold there says little. Test several splits and markets and look at the spread of outcomes (how to backtest a crypto strategy, Monte Carlo backtests). Funding, which Hyperliquid pays every hour, is not included.

vectorbt vs VectorBT PRO

vectorbt (community)VectorBT PRO
LicenceApache 2.0 with Commons ClauseProprietary
PriceFree, from PyPI$25 a month, $225 a year or $500 lifetime
Leverage, limit ordersNoYes
Train/test splitsWrite your ownBuilt in
New data as it arrivesMainly backtests supplied arraysContinues a portfolio, keeping positions and stops
Sources: vectorbt README and LICENSE, vectorbt.dev, vectorbt.pro; checked Nov 18, 2026.

vectorbt’s CCXTData class downloads data, but vectorbt places no orders: to go live, rewrite the rule with CCXT or Hyperliquid’s hyperliquid-python-sdk, or move it to Freqtrade.

Or run the rule on Senpi

On Senpi, a strategy you confirm runs as code on Senpi’s runtime, and by default no AI model makes live trading decisions. Senpi doesn’t run backtests; Simulations, paper trading with simulated money, are coming. Hyperliquid charges 0.015% maker and 0.045% taker at the base tier on crypto perps. Senpi adds 0% on paid plans (from $50 a month) and 0.03% on the free trial.

How do I add fees and slippage in vectorbt?

Pass fees and slippage to Portfolio.from_signals as fractions per order, for example fees=0.00045 for Hyperliquid’s 0.045% base-tier taker fee. Slippage is your own assumption.

Is vectorbt free?

Yes, under Apache 2.0 with Commons Clause: free to use, but not to sell as a product or service that is primarily the software. VectorBT PRO costs from $25 a month (Nov 18, 2026).

Can vectorbt trade live on Hyperliquid?

No. Use it for research, then trade the rule with CCXT, Hyperliquid’s Python SDK or Freqtrade.

Sources: vectorbt on PyPI and GitHub, vectorbt.dev, vectorbt.pro; Hyperliquid docs (info endpoint, fees, funding); Freqtrade docs. Checked and run Nov 18, 2026.

This is educational material, not financial advice. Leveraged perps can lose money quickly.

Run a rule without a server

Describe the rule; Senpi runs it on its runtime with a stop from the first fill.

Try Senpi free
Share

Related articles