Skip to main content

ETF

The ETF module provides programmatic access to the commands from within the OpenBB Terminal. Import the OpenBB SDK module, and then access the functions similarly to how the Terminal menus are navigated. The code completion will be activated upon entering ., after, openbb.etf

How to Use

​The examples provided below will assume that the following import block is included at the beginning of the Python script or Notebook file: ​

from openbb_terminal.sdk import openbb
import pandas as pd

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

PathTypeDescription
openbb.etf.candleFunctionChart OHLC + Volume + Moving Averages
openbb.etf.discSub-ModuleBest/Worst/Highest Volume ETFs Today
openbb.etf.etf_by_categoryFunctionLookup by Category
openbb.etf.etf_by_nameFunctionLookup by Name
openbb.etf.holdingsFunctionHoldings and Weights
openbb.etf.ldFunctionLookup by Description
openbb.etf.loadFunctionGet Historical Price Data
openbb.etf.lnFunctionLookup by Name (More Details Than by_name)
openbb.etf.newsFunctionNews Headlines for a Ticker
openbb.etf.overviewFunctionBasic Statistics for an ETF
openbb.etf.scrSub-ModuleETF Screener
openbb.etf.summaryFunctionText Description and Summary of an ETF
openbb.etf.symbolsDictionaryDictionary of {Ticker:Name}
openbb.etf.weightsFunctionTable or Pie Graph of Sector Weightings

Alternatively you can print the contents of the ETF SDK with: ​

help(openbb.etf)

Examples

etf_by_category

​ ETFs are categorized into different buckets. Use the code block below as a way to generate a list of all categories: ​

etf_list = pd.DataFrame.from_dict(openbb.etf.etf_by_category(''))
categories = list(etf_list['category'].drop_duplicates())
categories = pd.DataFrame(categories[1::], columns = ['Type'])

categories.head(6)
Type
Financials
Emerging Markets
Industrials
Factors
Utilities
Bonds

​Replacing the empty category in the syntax above will return the ETFs within that category: ​

etf_category = pd.DataFrame.from_dict(openbb.etf.etf_by_category('Emerging Markets'))
etf_category.head(2)
symbolnamecurrencysummarycategory_groupcategoryfamilyexchangemarket
AAXJiShares MSCI All Country Asia ex Japan ETFUSDThe investment seeks to track the investment results of the MSCI AC Asia ex Japan Index.EquitiesEmerging MarketsBlackRock Asset ManagementNMSus_market
The fund will invest at least 90% of its assets in the component securities of the index and in investments that have economic characteristics that are substantially identical to the component securities of the index. The index is a free float-adjusted market capitalization index designed to measure equity market performance of securities from the following 11 developed and emerging market countries or regions: China, Hong Kong, India, Indonesia, Malaysia, Pakistan, the Philippines, Singapore, South Korea, Taiwan and Thailand.
JHEMJohn Hancock Multifactor Emerging Markets ETFUSDThe investment seeks to provide investment results that closely correspond, before fees and expenses, to the performance of the John Hancock Dimensional Emerging Markets Index (the index).EquitiesEmerging MarketsJohn HancockPCXus_market
The fund normally invests at least 80% of its net assets (plus any borrowings for investment purposes) in securities included in the index, in depositary receipts representing securities included in the index, and in underlying stocks in respect of depositary receipts included in the index. The index is designed to comprise a subset of securities associated with emerging markets, which may include frontier markets (emerging markets in an earlier stage of development).

ETF Tickers

A list of all tickers in the specific category can be generated from the index of the above DataFrame, etf_category:

symbols = etf_category.index.to_list()

Performance Metrics

This list of tickers can then be used for comparison analysis, or portfolio optimization. For example, comparing the performance metrics of the Emerging Market category:

performance = openbb.stocks.ca.screener(similar = symbols, data_type = 'performance')
performance = performance.sort_values(by=['3M'], ascending=False)
performance.head(5)
Ticker1W1M3M6M1YYTD1W Volatility1M VolatilityRecomAvg VolumeRel VolumePriceChangeVolume
CHB0.0301-0.0150.11230.0086-0.132-0.12770.01050.004811300.048.220.012321
INCO0.01930.07160.10920.15430.27060.31710.00660.0049178101.6259.770.007314060
GLIN0.02510.07330.10830.2210.27040.33190.01050.0079203600.8943.50.01338833
ILF0.04970.06310.10320.0620.30820.27680.01410.01351.18e+062.1629.230.02151237337
SMIN0.01740.05730.09140.21280.28480.34470.00780.0074999805.6169.60.0053272774

Holdings

To peer into the holdings of a specific ETF:

holdings = openbb.etf.holdings('DIA').reset_index()
holdings.head(5)
SymbolName% Of EtfShares
0UNHUnitedHealth Group Incorporated10.09%5985297
1GSThe Goldman Sachs Group, Inc.7.51%5985297
2HDThe Home Depot, Inc.6.03%5985297
3AMGNAmgen Inc.5.61%5985297
4MCDMcDonald's Corporation5.35%5985297

Disc

The current top gainers, losers, and volume for ETFs is returned with:

openbb.etf.disc.mover(sort_type = 'decliners')

openbb.etf.disc.mover(sort_type = 'gainers')

openbb.etf.disc.mover(sort_type = 'active')

With no sort_type chosen, it will default to gainers:

movers = openbb.etf.disc.mover()
movers.head(5)
PriceChg%ChgVol
0Direxion Daily Semiconductor Bear 3X Shares35.31013.310110.3424.5M
1ProShares UltraShort Bloomberg Natural Gas18.091.197.044.4M
2MicroSectors FANG & Innovation -3x Inverse Leveraged ETN28.981.836.74160.1K
3Direxion Daily Dow Jones Internet Bear 3X Shares32.141.916.32554.2K
4Direxion Daily S&P 500 High Beta Bear 3X Shares6.46520.37526.161.2M