Home · Guides · Backtest crypto perpetual futures in Python, with funding included
GUIDE · CRYPTO PERPETUALS · BACKTEST · CATALOG VERIFIED 2026-10-08
Backtest crypto perpetual futures in Python, with funding included
A perpetual-futures backtest is only realistic if it charges or pays funding while a position is open. AI Options Data Store sells 1-minute perpetual OHLC with mark price and the matching hourly funding-rate files for BTC, ETH, SOL, XRP, BNB, DOGE, ADA, AVAX, LINK, LTC and DOT as Parquet in UTC, so price and funding join on one clock.
Get the Top 10 crypto packBTC onlyFunding rate history Free sample (no email)
Download the sample → check the columns
Dates on this page are read from the live file catalog, not typed by hand. Full matrix: /coverage.
Example: trend rule on hourly bars, with funding and fees
Resample 1-minute closes to hourly, take the funding rate for each hour, shift the position one bar to avoid look-ahead, then add price return, funding and fees.
import pandas as pd
px = pd.read_parquet('ETHUSDT_PERP_FUT_1min_2025-01-01_2025-12-31.parquet').set_index('datetime')
fr = pd.read_parquet('ETHUSDT_PERP_FUNDING_FUT_1hour_<first>_<last>.parquet').set_index('datetime')
h = px['close'].resample('1h').last().dropna().to_frame('close')
h['rate'] = fr['funding_rate_pct_close'].reindex(h.index) / 100 # percent -> fraction
fast, slow = h.close.rolling(24).mean(), h.close.rolling(96).mean()
h['pos'] = ((fast > slow).astype(int) * 2 - 1).shift(1) # act on the next bar
SETTLE = [0, 8, 16] # assumed settlement hours (UTC); match your series
settle = h.index.hour.isin(SETTLE)
h['ret'] = h.close.pct_change() * h.pos
h['funding'] = (-h.pos * h.rate).where(settle, 0.0).fillna(0) # longs pay when rate > 0
h['fees'] = h.pos.diff().abs().fillna(0) * 0.0005 # assumed 5 bp per unit traded
h['net'] = h.ret.fillna(0) + h.funding - h.fees
print(h[['ret', 'funding', 'fees', 'net']].sum())
How the funding columns work
funding_rate_pct_* is the published funding rate in percent, stored as hourly open, high, low and close. Divide by 100 for a fraction. A positive rate means longs pay shorts.
Funding is exchanged at each settlement time of the series. Set SETTLE to the schedule of the series you test; the example assumes three settlements a day.
Mark price, gaps and many coins
Use mark_close rather than close for liquidation and margin checks; the mark columns are empty where no mark price was published.
Series start on different dates and some have short gaps; drop or flag hours with no bar instead of filling them.
To run every coin, loop over the files with glob and keep one frame per series; per-coin coverage is on the crypto historical data page.
Exactly which fields are in the files
Perpetual 1-minute files
| Column | Type | Meaning |
|---|---|---|
| datetime | timestamp (UTC) | Minute start, timezone-aware UTC (add 5:30 for IST) |
| open / high / low / close | float | Traded price OHLC of the perpetual in that minute |
| mark_open / mark_high / mark_low / mark_close | float | Mark-price OHLC for the same minute; empty where no mark price was published |
Funding-rate files (hourly)
| Column | Type | Meaning |
|---|---|---|
| datetime | timestamp (UTC) | Hour start, UTC |
| funding_rate_pct_open / _high / _low / _close | float | Published funding rate of the perpetual in percent, as hourly OHLC |
Not included: options, implied volatility, Greeks, order book or bid/ask, open interest, and spot (cash) prices.
Format: Parquet (1-minute perpetual and hourly funding files), UTC. The free BTC sample has a week of both.
FAQ
Where can I get crypto perpetual futures data with funding for backtesting?
AI Options Data Store sells 1-minute perpetual OHLC with mark price and hourly funding for BTC and ten more major coins as Parquet in UTC, paid by UPI. Free BTC and crypto samples need no email.
Why include funding in a perpetual backtest?
Holding a perpetual pays or receives funding at every settlement. Over weeks it can outweigh small trading edges, so leaving it out biases the result.
Should I use last price or mark price?
Last-price OHLC for signals and fills; mark price for liquidation and margin checks.
Which settlement schedule should I use?
The one of the series you trade. The files hold the published rate for every hour; apply it at that series' settlement hours.
Can I backtest on 1-minute bars directly?
Yes; the same logic works on 1-minute data. Hourly bars are faster for a first pass.
Does the data include open interest or order book?
No. OHLC, mark price and funding only.
Get the data
Free sample · Schema · Ask the AI for your data
Get the Top 10 crypto packBTC onlyFunding rate history Free sample
Related guides
- Bitcoin 1-minute historical data: what is in the files and how to load them
- Crypto funding rate history and 1-minute perpetual futures data
- Ethereum 1-minute historical data: ETH perpetual futures, funding and files
- XAU/USD 1-minute (M1) data: files, columns and how to get CSV
- XAU/USD session analysis: Asia, London and New York hours with 1-minute data
- Backtest an XAU/USD intraday strategy in Python with 1-minute data
- XAU/USD timeframes: resample 1-minute (M1) data to M5, H1, H4 and daily
- Crypto historical data, per coin
- All Crypto & XAU/USD packs
- Datasets index
Example code for research only; it is not trading advice.