Update README.md

This commit is contained in:
Immanuel Edunsin
2025-07-23 18:02:40 +01:00
committed by GitHub
parent ed3e63180c
commit dc1cc1b2eb
+94 -23
View File
@@ -1,28 +1,99 @@
# FX Arbitrage Dashboard
# FX Arbitrage Dashboard ⚖️
A Streamlit-based dashboard for monitoring covered interest parity (CIP) deviations and simulating P&L for FX arbitrage strategies in real time.
Realtime FX CIP arbitrage signals with PnL simulation, equity curve, and Slack alerts.
## 🚀 Features
## Key features
- **Live Spot & Forward Rates**: Fetches spot prices from OANDA and simulates forward rates via manual offsets or demo swap-points.
- **Deviation Analysis**: Calculates deviation in basis points between observed and theoretical (CIP) forward rates.
- **Historical Charts**:
- Deviation history (last 50 refresh bars)
- Observed forward history (last 50 refresh bars)
- **Risk Metrics**:
- P&L distribution histograms for each tenor
- Equity curve showing cumulative P&L over the dashboard session
- **Summary Metrics**: Total PnL, Win Rate, Max Drawdown, and Current Deviation at a glance.
- **Alerts**: Sends Slack notifications on arbitrage signals exceeding configured thresholds.
- **Auto-Refresh**: Dashboard refreshes data every 5 seconds.
* **Live Data**: Fetches FX spot prices from OANDA practice API every 5 seconds
* **Forward Calculation**: Supports manual forwardrate offsets or practicemode swappoints
* **CIP Deviation**: Computes basispoint deviation between observed and theoretical forward rates
* **Interactive Metrics**: Onscreen summary cards (Total PnL, Win Rate, Max Drawdown, Current Dev)
* **Visualizations**:
* Deviation & Observed Forward history charts
* PnL distribution histograms
* Equity curve over the last 50 bars
* **Alerts**: Sends Slack notifications when deviation exceeds your threshold
* **Autorefresh**: Dashboard refreshes every 5 seconds for nearlive monitoring
## Overview
This Streamlit app provides a live dashboard for monitoring Covered Interest Parity (CIP) arbitrage opportunities in the FX market. It pulls spot prices from OANDA, applies either manual offsets or swappoint data to generate observed forward rates, and calculates the deviation from the theoretical forward implied by interestrate differentials. Users can simulate PnL paths, view summary metrics, and receive Slack alerts when the deviation signal indicates a buy or sell opportunity.
## Why I Built This
I wanted to explore how CIP deviations can reveal riskfree arbitrage opportunities between FX spot and forward markets. Building this dashboard helped me practice realtime data integration, interactive UI development with Streamlit, and automated alerting—key skills for quantitative trading and fintech engineering.
## Problem Statement & Business Context
**Covered Interest Parity** states that the forward FX rate should offset interestrate differentials between two currencies. When markets deviate, banks and hedge funds can lock in arbitrage profits by simultaneously borrowing, converting, and hedging FX exposures. Detecting these fleeting mispricings in real time is valuable for highfrequency traders, corporate treasuries, and quantitative researchers.
## Data & Tools Used
* **Data Sources**: OANDA practice API for spot rates; manual-bps slider or practice swappoints for forwards
* **Languages & Frameworks**: Python, Streamlit
* **Libraries**:
* `oandapyV20` for OANDA REST calls
* `pandas`, `numpy` for data processing
* `matplotlib` (via Streamlit) for charts
* `streamlit_autorefresh` for autoreload
* **Alerting**: Slack webhook integration
## Methodology
1. **Spot & Forward Retrieval**:
* **Manual offset**:
`F_obs = F_theo * (1 + offset_bps/10000)`
* **Swap-points fallback**:
`F_obs = spot + swap_pts * tenor_days/360`
2. **Theoretical Forward** (Covered Interest Parity):
`F_theo = spot * (1 + r_dom * T) / (1 + r_for * T)`
*where* `T = tenor_days/360`
3. **Deviation** (in basis points):
`dev_bps = (F_obs - F_theo)/F_theo * 10000`
4. **Signal Generation**:
* If `dev_bps > threshold` → Sell forward
* If `dev_bps < -threshold` → Buy forward
* Otherwise → No arbitrage
5. **Risk Simulation**:
* Simulate *N* spot paths with white-noise shocks
* Compute PnL per path: `(S_T - F_obs) * notional - cost`, apply stop-loss cap
6. **Back-testing & Optimization**:
* Parameter sweep on threshold, offset, spread, stop-loss
* Evaluate Total PnL, Win Rate, Average PnL, Max Drawdown to pick optimal settings
## Results & Demo
* **Optimized backtest** (30day tenor, 1bp threshold, 2bp stoploss, 0.1bp spread):
* Total PnL: **\$5,153,890**
* Win Rate: **57.6%**
* Max Drawdown: **\$18,295**
* **Live dashboard**: see realtime deviation, forward history, PnL distributions, equity curve, and Slack alerts.
## Key Challenges & Solutions
* **API Errors & Secret Management**: Learned to debug HTTP JSON errors and securely store credentials via Streamlit secrets or environment variables.
* **Streamlit State & Autorefresh**: Managing session state for timeseries history required careful use of `st.session_state` and `st_autorefresh`.
* **Debugging Complex Data Flows**: Overcame intermittent data errors by inserting smoketest banners and raw response dumps for rapid troubleshooting.
## Takeaways
* Sharpened Python debugging and attention to detail when integrating multiple APIs.
* Gained handson experience with realtime UI development using Streamlit.
* Developed a deep understanding of CIP arbitrage mechanics and PnL simulation.
* Improved best practices around secrets management and automated alerting workflows.
## Future Improvements
* **Reduce AI dependency**: rewrite key modules without AI assistance to strengthen core skills.
* **Real swappoints**: upgrade to a funded OANDA account or integrate a paid forwardrate API for genuine forward data.
* **Expand tenor & pairs**: support 7day, 90day forwards and additional FX crosses (AUD/USD, USD/CAD).
* **Cloud deployment**: containerize and host on Streamlit Cloud for 24/7 monitoring with builtin uptime alerts.
## 📁 Repo Structure
fx-arb-dashboard/
├── app.py # Main Streamlit dashboard
├── cip.py # CIP calculation helpers
├── optimize.py # Parameter sweep backtest script
├── backtest.py # Historical backtest using swap-points
├── requirements.txt # Python dependencies
└── .streamlit/
└── config.toml # Optional Streamlit config (no secrets)