mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-10-28 21:12:16 +00:00
Adds SDK Guide for Forex Menu (#3259)
Co-authored-by: Jeroen Bouma <jer.bouma@gmail.com>
This commit is contained in:
91
website/content/SDK/forex/_index.md
vendored
91
website/content/SDK/forex/_index.md
vendored
@@ -1,6 +1,91 @@
|
||||
---
|
||||
title: forex
|
||||
keywords: ""
|
||||
excerpt: ""
|
||||
title: Introduction to Forex
|
||||
keywords: "sdk, api, forex, fx, foreign, exchange, currency, pair, pairs, forward, rate, rates, eurodollar, usd, us, dollar, euro, yen, franc, central, bank, currencies, oanda"
|
||||
excerpt: "This guide introduces the Forex module, within the OpenBB SDK, and provides examples."
|
||||
geekdocCollapseSection: true
|
||||
---
|
||||
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](https://openbb-finance.github.io/OpenBBTerminal/SDK/keys/). After importing the entire OpenBB SDK, no further action is required to authorize the sources. This module also provides Oanda account holders [additional functionality](https://openbb-finance.github.io/OpenBBTerminal/terminal/forex/oanda/).
|
||||
|
||||
For the purpose of demonstration, additional modules will be imported to begin the Python script or Notebook file.
|
||||
|
||||
```python
|
||||
from openbb_terminal.sdk import openbb
|
||||
|
||||
import pandas as pd
|
||||
|
||||
%matplotlib inline
|
||||
```
|
||||
|
||||

|
||||
|
||||
## How to Use
|
||||
|
||||
To load historical data for a desired currency pair, copy and paste the code below:
|
||||
|
||||
```python
|
||||
currency_pair = openbb.forex.load(
|
||||
from_symbol='USD',
|
||||
to_symbol='EUR',
|
||||
source = 'Polygon',
|
||||
start_date = '2000-01-01',
|
||||
resolution = 'd',
|
||||
interval = '1day',
|
||||
)
|
||||
```
|
||||
|
||||
Note that `source` can be any of: AlphaVantage, Oanda, Polygon, or, YahooFinance. It returns a Pandas DataFrame:
|
||||
|
||||

|
||||
|
||||
Cached as a DataFrame, it can then be passed along to any time-series function within the OpenBB SDK; such as, the [Technical Analysis](https://openbb-finance.github.io/OpenBBTerminal/terminal/common/ta/) and [Quantitative Analysis](https://openbb-finance.github.io/OpenBBTerminal/terminal/common/qa/) modules. Pandas can also be used to further process data, for example, using the cached example above:
|
||||
|
||||
```python
|
||||
daily_range = pd.DataFrame(columns = ['range'])
|
||||
|
||||
daily_range.range = currency_pair['High']-currency_pair['Low']
|
||||
|
||||
openbb.common.qa.bw(daily_range, target = 'range', symbol = 'Daily Variance EUR/USD')
|
||||
|
||||
```
|
||||
|
||||

|
||||
|
||||
One free set of data, from the Oanda subset of functions, is the current forward rates of a currency pair. Data is returned as a table, for example:
|
||||
|
||||
```python
|
||||
openbb.forex.oanda.fwd(from_symbol = 'EUR', to_symbol = 'USD')
|
||||
```
|
||||
|
||||

|
||||
|
||||
This code snippet returns a Pandas DataFrame containing forward points for two currency pairs, JPY/USD & USD/EUR:
|
||||
|
||||
```python
|
||||
from openbb_terminal.sdk import openbb
|
||||
|
||||
import pandas as pd
|
||||
|
||||
JPYUSD = openbb.forex.oanda.fwd(to_symbol='JPY', from_symbol='USD')
|
||||
Expiration = list(JPYUSD.index)
|
||||
JPYUSD_points = list(JPYUSD.Points)
|
||||
USDEUR = openbb.forex.oanda.fwd(to_symbol='USD', from_symbol='EUR')
|
||||
USDEUR_points = list(USDEUR.Points)
|
||||
|
||||
fwd_spread = Expiration,JPYUSD_points,USDEUR_points
|
||||
|
||||
pair_spreads = pd.DataFrame.from_dict(fwd_spread).transpose()
|
||||
pair_spreads = pair_spreads.reset_index()
|
||||
|
||||
pd.DataFrame(pair_spreads).rename(columns = {
|
||||
0: "Expiration",
|
||||
1: "JPY/USD Points",
|
||||
2: "USD/EUR Points",
|
||||
}, inplace = True)
|
||||
|
||||
pair_spreads.set_index(['Expiration'], inplace = True)
|
||||
|
||||
pair_spreads = pd.DataFrame(pair_spreads, columns = ['JPY/USD Points', 'USD/EUR Points'])
|
||||
|
||||
pair_spreads
|
||||
```
|
||||

|
||||
|
||||
Reference in New Issue
Block a user