This repository contains a Python-based Transaction Cost Analysis (TCA) workflow for equity trades. It includes scripts to compute key trading metrics such as Arrival Slippage, Implementation Shortfall (IS), and Broker Ranking, along with a Jupyter notebook to orchestrate the analysis.
TCA_Project/
β
ββ database/ # SQLite database (tca.db) with trade data
ββ notebooks/ # Jupyter notebook: tca_metrics.ipynb
ββ tca/ # Python scripts for metrics
β ββ compute_slippage.py
β ββ compute_IS.py
β ββ compute_broker.py
ββ README.md
- Python 3.11+
- pandas
- sqlite3 (built-in with Python)
- Jupyter Notebook
- Optional: Anaconda for environment management
Install dependencies:
pip install pandas jupyter-
Set up the database
Place your SQLite database (tca.db) in thedatabase/folder. Ensure thetradestable exists with proper columns. -
Run the notebook
Launch the Jupyter notebook innotebooks/tca_metrics.ipynb.
Example:
from tca.compute_slippage import compute_arrival_slippage
from tca.compute_IS import compute_IS
from tca.compute_broker import compute_broker
# Compute arrival slippage for all trades
slippage_df = compute_arrival_slippage()
# Compute Implementation Shortfall
is_df = compute_arrival_slippage()
# Compute Broker Ranking
trades_df, broker_summary = compute_broker_rank()- Filter and analyze
You can filter the DataFrames in the notebook for specific symbols, sides, or date ranges.
- Arrival Slippage β measures execution price vs. arrival price
- Implementation Shortfall (IS) β measures execution price vs. decision price
- Broker Ranking β evaluates brokers based on slippage and IS
- Functions are designed to load from database if no DataFrame is provided.
- All functions return pandas DataFrames for flexible analysis in notebooks.
- You can expand with additional TCA metrics (VWAP slippage, market impact, venue analysis).
MIT License (or your preferred license)