---
title: "FOREX Data"
description: "FOREX Data dataset from QuantConnect."
canonical: https://www.quantconnect.com/docs/v2/writing-algorithms/datasets/quantconnect/forex-data
markdown: https://www.quantconnect.com/docs/v2/writing-algorithms/datasets/quantconnect/forex-data.md
language: python
source: https://github.com/QuantConnect/Documentation/tree/master/03%20Writing%20Algorithms/14%20Datasets/02%20QuantConnect/12%20FOREX%20Data
modified: 2026-10-29
index: https://www.quantconnect.com/llms.txt
---

# FOREX Data

[Documentation](https://www.quantconnect.com/docs/v2.md) > [Writing Algorithms](https://www.quantconnect.com/docs/v2/writing-algorithms.md) > Datasets > [QuantConnect](https://www.quantconnect.com/docs/v2/writing-algorithms/datasets/quantconnect.md) > FOREX Data

> Code examples are shown in Python. Append `?lang=csharp` to this URL for the C# version of this page.

## Introduction

The FOREX Data by QuantConnect serves 72 [foreign exchange](https://www.investopedia.com/terms/f/forex.asp) (FOREX) pairs, starts on various dates from January 2007, and is delivered on any frequency from tick to daily. This dataset is created by QuantConnect processing raw tick data from OANDA.

FOREX data does not include ask and bid sizes.

For more information about the FOREX Data dataset, including CLI commands and pricing, see the [dataset listing](https://www.quantconnect.com/datasets/quantconnect-forex).

## About the Provider

QuantConnect was founded in 2012 to serve quants everywhere with the best possible algorithmic trading technology. Seeking to disrupt a notoriously closed-source industry, QuantConnect takes a radically open-source approach to algorithmic trading. Through the QuantConnect web platform, more than 50,000 quants are served every month.

## Getting Started

The following snippet demonstrates how to request data from the FOREX dataset:

```python
self.eurusd = self.add_forex("EURUSD", Resolution.DAILY).symbol
```

## Data Summary

The following table describes the dataset properties:

| Property | Value |
| --- | --- |
| Start Date | January 2007 |
| Asset Coverage | 72 Currency pairs |
| Data Density | Dense |
| Resolution | Tick, Second, Minute, Hour, & Daily |
| Timezone | UTC |
| Market Hours | [Always Open](https://www.quantconnect.com/docs/v2/writing-algorithms/securities/asset-classes/forex/market-hours.md), except from Friday 5 PM EST to Sunday 5 PM EST |

## Requesting Data

To add FOREX data to your algorithm, call the `add_forex` method. Save a reference to the Forex `Symbol` so you can access the data later in your algorithm.

```python
class ForexAlgorithm (QCAlgorithm):
    def initialize(self) -> None:
        self.set_start_date(2019, 2, 20)
        self.set_end_date(2019, 2, 21)
        self.set_cash(100000)

        self.eurusd = self.add_forex('EURUSD', Resolution.MINUTE).symbol

        self.set_benchmark(self.eurusd)
```

For more information about creating Forex subscriptions, see [Requesting Data](https://www.quantconnect.com/docs/v2/writing-algorithms/securities/asset-classes/forex/requesting-data.md).

## Accessing Data

To get the current Forex data, index the `quote_bars`, or `ticks` properties of the current [`Slice`](https://www.quantconnect.com/docs/v2/writing-algorithms/key-concepts/time-modeling/timeslices.md) with the Forex `Symbol`. Slice objects deliver unique events to your algorithm as they happen, but the `Slice` may not contain data for your security at every time step. To avoid issues, check if the `Slice` contains the data you want before you index it.

```python
def on_data(self, slice: Slice) -> None:
    if self.eurusd in slice.quote_bars:
        quote_bar = slice.quote_bars[self.eurusd]
        self.log(f"{self.eurusd} bid at {slice.time}: {quote_bar.bid.close}")

    if self.eurusd in slice.ticks:
        ticks = slice.ticks[self.eurusd]
        for tick in ticks:
            self.log(f"{self.eurusd} price at {slice.time}: {tick.price}")
```

You can also iterate through all of the data objects in the current `Slice`.

```python
def on_data(self, slice: Slice) -> None:
    for symbol, quote_bar in slice.quote_bars.items():
        self.log(f"{symbol} bid at {slice.time}: {quote_bar.bid.close}")

    for symbol, ticks in slice.ticks.items():
        for tick in ticks:
            self.log(f"{symbol} price at {slice.time}: {tick.price}")
```

For more information about accessing Forex data, see [Handling Data](https://www.quantconnect.com/docs/v2/writing-algorithms/securities/asset-classes/forex/handling-data.md).

## Historical Data

To get historical Forex data, call the `history` method with the Forex `Symbol`. If there is no data in the period you request, the history result is empty.

```python
# DataFrame
history_df = self.history(self.eurusd, 100, Resolution.MINUTE)

# QuoteBar objects
history_quote_bars = self.history[QuoteBar](self.eurusd, 100, Resolution.MINUTE)

# Tick objects
history_ticks = self.history[Tick](self.eurusd, timedelta(seconds=10), Resolution.TICK)
```

For more information about historical data, see [History Requests](https://www.quantconnect.com/docs/v2/writing-algorithms/historical-data/history-requests.md).

## Remove Subscriptions

To remove a Forex pair subscription, call the `remove_security` method.

```python
self.remove_security(self.eurusd)
```

The `remove_security` method cancels your open orders for the security and liquidates your holdings.

## Supported Assets

The following table shows the available Forex pairs:

| Pairs Available (72) |  |  |  |  |  |
| --- | --- | --- | --- | --- | --- |
| AUDCAD | AUDCHF | AUDHKD | AUDJPY | AUDNZD | AUDSGD |
| AUDUSD | CADCHF | CADHKD | CADJPY | CADSGD | CHFHKD |
| CHFJPY | CHFZAR | EURAUD | EURCAD | EURCHF | EURCZK |
| EURDKK | EURGBP | EURHKD | EURHUF | EURJPY | EURNOK |
| EURNZD | EURPLN | EURSEK | EURSGD | EURTRY | EURUSD |
| EURZAR | GBPAUD | GBPCAD | GBPCHF | GBPHKD | GBPJPY |
| GBPNZD | GBPPLN | GBPSGD | GBPUSD | GBPZAR | HKDJPY |
| NZDCAD | NZDCHF | NZDHKD | NZDJPY | NZDSGD | NZDUSD |
| SGDCHF | SGDHKD | SGDJPY | TRYJPY | USDCAD | USDCHF |
| USDCNH | USDCZK | USDDKK | USDHKD | USDHUF | USDINR |
| USDJPY | USDKRW | USDMXN | USDNOK | USDPLN | USDSAR |
| USDSEK | USDSGD | USDTHB | USDTRY | USDZAR | ZARJPY |

## Downloading Data

You can download the FOREX Data dataset to your local machine to run the LEAN engine locally with the [LEAN CLI](https://www.quantconnect.com/docs/v2/lean-cli.md). For the download commands, prerequisites, and pricing, see [Forex](https://www.quantconnect.com/docs/v2/lean-cli/datasets/quantconnect/forex.md) in the LEAN CLI documentation.

## Example Applications

The FOREX price data enables you to trade currency pairs in the global market. Examples include the following strategies:

- Exploring the impact that daily worldwide news cycles have on international currencies
- Carry Trade: borrow from a lower interest currency pair to fund the purchase of a currency pair with a higher interest rate

### Classic Algorithm Example

The following example algorithm implements a FOREX carry trade. It buys the FOREX pair of the country with the lowest interest rate and sells the FOREX pair of the country with the highest interest rate.

```python
from AlgorithmImports import *

class ForexCarryTradeAlgorithm(QCAlgorithm):

    def initialize(self) -> None:
        self.set_start_date(2024, 9, 1)
        self.set_end_date(2024, 12, 31)
        self.set_cash(25000)

        # We will use hard-coded interest rates for each base currency
        self.rates = {
            "USDAUD": 1.5,    # Australia
            "USDCAD": 0.5,    # Canada
            "USDCNY": 4.35,   # China
            "USDEUR": 0.0,    # Euro Area
            "USDINR": 6.5,    # India
            "USDJPY": -0.1,   # Japan
            "USDMXN": 4.25,   # Mexico
            "USDTRY": 7.5,    # Turkey
            "USDZAR": 7.0     # South Africa
        }

        # Subscribe to forex data for trading
        for ticker in self.rates:
            self.add_forex(ticker, Resolution.DAILY)

        # Use a month counter as variable to control rebalancing
        self.month = -1

    def on_data(self, slice: Slice) -> None:
        # Monthly rebalance checker
        if self.month == self.time.month:
            return
        self.month = self.time.month

        # Long the pair with highest interest rate and sell the pair with the lowest to earn the max monetary inflation difference between the two
        sorted_rates = sorted(self.rates.items(), key = lambda x: x[1])
        self.set_holdings(sorted_rates[0][0], -0.5)
        self.set_holdings(sorted_rates[-1][0], 0.5)
```

### Framework Algorithm Example

The following example algorithm implements a FOREX carry trade. It buys the FOREX pair of the country with the lowest interest rate and sells the FOREX pair of the country with the highest interest rate.

```python
from AlgorithmImports import *

class ForexCarryTradeAlgorithm(QCAlgorithm):

    def initialize(self) -> None:
        self.set_start_date(2024, 9, 1)
        self.set_end_date(2024, 12, 31)
        self.set_cash(25000)

        def to_symbol(ticker: str) -> Symbol:
            return Symbol.create(ticker, SecurityType.FOREX, Market.OANDA)

        # We will use hard-coded interest rates for each base currency
        rates = {
            to_symbol("USDAUD"): 1.5,    # Australia
            to_symbol("USDCAD"): 0.5,    # Canada
            to_symbol("USDCNY"): 4.35,   # China
            to_symbol("USDEUR"): 0.0,    # Euro Area
            to_symbol("USDINR"): 6.5,    # India
            to_symbol("USDJPY"): -0.1,   # Japan
            to_symbol("USDMXN"): 4.25,   # Mexico
            to_symbol("USDTRY"): 7.5,    # Turkey
            to_symbol("USDZAR"): 7.0     # South Africa
        }

        self.set_universe_selection(ManualUniverseSelectionModel(list(rates.keys())))
        # A custom alpha model to emit insight according to interest rate
        self.set_alpha(IntestRatesAlphaModel(rates))
        # Equal size to capitalize the monetary value of quote currency only based on interest rate difference
        # For dollar-neutral to save margin cost
        self.set_portfolio_construction(EqualWeightingPortfolioConstructionModel(Expiry.END_OF_MONTH))

class IntestRatesAlphaModel(AlphaModel):
    def __init__(self, rates: float) -> None:
        self.rates = rates
        # Variable to control the rebalancing time
        self.month = -1

    def update(self, algorithm: QCAlgorithm, slice: Slice) -> List[Insight]:
        # Monthly rebalance
        if self.month == algorithm.time.month:
            return []
        self.month = algorithm.time.month

        # # Long the pair with highest interest rate and sell the pair with the lowest to earn the max monetary inflation difference between the two
        sorted_rates = sorted(self.rates.items(), key = lambda x: x[1])
        return Insight.group(
            Insight.price(sorted_rates[0][0], Expiry.END_OF_MONTH, InsightDirection.UP),
            Insight.price(sorted_rates[-1][0], Expiry.END_OF_MONTH, InsightDirection.DOWN)
        )
```

## Data Point Attributes

The FOREX dataset provides `QuoteBar` and `Tick` objects.

### QuoteBar Attributes

`QuoteBar` objects have the following attributes:

*Members of `QuantConnect.Data.Market.QuoteBar` (JSON): https://www.quantconnect.com/services/inspector?type=T:QuantConnect.Data.Market.QuoteBar&language=python*

### Tick Attributes

`Tick` objects have the following attributes:

*Members of `QuantConnect.Data.Market.Tick` (JSON): https://www.quantconnect.com/services/inspector?type=T:QuantConnect.Data.Market.Tick&language=python*
