Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Kalshi NBA Calibration Analysis

Quantitative research project analyzing pricing efficiency in Kalshi's NBA prediction markets. Tests whether market prices reflect true probabilities, identifies systematic biases, and simulates trading strategies that exploit miscalibration.

Over 1 million settled NBA markets analyzed, with full trade-level data for high-volume markets.


Findings

Calibration

The core question: when Kalshi prices a market at $0.80, does YES resolve 80% of the time?

Calibration Curve

Points above the diagonal = YES is underpriced (buy YES for edge). Points below = YES is overpriced (buy NO for edge). Error bars are 95% Wilson confidence intervals.

Favorite-Longshot Bias

Favorite-Longshot Bias

Classic bias from sports betting markets: longshots (low-probability outcomes) are systematically overpriced, while heavy favorites are underpriced. This is the primary exploitable edge.

Edge Per Price Bucket

Edge Per Bucket

Breaks down the calibration error (in cents per contract) across the full probability range. The dotted lines show the ~2¢ fee hurdle — buckets outside that range have tradeable edge.

Volume vs. Edge

Volume vs Edge

Whether edge is correlated with market liquidity. High-volume markets tend to be better calibrated; thin markets show larger deviations.

Time-Varying Calibration

Time Calibration Grid Edge by Time to Close Edge Convergence

How calibration evolves as markets approach settlement. Edge is generally larger farther from close and narrows as prices incorporate new information.

Recent vs. All-Time

All-Time vs Recent Recent 30 Days

Compares historical calibration against the most recent 30 days to check whether the edge is persistent or decaying.

Edge vs. Fees

Edge vs Fees

Visualizes gross edge against the fee threshold. Only the portion above the dashed line translates to real profit after Kalshi's ~2¢/contract fee.


Strategy

The strategy exploits the favorite-longshot bias:

  • BUY NO on longshots priced 20–35¢ (they resolve YES less often than priced)
  • BUY YES on heavy favorites priced 65–80¢ (they resolve YES more often than priced)

Backtest Results

P&L Curve Backtest P&L Monthly Backtest Risk vs Risk-Free

Strategy card summary:

Strategy Card

Backtest accounts for:

  • Kalshi fee: $0.02 per contract
  • Bid-ask spread: ~$0.01 per contract
  • Position sizing: flat $1 per trade

Edge Over Time

Edge Over Time

Tracks whether the strategy's edge has been stable, growing, or decaying over the dataset window.


Calibration Cuts

Chart Description
All markets
High-volume markets only
Low-volume markets only

Setup

pip install requests tqdm matplotlib numpy scipy pandas

Optional: Kalshi API credentials for higher rate limits (get API keys).

export KALSHI_API_KEY_ID="your-key-id"
export KALSHI_PRIVATE_KEY_PATH="path/to/private_key.pem"

Usage

# 1. Collect data (~10–30 min depending on rate limits)
python collect_data.py

# 2. Run core calibration analysis
python analyze_calibration.py

# 3. Generate all charts
python make_charts.py
python make_recent_charts.py

# 4. Backtest the strategy
python backtest.py

# 5. Scan all markets for current edges
python scan_all_markets.py

# 6. Run paper trader (live monitoring, no real money)
python paper_trader.py         # run once
python paper_trader.py --loop  # run every 30 min

Database Schema

The main database (kalshi_nba.db, ~11 GB, not included) has four tables:

Table Description
markets Every settled NBA market: ticker, title, result, last price, volume
events Parent events with category metadata
candlesticks Hourly OHLCV price history per market
trades Individual trade fills: price, size, timestamp, taker side

Interpreting Calibration Charts

  • Diagonal = perfect calibration
  • Above diagonal = YES underpriced → buy YES
  • Below diagonal = YES overpriced → buy NO
  • Error bars = 95% Wilson confidence intervals
  • Edge = cents of expected profit per $1 contract, before fees

The fee hurdle on Kalshi is roughly 2¢ per contract (varies by market). Only price buckets where the measured edge exceeds 2¢ are actionable.


Project Structure

collect_data.py         — Fetches all settled NBA markets + trade history from Kalshi API
explore_data.py         — Quick sanity checks on collected data
analyze_calibration.py  — Core calibration tests and edge estimation
backtest.py             — Historical strategy backtest with fee modeling
make_charts.py          — Comprehensive chart generation suite
make_recent_charts.py   — Charts using recent trade-level snapshots
scan_all_markets.py     — Fast scanner across all Kalshi market categories
paper_trader.py         — Live paper trading bot (no real money)
analysis_output/        — Generated PNG charts

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages