A Streamlit app that estimates pre-trade transaction costs using a bid-ask spread model and a square-root market impact model (Almgren-Chriss simplified).
- Spread slippage + market impact cost breakdown
- Risk classification (Low / Medium / High / Very High)
- Actionable execution tips per risk level
- Scenario table: how slippage scales with order size
- Custom bid/ask/volatility overrides in sidebar
pip install -r requirements.txt
streamlit run app.pytransaction-slippage-estimator/
├── app.py # Streamlit UI
├── src/
│ ├── slippage_calculator.py # Spread & market impact models
│ └── risk_model.py # Risk classification & tips
├── utils/
│ └── helpers.py # Data loading & formatting
├── data/
│ └── *.csv # Put your CSV(s) here; app lets you pick one
├── tests/
│ └── test_slippage.py
└── requirements.txt
Preferred CSV includes these columns:
| Column | Description |
|---|---|
symbol |
Ticker symbol |
close |
Last close price |
bid |
Best bid |
ask |
Best ask |
avg_daily_volume |
Average daily share volume |
Optional: volume, open, high, low, market_cap
If your CSV has a different schema (e.g., NSE snapshots with LTP + VOLUME (shares)), the app will try to normalize it automatically by:
- mapping
LTP/PREV. CLOSEtoclose - mapping
VOLUME (shares)toavg_daily_volume - deriving
bid/askfromclosewhen missing
Spread Slippage = (ask - bid) / mid / 2 (one-way half-spread)
Market Impact = volatility × √(order_shares / ADV) (Almgren-Chriss square-root law)
Total Slippage = Spread + Market Impact
pytest tests/