Skip to main content

Forex

The Forex module provides a way for users to get currency pair data, from a number of sources. API keys for them are handled by the Keys module. After importing the entire OpenBB SDK, no further action is required to authorize the sources. This module also provides Oanda account holders with broker integration.

How to Use

Below is a brief description of each function within the Forex module:

PathTypeDescription
openbb.forex.candleFunctionOHLC Chart & Optional Moving Averages
openbb.forex.fwdFunctionForward Rates of Currency Pairs
openbb.forex.get_currency_listListList of Currency Symbols
openbb.forex.loadFunctionLoad Historical OHLC Data for Currency Pairs
openbb.forex.oandaSub-ModuleOanda Broker Integration
openbb.forex.quoteFunctionRealtime Currency Exchange Rate

The contents of the menu is printed with:

help(openbb.forex)

Examples

Import Statements

The examples in this guide will assume that the import statements below are present:

from openbb_terminal.sdk import openbb
import pandas as pd

Load

The load function has the ability to request data from multiple sources:

  • AlphaVantage
  • Polygon
  • YahooFinance (default)

Using the default source:

currency_pair = openbb.forex.load(
from_symbol='USD',
to_symbol='EUR',
start_date = '2000-01-01',
interval = '1week')

currency_pair.head(3)
dateOpenHighLowCloseAdj CloseVolume
2003-12-01 00:00:000.830980.837240.820280.821630.821630
2003-12-08 00:00:000.821830.824880.812610.820680.820680
2003-12-15 00:00:000.820550.821150.803730.809190.809190

To use an alternate source, add the source argument to the syntax:

currency_pair = openbb.forex.load(
from_symbol= 'USD',
to_symbol= 'EUR',
source = 'Polygon',
start_date = '2000-01-01',
interval = '1week')

currency_pair.head(3)
dateVolumevwOpenCloseHighLowTransactions
2012-01-29 00:00:0037580.7610.75650.75970.76760.75653758
2012-02-05 00:00:0056050.75660.7620.75810.76720.750815605
2012-02-12 00:00:0090450.76110.7570.76030.770530.752789045

The amount and granularity of historical data available will vary by source. The two tables above illustrate some of those differences.

Average True Range

The loaded data can now be used as inputs for other functions and calculations, such as the average true range over a four week window.

weekly_atr = openbb.ta.atr(data = currency_pair, window = 4)
currency_pair = currency_pair.join(weekly_atr)

currency_pair.tail(1)
dateVolumevwOpenCloseHighLowTransactionsATRe_4
2022-11-13 00:00:004819180.9650.964790.962050.973510.9544819180.0281756

Quote

Get real-time exchange rates.

openbb.forex.quote("EURUSD", source = "AlphaVantage")
Realtime Currency Exchange Rate
1. From_Currency CodeUSD
2. From_Currency NameUnited States Dollar
3. To_Currency CodeEUR
4. To_Currency NameEuro
5. Exchange Rate0.91580000
6. Last Refreshed2023-07-03 17:00:01
7. Time ZoneUTC
8. Bid Price0.91576000
9. Ask Price0.91580000

Forward Rates

fwd_usdeur = openbb.forex.fwd('EUR', 'USD')

fwd_usdeur
ExpirationAskBidMidPoints
Overnight0.916080.916020.91605-0.825
Tomorrow Next0.916080.916010.91604-0.855
Spot Next0.916120.916060.91609-0.425
One Week0.915860.91580.91583-2.995
Two Weeks0.915570.91550.91553-5.985
Three Weeks0.915260.915190.91523-9.05
One Month0.91470.914630.91466-14.685
Two Months0.913390.913310.91335-27.81
Three Months0.912010.911940.91198-41.54
Four Months0.910640.910550.9106-55.34
Five Months0.909390.90930.90934-67.885
Six Months0.907430.907320.90737-87.555
Seven Months0.906160.906040.9061-100.32
Eight Months0.905010.904890.90495-111.795
Nine Months0.90370.903580.90364-124.88
Ten Months0.902540.90240.90247-136.6
Eleven Months0.901460.901320.90139-147.375
One Year0.900410.900250.90033-158.025
Two Years0.890630.890170.8904-257.31

Currency pairs will have different term structure composition in the other direction:

fwd_eurusd = openbb.forex.fwd('USD', 'EUR')

fwd_eurusd
ExpirationAskBidMidPoints
Overnight1.091661.091641.091650.985
Tomorrow Next1.091611.091591.09160.515
Spot Next1.091611.091591.09160.5085
One Week1.091921.091891.091913.565
Two Weeks1.092281.092251.092267.13
Three Weeks1.092641.092611.0926310.78
One Month1.093321.093291.0933117.549
Two Months1.094881.094841.0948633.14
Three Months1.096551.09651.0965349.7665
Four Months1.098221.098151.0981866.32
Five Months1.099741.099671.0997181.56
Six Months1.102151.102081.10211105.6
Seven Months1.103721.10361.10366121.08
Eight Months1.105121.1051.10506135.06
Nine Months1.106731.106611.10667151.23
Ten Months1.108171.108051.10811165.64
Eleven Months1.109511.109411.10946179.09
One Year1.110821.11071.11076192.08
Two Years1.123381.122961.12317316.24
Three Years1.134221.13321.13371421.62
Four Years1.144761.143741.14425527
Five Years1.156471.154451.15546639.1
Six Years1.167961.166441.1672756.5
Seven Years1.179361.177341.17835868
Ten Years1.211661.206641.209151176

Not all currency pairs will have the same length of term structure.

fwd_eurjpy = openbb.forex.fwd('JPY', 'EUR')
fwd_pairs = fwd_eurjpy.join(fwd_usdeur, on = ['Expiration'], lsuffix = ' EUR/JPY', rsuffix=' USD/EUR')

fwd_pairs
ExpirationAsk EUR/JPYBid EUR/JPYMid EUR/JPYPoints EUR/JPYAsk USD/EURBid USD/EURMid USD/EURPoints USD/EUR
Overnight157.959157.951157.955-3.170.916080.916020.91605-0.825
Tomorrow Next157.959157.951157.95500.916080.916010.91604-0.855
Spot Next157.959157.951157.955-1.5850.916120.916060.91609-0.425
One Week157.958157.95157.954-11.120.915860.91580.91583-2.995
Two Weeks157.957157.949157.953-22.340.915570.91550.91553-5.985
Three Weeks157.956157.948157.952-33.410.915260.915190.91523-9.05
One Month157.954157.946157.95-53.2210.91470.914630.91466-14.685
Two Months157.949157.941157.945-102.350.913390.913310.91335-27.81
Three Months157.944157.936157.94-153.5750.912010.911940.91198-41.54
Four Months157.938157.93157.934-209.6350.910640.910550.9106-55.34
Five Months157.933157.925157.929-260.550.909390.90930.90934-67.885
Six Months157.927157.919157.923-318.3650.907430.907320.90737-87.555
Seven Months157.922157.913157.918-374.290.906160.906040.9061-100.32
Eight Months157.917157.908157.912-425.680.905010.904890.90495-111.795
Nine Months157.911157.903157.907-479.260.90370.903580.90364-124.88
Ten Months157.906157.897157.901-536.5250.902540.90240.90247-136.6
Eleven Months157.9157.892157.896-586.7750.901460.901320.90139-147.375
One Year157.895157.887157.891-637.1850.900410.900250.90033-158.025
Two Years157.841157.831157.836-1190.550.890630.890170.8904-257.31