Skip to content

frogjo99/kalshi-backtest

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Kalshi Backtest

Strategy backtesting engine for Kalshi event contracts. Test your entry and exit rules against historical market data before risking real money. Get P&L curves, win rate, Sharpe ratio, and drawdown metrics.

Last updated: March 2026

What is Kalshi Backtest?

Kalshi Backtest is a historical simulation engine for Kalshi prediction market strategies. You define entry rules (price range, category, time to resolution), exit rules (take profit, stop loss), and position sizing - then replay those rules against downloaded Kalshi market history.

Before running any live bot, backtest tells you how the strategy performed on past data: which market categories worked, what edge threshold was realistic, how drawdowns looked, and whether the strategy was profitable after fees.


What You Can Test

  • Price-based entries - enter YES when price is between X and Y; exit at take-profit or stop-loss
  • Category filters - run strategies only on politics, economics, crypto, sports, or custom categories
  • Time-to-resolution windows - test entries made 7 days, 30 days, or 90 days before market close
  • Scale modes - fixed USD per trade, Kelly criterion sizing, or proportional portfolio sizing
  • Fee simulation - Kalshi settlement fees are deducted from winning trades automatically
  • Multi-strategy comparison - run several parameter sets and compare results side by side

Output Metrics

For each backtest run:

Metric Description
Total P&L Net USD gain/loss across all simulated trades
Win rate Percentage of trades that resolved in your favor
Sharpe ratio Risk-adjusted return (annualized)
Max drawdown Largest peak-to-trough loss in the period
Avg trade ROI Average return per closed trade
Trades per month Activity rate of the strategy
Best/worst category Which market categories drove performance

Two Ways to Run It

Windows App Python Engine
Setup Double-click pip install + config
Data Auto-download Bring your own CSV
Output Dashboard charts JSON + CSV
Config config.toml Direct code access
Comparison Built-in Script multi-run

Download

Platform Architecture Download
Windows x64 Download the latest release

Quick Start

# 1. Download from Releases
# 2. Run data download to fetch Kalshi market history
# 3. Edit config.toml - set strategy rules
# 4. Run Backtest - results print to dashboard

Python

cd kalshi-backtest/python
pip install -r requirements.txt
python kalshi-backtest-v.1.1.0.py --download-data
python kalshi-backtest-v.1.1.0.py --run

How It Works

kalshi backtest pipeline

Four stages:

  1. Download - fetches historical Kalshi markets and price snapshots via API
  2. Simulate - replays your entry/exit rules against each market chronologically
  3. Score - calculates per-trade P&L, fees, and aggregate metrics
  4. Report - outputs results to JSON, CSV, and optional equity curve chart

Config Reference

[strategy]
name = "politics_dip_buyer"

[entry]
categories = ["politics", "economics"]
yes_min = 0.20
yes_max = 0.45
min_days_to_resolution = 14
max_days_to_resolution = 180
usd_per_trade = 25
sizing_mode = "fixed"           # fixed | kelly | proportional

[exit]
take_profit_price = 0.75
stop_loss_price = 0.08
close_n_days_before_resolution = 3

[fees]
simulate_fees = true
kalshi_settlement_fee_pct = 7.0

[data]
start_date = "2023-01-01"
end_date = "2025-12-31"
data_dir = "data/history/"

[output]
results_dir = "data/results/"
export_csv = true
export_equity_curve = true

Results Format

{
  "strategy": "politics_dip_buyer",
  "period": "2023-01-01 to 2025-12-31",
  "total_trades": 214,
  "winning_trades": 138,
  "win_rate_pct": 64.5,
  "total_pnl_usd": 1842.30,
  "sharpe_ratio": 1.74,
  "max_drawdown_pct": 18.3,
  "avg_trade_roi_pct": 34.1,
  "trades_per_month": 7.4,
  "best_category": "politics",
  "worst_category": "economics",
  "fee_total_usd": 312.50
}

Example Backtest Output

Strategy: politics dip buyer (YES 0.20-0.45, $25/trade, 14-180 days to resolution)

Period: January 2023 - December 2025:

Metric Value
Total trades 214
Win rate 64.5%
Net P&L +$1,842.30
Sharpe ratio 1.74
Max drawdown -18.3%
Avg trade ROI 34.1%

Screen UI

Console

Frequently Asked Questions

What is Kalshi Backtest? Kalshi Backtest is a strategy simulation engine that replays your entry and exit rules against historical Kalshi market data. It produces win rate, P&L, Sharpe ratio, and drawdown metrics so you can evaluate a strategy before going live.

Where does the historical data come from? The engine downloads historical market data directly from the Kalshi API. Markets, price snapshots, and resolution outcomes are stored locally for offline replay. You can also supply your own CSV export.

How far back does the data go? Kalshi's API provides market data going back to early 2022 for most categories. Coverage is densest for politics, economics, and crypto markets. Sports market history is available from 2023 onward.

Does it account for Kalshi fees? Yes. The settlement fee (charged on winning positions) is deducted from each simulated winning trade. Configure the fee percentage in simulate_fees settings to match the current Kalshi fee schedule.

Can I compare multiple strategies at once? Yes. Define multiple strategy blocks in config and run with --compare. Results for each strategy are output side by side with a combined equity curve chart.

What is Kelly sizing mode? Kelly criterion calculates the optimal position size based on win probability and expected payout. In Kelly mode, the engine estimates win probability from historical data for each entry and sizes positions accordingly instead of using a fixed USD amount.

Is Kalshi Backtest available for Windows? Yes. A standalone Windows x64 application is included. The Python version runs on any platform with Python 3.10+.

Can I use the backtest results to configure my live trading bot? Yes. The output config from a backtest run can be used directly as input to kalshi-auto-trader. The same parameter format is shared across both tools.


Use Cases

  • Kalshi strategy backtesting - test entry and exit rules against 3 years of historical Kalshi market data
  • Prediction market strategy tester - evaluate probability range entries, time filters, and position sizing before going live
  • Kalshi win rate analysis - measure historical win rate by category, price range, and time to resolution
  • Sharpe ratio optimizer - compare dozens of parameter combinations and rank by risk-adjusted return
  • Kalshi fee impact analysis - see exactly how settlement fees affect net P&L across your strategy
  • Portfolio drawdown simulation - understand worst-case loss scenarios before deploying real capital

Repository Structure

kalshi-backtest/
+-- kalshi-backtest-v.1.1.0.exe
+-- config.toml
+-- data/
|   +-- history/
|   +-- results/
|   +-- charts/
|   +-- dll/
+-- python/
|   +-- src/
|   |   +-- downloader.py
|   |   +-- simulator.py
|   |   +-- scorer.py
|   |   +-- reporter.py
|   +-- requirements.txt
+-- README.md

Requirements

python-dotenv, typer[all], httpx, kalshi-python, pandas, numpy, matplotlib, devtools
  • Kalshi account with API access (for data download)

Test before you trade.

About

Strategy backtesting engine for Kalshi event contracts. Test your entry and exit rules against historical market data and get P&L curves, win rate, Sharpe ratio, and drawdown metrics before risking real money.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • Python 100.0%