{"id":23155691,"url":"https://github.com/jebin1999/triangular-arbitrage-histotical-opportunities-","last_synced_at":"2026-05-05T07:31:34.643Z","repository":{"id":268407993,"uuid":"869649737","full_name":"Jebin1999/Triangular-Arbitrage-Histotical-Opportunities-","owner":"Jebin1999","description":"Triangular Arbitrage opportunities  in Historical Forex Market","archived":false,"fork":false,"pushed_at":"2024-12-16T14:45:21.000Z","size":34,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-10T02:48:31.790Z","etag":null,"topics":["arbitrage","arbitrage-opportunity","financial","forex","forex-market","forex-trading","ipynb","python","python3","quantitative-finance","quants"],"latest_commit_sha":null,"homepage":"","language":"Jupyter Notebook","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Jebin1999.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-10-08T16:45:25.000Z","updated_at":"2024-12-16T14:45:25.000Z","dependencies_parsed_at":"2024-12-16T15:47:33.578Z","dependency_job_id":"a931a12f-e22e-4767-aef1-2d7ec74ab118","html_url":"https://github.com/Jebin1999/Triangular-Arbitrage-Histotical-Opportunities-","commit_stats":null,"previous_names":["jebin1999/triangular-arbitrage-histotical-opportunities-"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Jebin1999%2FTriangular-Arbitrage-Histotical-Opportunities-","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Jebin1999%2FTriangular-Arbitrage-Histotical-Opportunities-/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Jebin1999%2FTriangular-Arbitrage-Histotical-Opportunities-/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Jebin1999%2FTriangular-Arbitrage-Histotical-Opportunities-/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Jebin1999","download_url":"https://codeload.github.com/Jebin1999/Triangular-Arbitrage-Histotical-Opportunities-/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247218857,"owners_count":20903323,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["arbitrage","arbitrage-opportunity","financial","forex","forex-market","forex-trading","ipynb","python","python3","quantitative-finance","quants"],"created_at":"2024-12-17T21:11:12.265Z","updated_at":"2026-05-05T07:31:34.577Z","avatar_url":"https://github.com/Jebin1999.png","language":"Jupyter Notebook","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# Triangular Arbitrage Detection in Forex Market\n\nThis project is a **Python-based tool** that identifies **triangular arbitrage opportunities** in the foreign exchange (Forex) market. It fetches historical exchange rates for currency pairs, calculates potential arbitrage opportunities, and saves the results to an in-memory DataFrame, with an option to export to CSV. \n\n## Features\n- Fetches **historical data** for currency pairs from Yahoo Finance using the `yfinance` library.\n- Identifies **triangular arbitrage** opportunities based on the exchange rates of three currency pairs.\n- Provides **real-time analysis** by iterating over historical data to find and display arbitrage opportunities.\n- Saves detected opportunities in a **DataFrame**, which can be accessed in memory, and optionally exported to a CSV file.\n\n## Triangular Arbitrage Overview\n\n**Triangular arbitrage** involves exploiting price discrepancies between three related currency pairs, such as:\n- EUR/USD\n- USD/JPY\n- EUR/JPY\n\nThe code calculates the **cross rate** for EUR/JPY using EUR/USD and USD/JPY, and compares it with the actual EUR/JPY market rate. If a discrepancy exists that exceeds a certain threshold, it is flagged as an arbitrage opportunity.\n\n### Arbitrage Formula\n\nThe cross rate is calculated using the following formula:\n```\nCalculated_EURJPY = EUR/USD * USD/JPY\n```\n\nIf the difference between the calculated EUR/JPY and the actual EUR/JPY exceeds 0.01, an arbitrage opportunity is detected.\n\n## Prerequisites\n\nTo run this project, you'll need the following installed on your system:\n- **Python 3.x**\n- **pandas** for data manipulation.\n- **yfinance** for fetching exchange rate data.\n  \nYou can install the required libraries using the following command:\n```bash\npip install pandas yfinance\n```\n\n## How to Run the Code\n\n1. **Clone the repository** or download the project files.\n   \n2. Install the required dependencies:\n   ```bash\n   pip install pandas yfinance\n   ```\n\n3. Run the script:\n   ```bash\n   python triangular_arbitrage.py\n   ```\n\n4. The program will:\n   - Fetch historical exchange rate data for **EUR/USD**, **USD/JPY**, and **EUR/JPY**.\n   - Calculate triangular arbitrage opportunities over the past year.\n   - Display the detected opportunities in the terminal.\n\n5. **Optional:** The detected arbitrage opportunities are saved in-memory as a DataFrame. You can also export them to a CSV file:\n   ```bash\n   Opportunities saved to 'arbitrage_opportunities.csv'.\n   ```\n\n## Code Walkthrough\n\n### 1. `fetch_historical_data()`\nThis function fetches **historical exchange rate data** from Yahoo Finance using the `yfinance` library. It takes in a currency pair (e.g., `EURUSD`) and returns a DataFrame containing the historical close prices for the specified period.\n\n### 2. `calculate_triangular_arbitrage()`\nThis function takes in the exchange rates for **EUR/USD**, **USD/JPY**, and **EUR/JPY** on a specific date. It calculates the theoretical EUR/JPY rate using the EUR/USD and USD/JPY rates, and compares it with the actual EUR/JPY rate to determine whether an arbitrage opportunity exists.\n\n### 3. `list_past_arbitrage_opportunities()`\nThis is the main function that:\n- Fetches historical data for the three currency pairs.\n- Joins the datasets to align exchange rates by date.\n- Iterates through the historical data to detect and store arbitrage opportunities.\n- Saves the detected opportunities in a DataFrame (`stored_opportunities_df`) and optionally exports them to a CSV file.\n\n### Sample Output\n\nWhen the script runs, you will see output similar to this in the terminal:\n```\nFetching historical data...\nData for EURUSD:\n             Close\nDate              \n2023-01-02  1.0658\n2023-01-03  1.0617\n...\nJoining historical data...\nJoined Data (first few rows):\n            EURUSD=X  USDJPY=X  EURJPY=X\nDate                                   \n2023-01-02    1.0658   130.760   139.30\n2023-01-03    1.0617   131.120   139.10\n...\nDetected Arbitrage Opportunities:\n          Date  Calculated_EURJPY  Actual_EURJPY Opportunity\n0   2023-10-11         157.616904       157.598999         YES\n1   2023-10-12         158.340050       158.328995         YES\n...\n```\n\n### Saving Results to CSV\n\nIf you want to save the detected opportunities to a CSV file, they will be saved as:\n```bash\narbitrage_opportunities.csv\n```\n\nThe CSV file will contain the following columns:\n- **Date**: The date of the exchange rates.\n- **Calculated_EURJPY**: The theoretical EUR/JPY cross rate based on EUR/USD and USD/JPY.\n- **Actual_EURJPY**: The actual EUR/JPY rate from the market.\n- **Opportunity**: Whether an arbitrage opportunity was detected (YES/NO).\n\n## Future Enhancements\n\n- **Live Data Integration**: Extend the script to work with real-time exchange rates, allowing users to act on arbitrage opportunities as they emerge.\n- **Alert System**: Integrate **SMS, WhatsApp, or Telegram notifications** to alert traders when an arbitrage opportunity is detected.\n- **Customization**: Allow users to customize the currency pairs they want to monitor for arbitrage opportunities.\n  \n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n\n```\n\n---\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjebin1999%2Ftriangular-arbitrage-histotical-opportunities-","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjebin1999%2Ftriangular-arbitrage-histotical-opportunities-","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjebin1999%2Ftriangular-arbitrage-histotical-opportunities-/lists"}