mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-10-27 20:42:26 +00:00
Adds Introduction Guide for the Economy SDK Module (#3142)
* Adds Introduction Guide for the Economy SDK Module * Changes title Co-authored-by: Jeroen Bouma <jer.bouma@gmail.com>
This commit is contained in:
111
website/content/SDK/economy/_index.md
vendored
111
website/content/SDK/economy/_index.md
vendored
@@ -1,6 +1,111 @@
|
||||
---
|
||||
title: economy
|
||||
keywords: ""
|
||||
excerpt: ""
|
||||
title: Introduction to Economy
|
||||
keywords: "fred, sdk, api, bonds, treasury, treasuries, spread, events, calendar, futures, future, yield, curve, macro, index, indices, performance, bigmac, series, gdp, indicators"
|
||||
excerpt: "This guide introduces the Economy module within the OpenBB SDK and provides some use examples."
|
||||
geekdocCollapseSection: true
|
||||
---
|
||||
The Economy module wraps the functions of the <a href="https://openbb-finance.github.io/OpenBBTerminal/terminal/economy/" target="_blank">Economy menu</a>, within the <a href="https://openbb-finance.github.io/OpenBBTerminal/terminal/" target="_blank">OpenBB Terminal</a>, and provides the user with more control over their workflow. In a Jupyter Notebook environment, it is quick and easy to get going. Start a new `.ipynb` Notebook file, or a `.py` Python script by importing the necessary modules for the tasks at hand. For the purpose of these examples, two additional modules will be imported:
|
||||
````
|
||||
from openbb_terminal.sdk import openbb
|
||||
import pandas as pd
|
||||
%matplotlib inline
|
||||
````
|
||||
Jupyter Lab can be launched from the command line, in the `OpenBBTerminal` folder and with the Conda environment already activated, by entering either: `jupyter lab`, or, `jupyter notebook`; and then pressing `enter`. This will launch a browser window for the session.
|
||||
|
||||
To get the most out of these functions, it is highly recommended to acquire an API key to access the FRED data library. This is free, just create an account <a href="https://fred.stlouisfed.org" target="_blank"> here</a>, then look in the account settings for the assigned API key.
|
||||
|
||||
Refer to the <a href="https://openbb-finance.github.io/OpenBBTerminal/SDK/keys/" target="_blank">Introduction Guide to API Keys within the OpenBB SDK</a> for instructions on setting the API keys, with the Keys module.
|
||||
|
||||
## How to Use
|
||||
|
||||
With the modules imported, the code completion is activated after entering the `.` after, `openbb.economy`
|
||||
|
||||

|
||||
|
||||
Just like the other modules, there are several methods for returning the docstrings of a single function:
|
||||
|
||||
- Use Python's built-in help: `help(openbb.economy.index)`
|
||||
- View the documentation online: https://openbb-finance.github.io/OpenBBTerminal/SDK/economy/index/
|
||||
- Open the Contextual Help window
|
||||
````
|
||||
openbb.economy.index(indices = ['nyse', 'nasdaq', 'amex', 'ca_tsx', 'dow_dji', 'in_nse50'])
|
||||
````
|
||||
|
||||

|
||||
|
||||
There are some differences when comparing SDK functions against the OpenBB Terminal commands. For example, the Terminal command, `/economy/index --show`, becomes: `openbb.economy.available_indices()`. This returns a list of dictionaries; convert them to a DataFrame with:
|
||||
````
|
||||
pd.DataFrame.from_dict(openbb.economy.available_indices()).transpose()
|
||||
````
|
||||
|
||||

|
||||
|
||||
To display a chart inside the Notebook, instead of a DataFrame, add `chart = True` to the command syntax. For example:
|
||||
````
|
||||
openbb.economy.index(indices = ['sp500', 'sp500tr'], chart = True)
|
||||
````
|
||||
|
||||

|
||||
|
||||
It is also possible to make a DataFrame of a stock and an index. The list of symbols fed to the `index` function can be the dictionary name from, `openbb.economy.available_indices()`, or it can be a ticker symbol that is recognized by `yFinance`. As an example:
|
||||
````
|
||||
openbb.economy.index(indices = ['move', 'aapl'], chart = True, start_date = '2016-01-01')
|
||||
````
|
||||
|
||||

|
||||
|
||||
Another notable difference, between OpenBB Terminal commands and their corresponding SDK functions, is the way `fred` works. With the OpenBB SDK, the `fred` function is broken down into four components, as shown here:
|
||||
|
||||

|
||||
|
||||
`openbb.economy.fred_yield_curve()` returns a Tuple with the raw data for composing the chart presented by the OpenBB Terminal function, `/economy/ycrv --source fred`.
|
||||
|
||||
````
|
||||
data, date = openbb.economy.fred_yield_curve()
|
||||
````
|
||||
|
||||

|
||||
|
||||
The FRED library can be searched, by key words and phrases, in two ways:
|
||||
|
||||
- `openbb.economy.fred_notes('search term')`
|
||||
- `openbb.economy.fred_ids('search term')`
|
||||
|
||||
The former, giving more details than the latter.
|
||||
|
||||

|
||||
|
||||
Retrieving the time-series data is then accomplished by using the `fred_series` function:
|
||||
|
||||
````
|
||||
openbb.economy.fred_series(series_ids = ['PCENOW','GDPNOW'])
|
||||
````
|
||||
|
||||

|
||||
|
||||
Other functions more closely resemble their counterpart within the OpenBB Terminal, such as: `openbb.economy.bigmac(country_codes = ['CAN','USA'])`
|
||||
|
||||

|
||||
|
||||
Adding `chart = True` to the syntax will display the graph:
|
||||
|
||||
````
|
||||
openbb.economy.bigmac(country_codes = ['CAN','USA'], chart = True)
|
||||
````
|
||||
|
||||

|
||||
|
||||
The `performance` and `valuation` functions, compared against the OpenBB Terminal, are also similar. Note that data returned by these functions are inclusive only of companies with an active and public US listing.
|
||||
|
||||
````
|
||||
openbb.economy.performance()
|
||||
openbb.economy.valuation()
|
||||
````
|
||||
|
||||

|
||||
|
||||
````
|
||||
openbb.economy.performance(group = 'industry')
|
||||
````
|
||||
|
||||

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