A professional-grade detection system for finding profitable currency exchange cycles using the Floyd-Warshall Algorithm with logarithmic transformation.
This project detects currency arbitrage opportunitiesโcycles where you can exchange currencies and end up with more money than you started with. It uses pure algorithm implementation (no external packages) combined with a Django web interface.
- Pure Floyd-Warshall Implementation: O(nยณ) algorithm for finding shortest paths in currency graphs
- Mathematical Elegance: Converts exchange rates to negative logarithms to detect negative cycles
- Professional Django Setup: Full Django project with models, admin panel, and API endpoints
- Real-time Dashboard: Beautiful UI showing detected arbitrage opportunities
- Historical Data Support: Store and analyze detection results
- API Endpoints: JSON endpoints for programmatic access
A profitable arbitrage cycle satisfies:
Taking logarithm:
By negating the weights:
This transforms the problem into finding negative cycles using the Floyd-Warshall algorithm.
- Time: O(nยณ) where n = number of currencies
- Space: O(nยฒ) for distance and next-node matrices
- Convert Rates to Weights:
weight[iโj] = -log(exchange_rate[iโj]) - Build Matrices: Initialize distance and reconstruction matrices
- Run Floyd-Warshall: Find shortest paths between all currency pairs
- Detect Cycles: Check if
dist[i][i] < 0for any currency i - Reconstruct Path: Use backtracking to find the actual cycle sequence
- Calculate Profit: Compute the percentage profit for the cycle
currency-arbitrage-detector/
โโโ src/
โ โโโ manage.py
โ โโโ currency_arbitrage/ # Django settings
โ โ โโโ settings.py
โ โ โโโ urls.py
โ โ โโโ wsgi.py
โ โ โโโ asgi.py
โ โโโ detector/ # Main app
โ โ โโโ models.py # Database models
โ โ โโโ views.py # Web views and API
โ โ โโโ services.py # Floyd-Warshall algorithm
โ โ โโโ urls.py
โ โ โโโ admin.py
โ โ โโโ templates/detector/
โ โ โโโ index.html # Dashboard template
โ โโโ static/
โ โ โโโ css/style.css # Professional styling
โ โ โโโ js/
โ โโโ templates/ # Base templates
โโโ data/
โ โโโ exchange_rates.csv # Exchange rate data
โโโ requirements.txt
cd src
pip install -r ../requirements.txtpython manage.py migrate
python manage.py createsuperuser # Create admin accountpython manage.py runserverVisit: http://localhost:8000/
Access: http://localhost:8000/admin/
GET /api/latest/
Response:
{
"has_arbitrage": true,
"cycle": ["USD", "EUR", "INR", "USD"],
"profit_percent": 2.45,
"cycle_length": 4,
"calculation_time_ms": 1.23,
"detected_at": "2026-02-03T10:30:00Z"
}GET /api/history/
GET /api/rates/
You can fetch free live FX rates and update the CSV using a builtโin management command. This keeps the algorithm from scratch while allowing live data ingestion.
cd src
python manage.py fetch_live_rates --base USD --symbols EUR,GBP,JPY,INRWhat this does:
- Calls a free public FX endpoint
- Builds full crossโrates from the base rates
- Updates
data/exchange_rates.csv
Note: When all crossโrates are derived from a single base, realโworld arbitrage is usually not present. The algorithm still runs and reports โno arbitrageโ if none exists.
Simulate a โlive feedโ using free historical timeโseries data:
cd src
python manage.py simulate_live --start 2025-12-01 --end 2025-12-07 --base USD --symbols EUR,GBP,JPY,INR --write-csv --sleep 1This runs the algorithm for each day in the range and (optionally) updates the CSV so the dashboard reflects each step.
Add exchange rates to data/exchange_rates.csv:
base,quote,rate
USD,EUR,0.90
EUR,GBP,1.18
GBP,USD,1.27
USD,JPY,148.50
JPY,INR,0.55
INR,USD,0.013base_currency: Currency code (e.g., USD)quote_currency: Currency code (e.g., EUR)rate: Exchange rate valuetimestamp: When the rate was recorded
has_arbitrage: Boolean flagcycle: JSON list of currencies in cycleprofit_percent: Calculated profit percentagecycle_length: Number of currencies in cyclecalculation_time_ms: Algorithm execution time
from pathlib import Path
from detector.services import detect_arbitrage
csv_path = Path("data/exchange_rates.csv")
result, edges = detect_arbitrage(csv_path)
if result.has_arbitrage:
print(f"Cycle: {' โ '.join(result.cycle)}")
print(f"Profit: {result.profit_percent:.2f}%")
print(f"Time: {result.calculation_time_ms:.2f}ms")This project is perfect for demonstrating:
- Graph algorithms in Python
- Dynamic programming concepts
- Mathematical problem solving
- Web application development with Django
- Algorithm optimization and complexity analysis
- Professional code documentation
| Feature | Status |
|---|---|
| Floyd-Warshall Algorithm | โ Implemented |
| Cycle Detection | โ Implemented |
| Profit Calculation | โ Implemented |
| Django Models | โ Implemented |
| Admin Panel | โ Implemented |
| REST API | โ Implemented |
| Professional UI | โ Implemented |
| Historical Data | โ Implemented |
| Dark Mode Theme | โ Implemented |
| Responsive Design | โ Implemented |
- Backend: Django 5.0+
- Algorithm: Pure Python (no external packages)
- Frontend: HTML5, CSS3, JavaScript
- Database: SQLite (default)
- Server: Django development server / Gunicorn
-
Real-World Limitations: This detector uses the latest rates provided. In production, you'd need real-time market data and account for:
- Trading fees and commissions
- Bid-ask spreads
- Time delays in execution
- Currency conversion minimums
-
Numerical Precision: The algorithm uses float precision tolerance (1e-9) for stability
-
Graph Size: Works efficiently for up to ~100 currencies; optimize for larger datasets
Educational project for DAA subject
Created as a comprehensive demonstration of algorithm implementation and web development
Note: This is an educational project. Always verify exchange rates with real-time market data before any actual trading.