Skip to content

PedroVBAmorim/kalshi-edge

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Kalshi Edge

Implied probability anomaly detection engine for Kalshi prediction markets. Scans live markets, computes Z-score deviation from category baselines, and surfaces ranked trading signals via REST API and Streamlit dashboard.


What it does

  1. Ingests all active Kalshi markets via REST API (auto-fallback to demo data)
  2. Computes a baseline probability for each market using historical category resolution rates + time-to-expiry correction
  3. Computes a Z-score: how many standard deviations is the market price from the data-derived baseline
  4. Flags OVERPRICED (Z > 2.0) and UNDERPRICED (Z < −2.0) markets
  5. Serves ranked signals via FastAPI and displays them on a Streamlit dashboard

File structure

kalshi_edge/
├── kalshi_client.py   # Kalshi API ingestion + fallback sample data
├── analytics.py       # Baseline computation, Z-scores, signal generation
├── main.py            # FastAPI: /health /markets /signals /summary
├── app.py             # Streamlit dashboard
├── requirements.txt
└── README.md

Run locally

1. Install dependencies

pip install -r requirements.txt

2. Start the API

uvicorn main:app --reload --port 8000

Test it:

curl http://localhost:8000/signals?min_z=2.0
curl http://localhost:8000/summary

3. Start the Streamlit dashboard

In a second terminal:

streamlit run app.py

Opens at http://localhost:8501


Demo-safe fallback mode

If Kalshi's API is unavailable during your demo, set:

USE_FALLBACK=true uvicorn main:app --reload
USE_FALLBACK=true streamlit run app.py

Or add USE_FALLBACK=true to a .env file. The app will load built-in sample data and remain fully functional.


API endpoints

Method Path Description
GET /health Status, uptime, cache state
GET /markets All markets with implied prob and volume
GET /signals?min_z=2.0&category=economics&direction=UNDERPRICED Anomaly signals ranked by |Z|
GET /summary Aggregate stats and category breakdown

Signal logic

baseline  = historical category resolution rate
            + time-decay correction (long/short-dated adjustment)

edge      = kalshi_mid_price − baseline_probability

z_score   = edge / category_historical_std

signal    = fired when |z_score| > 2.0

Category standard deviations are fixed constants set per category (see analytics.py). Baseline rates are fixed historical estimates per category (see kalshi_client.py).


Run in Zerve

  1. Create a new Zerve project
  2. Upload all six files (or paste them into the file editor)
  3. Open the Zerve terminal and run:
    pip install -r requirements.txt
    uvicorn main:app --host 0.0.0.0 --port 8000
    
  4. In a second Zerve process, run:
    streamlit run app.py --server.port 8501
    
  5. Zerve will expose both as public URLs — use these in your demo

If Kalshi API is blocked in Zerve's network: Add USE_FALLBACK=true to Zerve's environment variables.


Resume bullets

Quant / trading focus:

Built a market microstructure signal engine for Kalshi prediction markets: ingested live exchange data, computed Z-score deviations from category-derived probability baselines, and generated ranked OVERPRICED/UNDERPRICED signals via a REST API with 30-minute response caching.

Fintech SWE focus:

Designed and deployed a real-time anomaly detection API for prediction market data: Python ingestion layer with API fallback resilience, statistical signal generation (Z-score threshold = 2.0), FastAPI serving layer with four endpoints, and Streamlit dashboard with live category filtering.

Backend / data engineering focus:

Built end-to-end data pipeline from Kalshi REST API through statistical analysis to API deployment: robust price-format parsing (handles Kalshi's fixed-point and cents-integer formats), Pandas/NumPy analytics engine, FastAPI serving with in-memory caching, and Streamlit frontend — demo-safe fallback mode included.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages