Metadata-Version: 2.4
Name: pnl-watchdog
Version: 0.6.1
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Rust
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Topic :: Office/Business :: Financial :: Investment
Classifier: Topic :: Scientific/Engineering :: Information Analysis
Classifier: Intended Audience :: Financial and Insurance Industry
Classifier: Intended Audience :: Developers
Requires-Dist: requests>=2.25.0
Requires-Dist: ccxt>=3.0.0
Requires-Dist: smartapi-python>=1.3.4
Requires-Dist: logzero
Requires-Dist: pyotp
Requires-Dist: websocket-client
Requires-Dist: numpy
Requires-Dist: scikit-learn
Requires-Dist: python-dateutil
Requires-Dist: aiohttp
Requires-Dist: alpaca-py
Summary: Infrastructure Economics Advisor: Measure Kyle's Lambda fairness gaps using Rust-accelerated calculations. Optimize trading strategy within broker latency constraints.
Keywords: trading,execution,fairness,kyle-lambda,market-microstructure,infrastructure-economics,rust,quantitative-finance
Home-Page: https://github.com/sohammirajkar/pnl_watchdog
Author-email: Soham Mirajkar <b25bs1197@iitj.ac.in>
Requires-Python: >=3.7
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
Project-URL: Homepage, https://github.com/sohammirajkar/pnl_watchdog
Project-URL: Repository, https://github.com/sohammirajkar/pnl_watchdog
Project-URL: Documentation, https://github.com/sohammirajkar/pnl_watchdog#readme
Project-URL: Bug Tracker, https://github.com/sohammirajkar/pnl_watchdog/issues
Project-URL: ArXiv Paper, https://arxiv.org/abs/coming-soon
Project-URL: Research, https://github.com/sohammirajkar/pnl_watchdog/tree/main/research

# 🐶 PnL Watchdog: Infrastructure Economics Advisor

**Measure the hidden cost of your execution. Optimize your strategy within broker constraints.**

Your broker shows you filled orders. But are you getting the same prices as institutions?

**No.** You're paying a latency tax. Every single trade.

pnl-watchdog measures **Kyle's Lambda fairness gaps** between retail and institutional execution using **Rust-accelerated calculations**—then shows you exactly how much that gap costs you and how to trade profitably within it.

**Stop fighting latency. Start optimizing around it.**

## 🚀 Key Features

- **Kyle's Lambda Calculator**: Measure price impact per signed volume (Rust-accelerated)
- **Fairness Audit**: Compare retail vs institutional execution costs
- **AI Anomaly Detection**: Catch unusual latency/slippage patterns
- **Smart Order Routing**: Get broker recommendations based on real-time performance
- **Privacy First**: No strategy exposure—only anonymous telemetry

## ⚡ Performance: Powered by Rust

| Operation | Rust | Python | Speedup |
|-----------|------|--------|---------|
| Kyle's Lambda (10k candles) | 0.1ms | 50ms | **500x faster** |
| Fairness Audit (5 samples) | 100ms | 1-2s | **20x faster** |
| Batch Processing (1000 symbols) | 100ms | 50s | **500x faster** |

## 📦 Installation

```bash
pip install pnl-watchdog
```

## 🎯 Quick Start

```python
from pnl_watchdog import PnLWatchdog

# Initialize with your broker credentials
dog = PnLWatchdog(
    broker="alpaca",
    api_key="YOUR_API_KEY",
    api_secret="YOUR_SECRET_KEY"
)

# Verify a trade
result = dog.check_order("AAPL", "buy", 10)
print(f"Trade verified in {result['latency_ms']}ms")

# Calculate Kyle's Lambda for market analysis
from pnl_watchdog import calculate_whale_metrics

opens = [100.0, 101.0, 102.0, 101.5, 100.5]
closes = [101.0, 102.0, 101.5, 100.5, 101.0]
volumes = [1000.0, 2000.0, 1500.0, 500.0, 1200.0]

amihud, kyles_lambda = calculate_whale_metrics(opens, closes, volumes)
print(f"Kyle's Lambda: {kyles_lambda}")
```

## 📊 Advanced Analytics

```python
# Get institutional order flow metrics
from pnl_watchdog import calculate_order_flow_metrics

prices = [100.0, 101.0, 102.0, 101.5, 100.5]
volumes = [1000.0, 2000.0, 1500.0, 500.0, 1200.0]
bids = [99.9, 100.9, 101.9, 101.4, 100.4]
asks = [100.1, 101.1, 102.1, 101.6, 100.6]

vwap_dev, tox, nof, obi, vwap = calculate_order_flow_metrics(prices, volumes, bids, asks)
print(f"Toxicity Score: {tox}")
print(f"VWAP: {vwap}")
```

## 🤝 Supported Brokers

- Alpaca
- Interactive Brokers
- Binance (and other CCXT-supported exchanges)
- Zerodha
- Angel One

## 📚 Documentation

- [Infrastructure Economics Guide](https://github.com/sohammirajkar/pnl_watchdog/blob/main/docs/ECONOMICS.md)
- [Performance Benchmarks](https://github.com/sohammirajkar/pnl_watchdog/blob/main/docs/PERFORMANCE.md)
- [API Reference](https://github.com/sohammirajkar/pnl_watchdog/wiki)

## 📞 Support

For issues, feature requests, or questions, please [open an issue](https://github.com/sohammirajkar/pnl_watchdog/issues) on GitHub.

