Files
OpenBB/website/content/sdk/usage/intros/futures.md
Jerry Duluk f21d25436b Improved SEO of OpenBB Docs (#4774)
* Small typo

* Updated SEO for OpenBB Bot Docs

* Updated SEO for all SDK docs pages

* Updated all SEO for OpenBB Terminal Docs pages. Plus grammar edits

* Updated spelling edits for SDK and Terminal

* fix: headtitle component

* Updated Page titles for SDK and Terminal FAQ pages

* Updated page titles for all SDK docs pages

* Updated page titles for all Terminal Docs Pages (not reference pages)

* Updated page titles for Bot (not reference pages)

* Add | OpenBB Docs title for SDK and Terminal (#4883)

* add Terminal | OpenBB Docs

* SDK | OpenBB Docs added

---------

Co-authored-by: andrewkenreich <andrew.kenreich@gmail.com>
Co-authored-by: DidierRLopes <dro.lopes@campus.fct.unl.pt>
Co-authored-by: jose-donato <zmcdonato@gmail.com>
2023-04-25 13:58:58 +00:00

5.8 KiB
Vendored

title, keywords, description
title keywords description
Futures
forex
currency
money
hedge
dollar
euro
futures
future
interest
rates
forwards
commodities
bonds
treasuries
bond
gold
oil
openbb terminal
sdk
how to
usage
examples
path
type
description
import statement
search
curve
historical
Learn how to use and see examples of the Futures menu, which provides historical prices and the current term structure for an asset.

import HeadTitle from '@site/src/components/General/HeadTitle.tsx';

The functions from the OpenBB Terminal Futures menu is part of the SDK layer, and provides methods for programmatically accessing the data and charts associated with them. Get started by importing the OpenBB SDK to the Python script or Jupyter Notebook file.

How to Use

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

Path Type Description
openbb.futures.curve Function Futures Forward Curve Data
openbb.futures.curve_chart Function Futures Forward Curve Chart
openbb.futures.search Function Search Available Futures
openbb.futures.historical Function Historical OHLC+V Data
openbb.futures.historical_chart Function Chart Historical Price of Individual Contracts

Examples

Import Statements

The examples here will assume that the block below is included at the top of the file:

from openbb_terminal.sdk import openbb
import pandas as pd
%matplotlib inline

Futures can be searched by description, exchange, or category.

openbb.futures.search(description = 'Eurodollar')
Ticker Description Exchange Category
66 GE Eurodollar Futures CME currency
67 GLB One-Month Eurodollar Futures CME currency
152 SED SED (SOFR-Eurodollar) Spread Futures CME bonds

The historical front-month price is captured to a DataFrame with:

Curve

The forward curve data for a symbol is fetched with:

eurodollar = openbb.futures.curve('GE')
Expiration Futures
2022-11-01 00:00:00 95.3561
2022-12-01 00:00:00 94.9925
2023-01-01 00:00:00 94.985
2023-02-01 00:00:00 94.9
2023-03-01 00:00:00 94.825

To display a chart of the data, use curve_chart:

openbb.futures.curve_chart(symbol = 'GE')

openbb.futures.curve_chart

Historical

The historical function can fetch the historical front-month price:

wti_continuous = obb.futures.historical('CL')

Or, while actively trading, individual contracts. The example below requests historical data for the December WTI contract from 2023 to 2030, starting at the first recorded trading day of the December 2030 contract.

cl_2312 = openbb.futures.historical(symbols = ['CL'], expiry = '2023-12')
cl_2312 = cl_2312.rename(columns={'Adj Close':'2023-12'})
cl_2412 = openbb.futures.historical(symbols = ['CL'], expiry = '2024-12')
cl_2412 = cl_2412.rename(columns={'Adj Close':'2024-12'})
cl_2512 = openbb.futures.historical(symbols = ['CL'], expiry = '2025-12')
cl_2512 = cl_2512.rename(columns={'Adj Close':'2025-12'})
cl_2612 = openbb.futures.historical(symbols = ['CL'], expiry = '2026-12')
cl_2612 = cl_2612.rename(columns={'Adj Close':'2026-12'})
cl_2712 = openbb.futures.historical(symbols = ['CL'], expiry = '2027-12')
cl_2712 = cl_2712.rename(columns={'Adj Close':'2027-12'})
cl_2812 = openbb.futures.historical(symbols = ['CL'], expiry = '2028-12')
cl_2812 = cl_2812.rename(columns={'Adj Close':'2028-12'})
cl_2912 = openbb.futures.historical(symbols = ['CL'], expiry = '2029-12')
cl_2912 = cl_2912.rename(columns={'Adj Close':'2029-12'})
cl_3012 = openbb.futures.historical(symbols = ['CL'], expiry = '2030-12')
cl_3012 = cl_3012.rename(columns={'Adj Close':'2030-12'})

historical = pd.DataFrame(data = [cl_2312['2023-12'],cl_2412['2024-12'],cl_2512['2025-12'],cl_2612['2026-12'],cl_2712['2027-12'],cl_2812['2028-12'],cl_2912['2029-12'],cl_3012['2030-12']]).transpose()
historical = historical.dropna()

historical
Date 2023-12 2024-12 2025-12 2026-12 2027-12 2028-12 2029-12 2030-12
2020-01-24 00:00:00 49.61 50.14 50.7 51.56 51.63 51.63 51.63 51.63
2020-01-27 00:00:00 49.94 50.6 51.18 51.05 51.12 51.12 51.12 51.12
2020-01-28 00:00:00 50.17 50.78 51.23 51.55 51.62 51.62 51.62 51.62
2020-01-29 00:00:00 50.07 50.64 51.13 51.6 51.67 51.67 51.67 51.67
2020-01-30 00:00:00 50.27 50.91 51.44 51.49 51.56 51.56 51.56 51.56
2022-11-09 00:00:00 76.69 71.62 68.01 65.1 62.52 60.17 58.12 56.49
2022-11-10 00:00:00 77 71.64 67.89 64.86 62.26 59.91 57.86 56.23
2022-11-11 00:00:00 78.81 73.1 69.22 66.19 63.6 61.25 59.2 57.57
2022-11-14 00:00:00 77.4 72.35 68.89 66.15 63.62 61.25 59.13 57.5
2022-11-15 00:00:00 78.82 73.66 70.14 67.36 64.94 62.62 60.49 58.68