mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-10-27 20:42:26 +00:00
Adds Intro Guide to ETF SDK Module (#3315)
* Adds Intro Guide to ETF SDK Module * Linter * removes portfolio optimization snippet Co-authored-by: Jeroen Bouma <jer.bouma@gmail.com>
This commit is contained in:
84
website/content/SDK/etf/_index.md
vendored
84
website/content/SDK/etf/_index.md
vendored
@@ -1,6 +1,84 @@
|
||||
---
|
||||
title: etf
|
||||
keywords: ""
|
||||
excerpt: ""
|
||||
title: Introduction to ETF
|
||||
keywords: "etf, etfs, etn, fund, funds, blackrock, vanguard, fidelity, statestreet, spdr, exchange-traded, SPY, QQQ, TQQQ, SQQQ"
|
||||
excerpt: "This guide introduces the ETF module within the context of the OpenBB SDK"
|
||||
geekdocCollapseSection: true
|
||||
|
||||
---
|
||||
The ETF module wraps the functions from the ETF menu, within the OpenBB Terminal, allowing programmatic access to the commands. Import the OpenBB SDK module, and then find the ETF functions similarly to how the Terminal menus are navigated. The code completion will be activated after entering the `.` in: `openbb.etf`
|
||||
|
||||
```python
|
||||
from openbb_terminal.sdk import openbb
|
||||
import pandas as pd
|
||||
%matplotlib widget
|
||||
```
|
||||
|
||||

|
||||
|
||||
## How to Use
|
||||
|
||||
ETFs are categorized into different buckets, use. the code block below as a way to generate the list of all categories:
|
||||
|
||||
```python
|
||||
etf_list = pd.DataFrame.from_dict(openbb.etf.etf_by_category('')).transpose()
|
||||
etf_list.set_index(keys = ['category', 'family'])
|
||||
etf_list.sort_values(by=['total_assets'], ascending = False)
|
||||
|
||||
categories = list(etf_list['category'].drop_duplicates())
|
||||
```
|
||||
|
||||

|
||||
|
||||
After determining the category to research, the same code block can be repeated, replacing the empty category in the syntax:
|
||||
|
||||
```python
|
||||
etf_category = pd.DataFrame.from_dict(openbb.etf.etf_by_category('Trading--Leveraged Equity')).transpose()
|
||||
etf_category.sort_values(by=['total_assets'], ascending = False)
|
||||
```
|
||||
|
||||

|
||||
|
||||
A list of all tickers in the category can be generated from the index of the DataFrame:
|
||||
|
||||
```python
|
||||
tickers = list(etf_category.index)
|
||||
```
|
||||
|
||||
This list of tickers can then be used for comparison analysis, or portfolio optimization. For example, comparing the performance metrics of all Technology ETFs available:
|
||||
|
||||
```python
|
||||
performance = openbb.stocks.ca.screener(similar = tickers, data_type = 'performance')
|
||||
performance.sort_values(by=['Perf Quart'])
|
||||
```
|
||||
|
||||

|
||||
|
||||
To peer into the holdings of a specific ETF:
|
||||
|
||||
```python
|
||||
openbb.etf.holdings('NXTG')
|
||||
```
|
||||
|
||||

|
||||
|
||||
The ETF screener is accessible through the SDK. Values for the screener are set in the file: `~/OpenBBTerminal/openbb_terminal/etf/screener/presets/etf_config.ini`
|
||||
|
||||
```python
|
||||
openbb.etf.scr.screen(preset='etf_config.ini')
|
||||
```
|
||||
|
||||
In this example, the configuration file is set to return results with a maximum Beta value of -2.
|
||||
|
||||

|
||||
|
||||
The current top gainers, losers, and volume for ETFs is returned with:
|
||||
|
||||
```python
|
||||
openbb.etf.disc.mover(sort_type = 'decliners')
|
||||
|
||||
openbb.etf.disc.mover(sort_type = 'gainers')
|
||||
|
||||
openbb.etf.disc.mover(sort_type = 'active')
|
||||
```
|
||||
|
||||
")
|
||||
|
||||
Reference in New Issue
Block a user