Realistic fixed-price grid backtester for crypto (or any OHLCV series). Built for honest simulation: no free high/low round-trips, cash-consistent fees, inventory risk limits, and full performance reports.
Works with any Binance spot pair (ETH, BTC, SOL, …) via a free public downloader, or with your own CSV data.
| Area | What you get |
|---|---|
| Execution models | A optimistic · B conservative (default) · C intrabar path |
| Costs | Maker/taker fees, spread, slippage |
| Risk | Max open positions, capital deployed, exposure %, cash reserve |
| Speed | O(log N) grid touch detection (binary search on levels) |
| Outputs | Equity curve, trades, daily returns, JSON summary, diagnostic charts |
| Data | Binance Vision monthly klines or any OHLCV CSV |
git clone https://github.com/tauseedzaman/Fixed-Grid-Backtester.git
cd Fixed-Grid-Backtester
python -m venv .venv
# Windows
.venv\Scripts\activate
# macOS / Linux
source .venv/bin/activate
pip install -r requirements.txt# Ethereum 1-minute (legacy layout: ETHUSDT_1m_data/)
python download_eth_1m.py --start 2024-01 --end 2024-12
# Or any symbol / interval
python download_binance.py --symbol BTCUSDT --interval 1m --start 2024-01 --end 2024-12
python download_binance.py --symbol SOLUSDT --interval 5m --start 2023-01 --end 2025-06Data lands under:
{SYMBOL}_{INTERVAL}_data/
zips/ # monthly archives
extracted/ # YYYY-MM/*.csv ← point --data_dir here
Examples: ETHUSDT_1m_data/extracted, BTCUSDT_1m_data/extracted.
# ETH defaults (grid 1500–4000, $20 spacing)
python backtester.py \
--data_dir ETHUSDT_1m_data/extracted \
--start 2024-01-01 --end 2024-06-01 \
--mode B \
--output_dir results/eth_2024h1
# Bitcoin — set grid to BTC’s price range
python backtester.py \
--data_dir BTCUSDT_1m_data/extracted \
--start 2024-01-01 --end 2024-06-01 \
--lower 30000 --upper 75000 --spacing 250 --size 100 \
--mode B \
--output_dir results/btc_2024h1Any file with timestamp, open, high, low, close (and optional volume):
python backtester.py \
--csv path/to/my_ohlcv.csv \
--start 2024-01-01 --end 2024-03-01 \
--lower 100 --upper 200 --spacing 2 \
--output_dir results/customTimestamps may be ISO strings or Unix epoch (seconds / ms / µs). Binance headerless kline CSVs are also accepted.
Data
--data_dir PATH Folder of CSVs (Binance monthly layout or flat)
--csv PATH Single OHLCV file (overrides --data_dir)
--start / --end Inclusive date filter (YYYY-MM-DD)
--output_dir PATH Where to write results (default: results/)
Grid
--lower --upper Buy-level range (quote currency)
--spacing Distance between levels
--size Quote notional per level
--capital Starting cash
Execution
--mode A|B|C Optimistic / Conservative / Intrabar
--maker_fee --taker_fee --slippage --spread
--taker_grid Charge taker fee on grid fills
Risk
--max_open_positions
--max_capital_deployed
--min_cash_reserve
--max_exposure_pct
Other
--snapshot_every N Equity sample rate (use 60 for multi-year runs)
--no_charts --no_progress --no_force_close
Full list: python backtester.py -h
Grid backtests often cheat by using both the bar high and low in the best order, inventing free round-trips that never happened.
| Mode | Path idea | Use when |
|---|---|---|
| A – Optimistic | Visits high then low after open | Upper-bound research only |
| B – Conservative (default) | Only the wick in the open→close direction | Honest baseline |
| C – Intrabar | Colour-conditional full path (O-L-H-C / O-H-L-C) | Common engine heuristic |
Prefer mode B for claims about live edge.
Win rate will often look “too high” (~90–99%). That is structural for a fixed grid:
- A normal cycle only closes when price recovers to buy + spacing → small win by construction.
- Real risk sits in open inventory until price returns or the run force-closes lots at the end (usually the bulk of losses).
Trust net profit, max drawdown, profit factor, expectancy, Sharpe more than win rate.
backtester.py # CLI + data load + simulator orchestration
download_binance.py # Any symbol/interval from Binance Vision
download_eth_1m.py # Thin ETHUSDT 1m convenience wrapper
exchange.py # Fees, spread, slippage fills
execution.py # Modes A/B/C price paths
grid_strategy.py # Level generation + O(log N) crosses
portfolio.py # Cash, inventory, risk limits
position.py # Position / trade records
metrics.py # Risk & performance stats
plotting.py # Diagnostic charts
grid_backtest.py # Legacy alias → backtester.main
requirements.txt
LICENSE
Market data and result CSVs/images are not in the repo (see .gitignore). Generate them locally.
# 1) Fetch
python download_binance.py --symbol ETHUSDT --interval 1m --start 2023-01 --end 2024-12
python download_binance.py --symbol BTCUSDT --interval 1m --start 2023-01 --end 2024-12
# 2) Backtest ETH
python backtester.py \
--data_dir ETHUSDT_1m_data/extracted \
--start 2023-01-01 --end 2024-01-01 \
--lower 1000 --upper 4000 --spacing 20 --size 50 \
--snapshot_every 60 --output_dir results/eth_2023
# 3) Backtest BTC
python backtester.py \
--data_dir BTCUSDT_1m_data/extracted \
--start 2023-01-01 --end 2024-01-01 \
--lower 15000 --upper 50000 --spacing 200 --size 100 \
--snapshot_every 60 --output_dir results/btc_2023This is research software. Past simulated performance is not indicative of future results. Fees, latency, partial fills, and exchange rules in live markets can differ from the model. Use at your own risk.
MIT — see LICENSE.