- Advertisement -Newspaper WordPress Theme
Algorithm tradingOpenBB Platform - A Complete Guide - AlgoTrading101 Blog

OpenBB Platform – A Complete Guide – AlgoTrading101 Blog


What is the OpenBB Platform?

The OpenBB Platform is an open-source modular financial analysis ecosystem.

It integrates with close to 100 different data sources from asset classes such as equity, options, crypto, forex, macro economy, fixed income, alternative datasets, and more.

Before we dive in deeper, take note that I’m the OpenBB Platform engineering team lead and that I will do my best to make sure this article isn’t biased.

Website: https://openbb.co/products/platform

GitHub: https://github.com/OpenBB-finance/OpenBBTerminal

What are the OpenBB Platform main features?

The main OpenBB Platform features come from its architecture which consists of the OpenBB Core and various Extensions, including Providers and Toolkits. The Core facilitates the development of custom applications with streamlined data provider connections, while the Extensions offer categorized data access and enhanced functionalities.

This design ensures a flexible, lightweight platform that easily integrates into different environments, avoiding the complexity and dependency issues of its predecessor.

Thus, the main features are these:

  • lightweight
  • modular
  • supports a Python and Web API interface
  • offers data standardization between providers
  • easily extendable
  • great documentation
  • free and open-sourced
  • secure

What interfaces does the OpenBB Platform have?

The OpenBB Platform features two interfaces which are the Python and Web API interface. The Python interface allows Python devs a seamless developing experience with robust and extendable code, type hinting, good documentation, etc.

The Web API allows any frontend to easily incorporate the available endpoints of the OpenBB Platform and integrate them into any programming language or framework of choice.

The only difference you might notice is that some endpoints will be available on the Python interface and not on the Web API interface. This is because the Web API interface requires everything to be serializable.

There are only a handful of econometrics endpoints that aren’t present on the Web API interface and the econometrics package is an optional one.

How to get started with the OpenBB Platform?

To get started with the OpenBB Platform, you will need to install it into a fresh environment. Having an OpenBB Hub account is highly advisable so that you can have all of your API keys in one place across all OpenBB products.

For this article, I’ll be installing only the base providers and extensions so that we can gradually pick what we need. You can also install everything that there is by adding the [all] flag. The version of openbb that I’ll be demoing in this article is openbb-4.1.2.

Now, let us go over and create an OpenBB Hub account that we can log into from the OpenBB Platform and thus have our API keys recognized. For those who want to follow along, providers such as CBOE and Yahoo Finance provide data and don’t require API keys.

To get our OpenBB Hub account ready, navigate to the website that is found on the following URL: https://my.openbb.co/login

Then either choose to register manually or log in with your Google account or equivalent. When you log in, you will be greeted by the landing page of the Hub and be able to see all of the OpenBB products.

Select the OpenBB Terminal and then on the left side of the screen you will see the API Keys section. Please navigate there and add your API keys. For this article, I’ll only be using FMP, Polygon, FRED, Intrinio, and Benzinga as providers that require an API key.

Now, one final step that we can do is to create a PAT (Personal Access Token) that we can use to log into our OpenBB Hub from the Python interface. To create a PAT, click on its title on the left side of your screen and then click the “Generate” button with a preferred expiry date.

You will be presented with your key and with the command that we want to run now to log in:

from openbb import obb
obb.account.login(pat="<YOUR_TOKEN>")

On first import, the extensions will be building their Python static assets that are used to provide a good Python development experience. Once built, you will have everything you need to get going.

The OpenBB Platform is comprised of several “menus” that are either utility ones or routers that serve as entry points into different asset classes and their commands. Because it is modular, your available commands, routers, and installed extensions will look different depending on what you installed.

Here is what the current core environment looks like:

OpenBB Platform v4.1.2

Utilities:
    /account
    /user
    /system
    /coverage

Routers:
    /crypto
    /currency
    /derivatives
    /economy
    /equity
    /etf
    /fixedincome
    /index
    /news
    /regulators

Extensions:
    - [email protected]
    - [email protected]
    - [email protected]
    - [email protected]
    - [email protected]
    - [email protected]
    - [email protected]
    - [email protected]
    - [email protected]
    - [email protected]

    - [email protected]
    - [email protected]
    - [email protected]
    - [email protected]
    - [email protected]
    - [email protected]
    - [email protected]
    - [email protected]
    - [email protected]
    - [email protected]    

A full list of available OpenBB Platform extensions can be found here: https://my.openbb.co/app/platform/extensions

From the utilities, you can access your user by navigating to the namespace of the obb.user. You can control your account and log out from the obb.account namespace and view your system settings from the obb.system namespace.

In the following headers, we will be exploring some of the things that the OpenBB Platform has to offer and the goal will be to get comfortable with using it and exploring.

How to explore OpenBB Platform commands?

There are several ways of exploring the OpenBB Platform commands. You can visit the documentation that is found on the following URL and explore the reference section that will show you all the menus and their commands.

Each command will have documentation on how to use it, what are the standard query parameters and what are the specific ones to each provider that supports the command. The same will be shown for the command outputs.

These standards are a product of the standardization framework, but more about that later.

Another way of exploring the commands is through your Python interface. You can simply do obb. and your intelisense should be picking up on what is available. Then you can go one layer deeper and do obb.equity. and see what is there.

Once you get to a particular command that you would like to try out, you can add a question mark at its end to get its signature, the docstring of the command, and all the details. For example:

obb.equity.price.performance?
Price performance as a return, over different periods.

Parameters
----------
symbol : str
    Symbol to get data for.
provider : Optional[Literal['fmp']]
    The provider to use for the query, by default None.
    If None, the provider specified in defaults is selected or 'fmp' if there is
    no default.

Returns
-------
OBBject
    results : List[PricePerformance]
        Serializable results.
    provider : Optional[Literal['fmp']]
        Provider name.
    warnings : Optional[List[Warning_]]
        List of warnings.
    chart : Optional[Chart]
        Chart object.
    extra: Dict[str, Any]
        Extra info.

PricePerformance
----------------
one_day : Optional[float]
    One-day return. 
wtd : Optional[float]
    Week to date return. 
one_week : Optional[float]
    One-week return. 
mtd : Optional[float]
    Month to date return. 
one_month : Optional[float]
    One-month return. 
qtd : Optional[float]
    Quarter to date return. 
three_month : Optional[float]
    Three-month return. 
six_month : Optional[float]
    Six-month return. 
ytd : Optional[float]
    Year to date return. 
one_year : Optional[float]
    One-year return. 
three_year : Optional[float]
    Three-year return. 
five_year : Optional[float]
    Five-year return. 
ten_year : Optional[float]
    Ten-year return. 
max : Optional[float]
    Return from the beginning of the time series. 
symbol : Optional[str]
    The ticker symbol. (provider: fmp)

Example
-------
>>> from openbb import obb
>>> obb.equity.price.performance(symbol="AAPL")

Here you will see a detailed presentation of the command parameters at your disposal, the structure of the OBBject, and the outputs of the model that you can expect. It is also provided with an example that you can use.

What is the OBBject?

The OBBject is the OpenBB result object (hence OBBject 😀 ) which is a standardized object that will be returned on every call execution. It will hold your results, warnings during the command execution, any extra info, charts, or something that an OBBject extension might add.

OBBject
    results : List[PricePerformance]
        Serializable results.
    provider : Optional[Literal['fmp']]
        Provider name.
    warnings : Optional[List[Warning_]]
        List of warnings.
    chart : Optional[Chart]
        Chart object.
    extra: Dict[str, Any]
        Extra info.

The OBBject also comes with custom helpers that can present your data in different ways such as to_df(), to_dict(), to_json(), etc.

How does the OpenBB Platform perform standardization?

The OpenBB Platform performs standardization by utilizing Pydantic v2 and standard data models that define the standard set of query parameters and resulting output fields for a particular command.

The standard is defined based on the intersection of fields that are shared between two or more providers that can fuel the same command. It is also based on the financial knowledge of the OpenBB team.

These standard models ensure that you can easily switch out a provider and compare apples to apples by just changing the provider query parameter. It will also guarantee a set of fields that are expected to always be returned by any of the supported providers and a set of query parameters that will work for all of them.

Saying this, the OpenBB Platform will always allow you to use any provider-specific query parameters, and all provider-specific fields that aren’t a part of the standard are documented and returned too.

To illustrate this, we can see what the standard query parameters for this command look like and how they change when SEC is the provider:

We can also observe the difference between the output of the same command and when the provider is Intrinio:

This is a very powerful feature and it will allow for seamless switching between different data providers and you won’t need to worry about different API conventions, naming, libraries, etc.

How to get stock data with the OpenBB Platform?

To get stock data with the OpenBB Platform, you will need to access the equity router under which you will find the data for that sector. It will consist of commands and/or sub-routers that you can access. To view what is available we can do:

/equity
    /calendar
    /compare
    /discovery
    /estimates
    /fundamental
    market_snapshots
    /ownership
    /price
    profile
    screener
    search
    /shorts

Now, let us get historical price data by navigating to the price sub-router and using the historical command.

obb.equity.price.historical("LUV")
OBBject

id: 065abf67-8e3b-71af-8000-3b73cf8eb7f7
results: [{'date': datetime.datetime(2024, 1, 19, 0, 0), 'open': 30.14, 'high': 30....
provider: fmp
warnings: None
chart: None
extra: {'metadata': {'arguments': {'provider_choices': {'provider': None}, 'standar...

Here you will see the OBBject with your results and other information. To get this data as a dataframe we can write it as:

obb.equity.price.historical("LUV").to_df().head()

You can now easily change the default provider which is FMP to another one such as Intrinio:

obb.equity.price.historical("LUV", provider="intrinio").to_df().head()

You can install matplotlib, plotly, or any preferred charting library to create charts. The OpenBB Platform also features a charting extension that can do this. It is currently in the reworks so I won’t be demoing it here.

How to get fundamental data with the OpenBB Platform?

To get fundamental data with the OpenBB Platform, you can visit the equity.fundamental router and get fundamental data such as balance sheets, cash flow statements, income statements, and more.

/equity/fundamental
    balance
    balance_growth
    cash
    cash_growth
    dividends
    employee_count
    filings
    historical_attributes
    historical_eps
    historical_splits
    income
    income_growth
    latest_attributes
    management
    management_compensation
    metrics
    multiples
    overview
    ratios
    reported_financials
    revenue_per_geography
    revenue_per_segment
    search_attributes
    trailing_dividend_yield
    transcript

Now, we will get the revenue per geography and the annual cash flow statement:

obb.equity.fundamental.revenue_per_geography("LUV").to_df()
	period_ending	fiscal_period	fiscal_year	filing_date	geographic_segment
0	2018-12-31	FY	2018	2019-02-05	{'Latin America': 566000000, 'North America': ...
1	2019-12-31	FY	2019	2020-02-04	{'Latin America': 615000000, 'North America': ...
2	2020-12-31	FY	2020	2021-02-08	{'Latin America': 184000000, 'North America': ...
3	2021-12-31	FY	2021	2022-02-07	{'Latin America': 475000000, 'North America': ...
4	2022-12-31	FY	2022	2023-02-07	{'Latin America': 811000000, 'North America': ...
obb.equity.fundamental.cash("LUV", provider="intrinio").to_df().transpose()

How to get ETF data with the OpenBB Platform?

To get ETF data with the OpenBB Platform, we can utilize the obb.etf router and the commands within it. For example, the ETF data router has access to the following commands:

/etf
    countries
    holdings
    holdings_date
    holdings_performance
    info
    price_performance
    search
    sectors

Let us obtain the price performance of SPY and QQ:

obb.etf.price_performance(["SPY", "QQQ"]).to_df().transpose()
	        0	        1
one_day	        0.012466	0.019831
one_week	0.015087	0.03152
one_month	0.030261	0.044904
three_month	0.145398	0.187761
six_month	0.066898	0.1179
ytd	        0.020692	0.046176
one_year	0.218627	0.489953
three_year	0.256688	0.300862
five_year	0.835312	1.60084
ten_year	1.61934	        3.756409
max	        9.97929	        7.248727
symbol	        SPY	        QQQ

Now, let us also see the weight of an ETF across different sectors:

obb.etf.sectors("QQQ").to_df()
	sector	weight
0	Cash	0.000496
1	Commercial Services	0.005482
2	Communications	0.014800
3	Consumer Durables	0.030500
4	Consumer Non-Durables	0.039200
5	Consumer Services	0.054000
6	Distribution Services	0.003061
7	Electronic Technology	0.294000
8	Energy Minerals	0.002089
9	Health Technology	0.069300
10	Industrial Services	0.002386
11	Producer Manufacturing	0.023200
12	Retail Trade	0.104600
13	Technology Services	0.334200
14	Transportation	0.011600
15	Utilities	0.011200

How to perform quantitative analysis with the OpenBB Platform?

To perform quantitative analysis with the OpenBB Platform, you will need to make sure that the openbb-quantitative library is installed. By having it installed, you will unlock a new pathway which is the obb.quantitative router and its endpoints.

Let us install it by running:

pip install openbb-quantitative

After installing it, make sure to restart the notebook and import again obb so that it builds the Python static assets for the added extension.

/quantitative
    capm
    kurtosis
    normality
    omega_ratio
    quantile
    sharpe_ratio
    skewness
    sortino_ratio
    summary
    unitroot_test

Now, let us run a normality test on the adjusted close data:

luv_historical = obb.equity.price.historical("LUV").to_df()
obb.quantitative.normality(data=luv_historical, target="adj_close").to_df()
0	kurtosis	statistic=-1.980922466143507 p_value=0.0475999...
1	skewness	statistic=-0.7194281764567769 p_value=0.471877...
2	jarque_bera	statistic=3.0962272128471486 p_value=0.2126487...
3	shapiro_wilk	statistic=0.98307204246521 p_value=0.004416265...
4	kolmogorov_smirnov	statistic=1.0 p_value=0.0

How to perform technical analysis with the OpenBB Platform?

To perform technical analysis with the OpenBB Platform, you will need to make sure that the openbb-technical library is installed. By having it installed, you will unlock a new pathway which is the obb.technical router and its endpoints.

Let us install it by running:

pip install openbb-technical

Whenever you add a new extension, you will need to restart and re-import the library so it gets picked up accordingly. Let us see what we have unlocked:

/technical
    ad
    adosc
    adx
    aroon
    atr
    bbands
    cci
    cg
    clenow
    cones
    demark
    donchian
    ema
    fib
    fisher
    hma
    ichimoku
    kc
    macd
    obv
    rsi
    sma
    stoch
    vwap
    wma
    zlma

Now, I will calculate the length of 14 RSI on the adjusted closing prices:

obb.technical.rsi(data=luv_historical, target="adj_close").to_df().tail(10)[
    "adj_close_RSI_14"
]
241    57.444245
242    57.199409
243    58.470221
244    60.907707
245    61.714351
246    50.706565
247    51.800099
248    47.213098
249    59.399720
250    59.093636

How to perform econometrics analysis with the OpenBB Platform?

To perform econometrics analysis with the OpenBB Platform, you will need to install the openbb.econometrics extension that will unlock the obb.econometrics router for usage.

Let us install it by running:

pip install openbb-econometrics

After restarting and re-importing obb, we can now start using the following set of functions:

/econometrics
    autocorrelation
    causality
    cointegration
    correlation_matrix
    ols_regression
    ols_regression_summary
    panel_between
    panel_first_difference
    panel_fixed
    panel_fmac
    panel_pooled
    panel_random_effects
    residual_autocorrelation
    unit_root

Now, we can do an autocorrelation test for the adjusted close column:

obb.econometrics.correlation_matrix(
    data=luv_historical,
).to_df()

We can also do an OLS Regression which will return a statsmodel object:

obb.econometrics.ols_regression(
    data=luv_historical,
    y_column="adj_close",
    x_columns=["high", "low", "open"],
).results["results"].summary()

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Subscribe Today

GET EXCLUSIVE FULL ACCESS TO PREMIUM CONTENT

SUPPORT NONPROFIT JOURNALISM

EXPERT ANALYSIS OF AND EMERGING TRENDS IN CHILD WELFARE AND JUVENILE JUSTICE

TOPICAL VIDEO WEBINARS

Get unlimited access to our EXCLUSIVE Content and our archive of subscriber stories.

Exclusive content

- Advertisement -Newspaper WordPress Theme

Latest article

More article

- Advertisement -Newspaper WordPress Theme