Streamlining Research and Analysis with OpenBB

adityadeshlahre

Aditya Deshlahre

Posted on October 30, 2024

Streamlining Research and Analysis with OpenBB

Introduction

For investors aiming to make informed decisions, a simple glance at price trends isn’t enough—they require a thorough examination of a company's fundamentals. OpenBB Terminal, an open-source investment research platform, equips users with a robust toolkit for conducting in-depth fundamental analysis. In this post, we'll explore the key features of OpenBB for fundamental analysis and provide practical examples to help you get started.

What is OpenBB Terminal?

OpenBB Terminal is a free, open-source command-line interface (CLI) platform tailored for comprehensive research in stocks, cryptocurrencies, options, ETFs, and more. With its extensive feature set, retail investors can perform analyses comparable to those conducted by institutional analysts—without the burden of costly subscription fees.

General System Requirements

To install OpenBB, you'll need:

  • Python Compatibility: OpenBB is compatible with Python versions 3.9 to 3.12.
  • Hardware: A modern processor (within the last five years) and at least 4GB of RAM.
  • Operating System: Up-to-date systems are recommended, with the following OS minimums:
    • Windows: Windows 10 or newer
    • macOS: Big Sur or newer
    • Linux: For Linux users, it’s best to update your package manager before installation.

Supported Environments

OpenBB is installed in a Python virtual environment to avoid conflicts and ensure stability. Python environments can be created via Conda, venv, or an integrated development environment (IDE) like VS Code or PyCharm. For Docker users, there’s an installation method specific to Docker containers, which we cover below.

Tip: If you’re new to Python, we recommend reading up on virtual environments to understand how they help manage dependencies. Check out our guide on setting up environments in VS Code for additional help.


Installation Steps

  1. Update the Package Manager Ensure you’re working with the latest version of pip by running:
pip install --upgrade pip
Enter fullscreen mode Exit fullscreen mode
  1. Create a Virtual Environment To keep OpenBB isolated from other Python projects, create a dedicated virtual environment. Here’s how with Conda:
conda create -n openbb python=3.11
conda activate openbb
Enter fullscreen mode Exit fullscreen mode

Note: Installing packages directly into the system Python or base environment is not recommended.

  1. Install OpenBB Install via your preferred method below:
  • PyPI: You can install OpenBB directly from the Python Package Index.
  • Docker: Docker setup offers isolation and ease of use. (See Docker-specific instructions below.)
  • Source: For developers or advanced users, installing from the source allows more customization.

Lets get started on how to install Open BB

Now OpenBB Platform can be installed as PyPI package using this command

pip install openbb
Enter fullscreen mode Exit fullscreen mode

Installing All Extensions and Providers

For a comprehensive installation that includes all available extensions and data providers, run:

pip install openbb[all]
Enter fullscreen mode Exit fullscreen mode

Tip for macOS Users: If you’re using the zsh shell, add quotation marks around the library name:

pip install "openbb[all]"

Enter fullscreen mode Exit fullscreen mode

Installing Specific Extensions and Providers

OpenBB is modular, which means you can pick and choose the features you need. Here’s how to install specific extensions or providers based on your analysis needs.

Single Extension Installation:

For charting tools:

pip install openbb[charting]

Enter fullscreen mode Exit fullscreen mode

For technical analysis tools:

pip install openbb[ta]
Enter fullscreen mode Exit fullscreen mode

Single Provider Installation:

For the Yahoo Finance API integration:

pip install openbb[yfinance]

Enter fullscreen mode Exit fullscreen mode

Nightly Distribution: The Cutting Edge

If you want to test the latest features, install the Nightly build. This includes all extras by default:

pip install openbb-nightly

Enter fullscreen mode Exit fullscreen mode

This version may include new and experimental features but could also have minor instabilities, so it’s best suited for users who don’t mind testing cutting-edge updates.

Importing OpenBB

To start using OpenBB after installation, import it into your Python environment:

from openbb import obb
Enter fullscreen mode Exit fullscreen mode

Note: Because of OpenBB’s structure, this single import line is necessary to access the platform. Imports such as from openbb.obb.equity import * are currently unsupported, so always use from openbb import obb for a stable experience.

When you load OpenBB, any installed extensions will automatically be detected and made available, so you can start using all features right away.

Installing the Core Package Only

If you want to install OpenBB without any extensions or providers, opt for the minimal openbb-core package:

pip install openbb-core && pip install openbb --no-deps

Enter fullscreen mode Exit fullscreen mode

This installs the core platform only, giving you the flexibility to add specific tools as needed later on.

Keeping OpenBB Updated

To make sure you’re working with the latest features, update the OpenBB package regularly. Here’s how:

Core Package Update:

pip install --upgrade openbb
Enter fullscreen mode Exit fullscreen mode

Update All Extensions and Providers:

pip install --upgrade openbb[all]
Enter fullscreen mode Exit fullscreen mode

Installing OpenBB with Docker

Using Docker, you can set up the OpenBB Platform directly from the GitHub Container Registry or by building the Docker image from the source. Here’s how.

Pulling OpenBB from GitHub Container Registry
To get started quickly, use the prebuilt Docker image from GitHub’s Container Registry. Run the following command in your terminal:

docker run --rm -p 8000:8000 -v ~/.openbb_platform:/root/.openbb_platform ghcr.io/openbb-finance/openbb-platform:latest

Enter fullscreen mode Exit fullscreen mode

Options explained:
--rm: Automatically removes the container when it stops.
-p 8000:8000: Exposes the API on port 8000.
-v ~/.openbb_platform:/root/.openbb_platform: Mounts the local ~/.openbb_platform directory into the container to store your API keys and preferences.

Building OpenBB from Source

For a more customizable setup, you can build the OpenBB Docker image from the source using the platform.dockerfile provided in the GitHub repository.

Clone the OpenBB Repository: If you haven’t already, clone the OpenBB GitHub repository to access the Dockerfile.

git clone https://github.com/openbb-finance/openbb-platform.git
cd openbb-platform
Enter fullscreen mode Exit fullscreen mode

Build the Docker Image:

docker build -f build/docker/platform.dockerfile -t openbb-platform:latest .
Enter fullscreen mode Exit fullscreen mode

Run the Docker Container:

docker run --rm -p 8000:8000 -v ~/.openbb_platform:/root/.openbb_platform openbb-platform:latest

Enter fullscreen mode Exit fullscreen mode

By mounting the ~/.openbb_platform directory, this setup saves your API keys and preferences, ensuring they remain accessible each time you run OpenBB in Docker.

Accessing the OpenBB API
Once the container is running, you can access the OpenBB API on localhost:8000. For advanced use, consider customizing port settings or specifying different configuration files using Docker options.


Othe way: By cloning the repository directly

Step 1: Set Up a Python Virtual Environment

Creating a virtual environment is recommended to avoid conflicts with other Python packages.

Create and activate the environment:

python -m venv openbb_env
source openbb_env/bin/activate   # On Windows, use `openbb_env\Scripts\activate`
Enter fullscreen mode Exit fullscreen mode

Upgrade pip and setuptools to ensure compatibility:

pip install --upgrade pip setuptools
Enter fullscreen mode Exit fullscreen mode

Step 2: Install Git
Make sure Git is installed so you can clone the OpenBB repository.

pip install git
Enter fullscreen mode Exit fullscreen mode

Step 3: Clone the OpenBB Repository
Now, pull the source code directly from OpenBB’s GitHub repository.

git clone git@github.com:OpenBB-finance/OpenBB.git
cd OpenBB
Enter fullscreen mode Exit fullscreen mode

Switch to the Desired Branch
If you’re interested in working with the latest developments, switch to the develop branch:

git checkout develop
Enter fullscreen mode Exit fullscreen mode

Step 4: Install Poetry
OpenBB uses Poetry for package management, so it needs to be installed before proceeding.

pip install poetry
Enter fullscreen mode Exit fullscreen mode

Step 5: Run the Developer Installation Script
To complete the setup, use the dev_install.py script to install the core OpenBB platform along with any dependencies.

python dev_install.py
Enter fullscreen mode Exit fullscreen mode

Optional: Install All Extensions and Providers
If you'd like access to all available OpenBB extensions and data providers, add the -e flag:

python dev_install.py -e
Enter fullscreen mode Exit fullscreen mode

Rest of the installation-related docs can be found here


Post-Installation Steps for OpenBB

After completing the installation of the OpenBB platform, whether from source or using another method, you’ll need to ensure that the Python interface is set up correctly. Here’s a step-by-step guide to ensure everything runs smoothly, including how to initiate the REST API.

Step 1: Build the Python Interface
With a new installation or any time you add or remove extensions, you’ll need to build the Python interface. This build process is triggered automatically upon installation, but you can also run it manually if required.

Open a Python session:

python

Enter fullscreen mode Exit fullscreen mode

Import OpenBB to initiate the interface:

from openbb import obb
Enter fullscreen mode Exit fullscreen mode

Exit the Python session after this initialization step:

exit()
Enter fullscreen mode Exit fullscreen mode

Manually Triggering the Build
If you need to rebuild the interface (e.g., after installing new extensions), follow these steps:

import openbb
openbb.build()
Enter fullscreen mode Exit fullscreen mode

After running this, restart the Python interpreter.

Step 2: Start Using the OpenBB Platform
With the environment properly set up, you can now start leveraging OpenBB’s functionality.

from openbb import obb
Enter fullscreen mode Exit fullscreen mode

Step 3: Starting the REST API
If you’re interested in leveraging OpenBB’s REST API for programmatic access to its data and analysis capabilities, here’s how to get it running.

Run the following command to start the REST API:

uvicorn openbb_core.api.rest_api:app --host 0.0.0.0 --port 8000 --reload

Enter fullscreen mode Exit fullscreen mode

This command launches the REST API on port 8000, making it accessible at http://localhost:8000.


Now lets learn some basic syntax. Official Docs here

Key Parameters Across OpenBB Commands

OpenBB’s standardized parameters appear at the start of each function docstring, making it easy to identify required inputs. Here are the essential ones:

  • provider
  • symbol
  • start_date
  • end_date
  • date
  • limit

Let’s dive into each parameter and how to use them in your queries.

  1. Provider: Choosing Your Data Source The provider parameter specifies the data source, allowing flexibility in data selection based on your preferred provider. For example:
historical_prices = obb.equity.price.historical("aapl", provider="alpha_vantage")
Enter fullscreen mode Exit fullscreen mode

If no provider is specified, OpenBB defaults to the first alphabetically installed provider, unless one is defined in the user settings. Available provider coverage can be checked with:

obb.coverage.providers
Enter fullscreen mode Exit fullscreen mode
  1. Symbol: Specifying Your Asset The symbol parameter identifies the asset you want data for. OpenBB accommodates multiple symbol formats and input methods:

Single Symbol

quote = obb.equity.price.quote(symbol="td", provider="fmp")
Enter fullscreen mode Exit fullscreen mode

Multiple Symbols

Using a comma-separated string:

quotes = obb.equity.price.quote("td,schw,jpm,ms", provider="fmp")
Enter fullscreen mode Exit fullscreen mode

Using a Python list:

quotes = obb.equity.price.quote(["td", "schw", "jpm", "ms"], provider="fmp")
Enter fullscreen mode Exit fullscreen mode
  1. Dates: Specifying Timeframes for Data Dates are a fundamental part of most data queries. OpenBB supports both date strings in the "YYYY-MM-DD" format and datetime objects.

Example with date strings:

historical_prices = obb.equity.price.historical(symbol="qqq", start_date="2023-01-10", end_date="2023-01-31", provider="fmp")

Enter fullscreen mode Exit fullscreen mode

Using datetime objects:

from datetime import datetime
start = datetime.strptime("100123", "%d%m%y")
end = datetime.strptime("2023-01-31","%Y-%m-%d")
historical_prices = obb.equity.price.historical("qqq", start_date=start, end_date=end, provider="fmp")
Enter fullscreen mode Exit fullscreen mode
  1. Limit: Restricting Data Quantity The limit parameter controls the number of results returned, helping manage large datasets by limiting the output to the most recent data or from a specified start date.
income = obb.equity.fa.income("AAPL", period="quarter", provider="fmp", limit=4)

Enter fullscreen mode Exit fullscreen mode
  1. Using **kwargs for Flexibility OpenBB commands support additional arguments through **kwargs, allowing easy parameter expansion for complex queries. Here’s how to use them:
kwargs = {"symbol": "msft", "start_date": "2023-01-01", "provider": "polygon"}
historical_prices = obb.equity.price.historical(**kwargs)

Enter fullscreen mode Exit fullscreen mode
  1. Handling Warnings and Unsupported Parameters Each query will warn of invalid parameters, and any unsupported parameter will appear in the warnings field, letting you know how to adjust your request.
data = obb.equity.price.quote("brk-b", provider="fmp", source="bats")
print(data.warnings)  # Expects a warning message
Enter fullscreen mode Exit fullscreen mode

Now let's learn some basic responses. Official Docs here

OpenBB Command Output Structure and Custom OBBject Class
Every command output in OpenBB is an OBBject, a custom class containing the primary result and relevant metadata. Here’s an overview of the OBBject fields and how to work with them.

OBBject Fields

  • id: A unique UUID identifier for the request.
  • results: The main data returned from the command.
  • provider: The data provider used in the request.
  • warnings: A list of any warnings encountered.
  • chart: A chart object, if applicable, with visualization capabilities.
  • extra: Additional metadata about the request, including the request parameters.

Example Usage:

from openbb import obb

# Run a command to get historical price data
data = obb.equity.price.historical("SPY", provider="polygon")

# Print the OBBject for an overview
print(data)

Enter fullscreen mode Exit fullscreen mode

Sample Output:

OBBject

id: 06520558-d54a-7e53-8000-7aafc8a42694
results: [{'date': datetime.datetime(2022, 10, 5, 0, 0), 'open': 375.62, 'high': 37...
provider: polygon
warnings: None
chart: None
extra: {'metadata': {'arguments': {'provider_choices': {'provider': 'polygon'}, 'st...
Enter fullscreen mode Exit fullscreen mode

Converting OBBject Results to Various Formats

OBBject offers methods to easily convert results into different formats:

  • to_dict(): Converts to a dictionary. Supports various orientations (e.g., "records").
  • to_df() / to_dataframe(): Converts results to a Pandas DataFrame, ideal for data manipulation in Python.
  • to_numpy(): Exports results as a Numpy array.
  • to_polars(): Converts results to a Polars table, useful for performance with large datasets.

Example:

# Convert data to a DataFrame
df = data.to_dataframe()

# Convert data to a dictionary
data_dict = data.to_dict(orientation="records")

Enter fullscreen mode Exit fullscreen mode

Setting Preferred Output Type

You can configure OpenBB to return results in a preferred format by setting the output_type in user preferences. For instance, to always get results as a DataFrame:

obb.user.preferences.output_type = "dataframe"
Enter fullscreen mode Exit fullscreen mode

With these tools, you’ll streamline data handling in OpenBB, making it easy to integrate results directly into your data analysis workflows.


Please prefer official documentation once again here

Conclusion

OpenBB provides a powerful set of fundamental analysis tools that empower retail investors to assess stocks like Apple with professional-level insights. By examining income statements, key ratios, growth trends, and valuations, investors can develop a comprehensive understanding of a company's financial health and its potential for future returns.

Increase your productivity with OpenBB now!

Are you prepared to enhance your investment research? Download OpenBB today and embark on your journey towards making more informed financial decisions. With OpenBB at your fingertips, professional-grade stock analysis tools are merely a command away.

💖 💪 🙅 🚩
adityadeshlahre
Aditya Deshlahre

Posted on October 30, 2024

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related