

Discover more from Tinz Twins Hub
OpenBB SDK: Do your Investment Research with Python
A beginner-friendly guide with a practical example

Do you want to know how to use OpenBB SDK for your investment research? Then this article is for you. The OpenBB SDK is developed as open-source by the company OpenBB. It is the core engine of the OpenBB platform and provides the basis for other OpenBB services. If you want to learn more about OpenBB services, we recommend our overview article on OpenBB 3.0. This article gives an excellent overview of all OpenBB services in 5 minutes. It is a must-read for all financial analysts!
The OpenBB SDK gives you access to a large amount of financial data. And best of all, if you know OpenBB Terminal, it’s easy to start with the OpenBB SDK. The commands of the OpenBB Terminal exist 1-to-1 in the OpenBB SDK. The SDK allows you to access close to 100 different data sources from one endpoint. It offers access to fundamental company data, economic data, news, and much more. Awesome!
You can also integrate the SDK into any investment research workflow. The SDK is written in Python, which makes it attractive to many developers. If you are not familiar with Python, you can take a look at the course The Complete Python, Machine Learning, AI Mega Bundle*. In addition to data access, it also offers visualisation capabilities that allowing you to analyse and visualise data directly from a Jupyter Notebook or Python file. Now you have a rough overview of the SDK.
Now let’s dive into the SDK!
How can you set up the OpenBB SDK?
Technical requirements
You will need the following prerequisites:
Installed Python (≥ 3.8 and != 3.11)
Installed conda and pip
Access to a bash (macOS, Linux or Windows)
Code editor of your choice (We prefer VSCode.)
We tested it on macOS Ventura 13.4 on an Intel-based MacBook. But OpenBB also supports Apple Silicon Macs.
Setup
First, we create a Python virtual environment. We use conda to create the environment. The OpenBB SDK documentation recommends the following procedure:
$ conda env create -n obb --file https://raw.githubusercontent.com/OpenBB-finance/OpenBBTerminal/main/build/conda/conda-3-9-env.yaml
Agree to all prompts! Then you can activate the environment. Enter the following in a terminal of your choice:
$ conda activate obb
Now we can install OpenBB SDK. Enter the following into the terminal with the activated environment obb
:
(obb) $ pip install "openbb[all]" --no-cache-dir
This command installs all available toolkits of OpenBB at once. The --no-cache-dir
option tells pip not to save the downloaded packages locally. If you want to install OpenBB again, it will be downloaded again. You have installed OpenBB SDK successfully, if no error appears. Great! Now we can start with the basics.
🎓 Learn Excel and Machine Learning for stock prediction
In today’s competitive job market, mastering a range of technical skills is more important than ever. The 100-hour course “The Complete Excel, AI and Data Science Mega Bundle“* is designed to equip you with in-demand capabilities in Excel, Python, and Artificial Intelligence (AI).
It is a completely self-paced online learning course.
Here you’ll discover:
Excel functions, formulae, and data visualization techniques. Unlock the financial functionalities of Excel to manage and analyze business data.
Gain an edge in the market by leveraging machine learning for stock prediction.
Learn to build advanced models, understand neural networks, and employ TensorFlow.
Invest in Your Future! Enroll now and set yourself on a path to technological mastery and unparalleled career growth.
Learn the Basics
In the last section, we installed the SDK successfully. Now we want to use the SDK for investment research. First, we must import the OpenBB SDK in our Python file or Jupyter Notebook.
from openbb_terminal.sdk import openbb
The OpenBB SDK has a very intuitive syntax. If you want to load the data for a stock, you can use the following command:
If you enter a dot (.) after openbb, the available submenus are displayed. For example, we load the data for the Tesla stock.
data = openbb.stocks.load(
symbol = 'TSLA',
start_date = '2023-01-01',
end_date = '2023-06-01',
monthly = False)
data
The code downloads the data between 2023–01–01 and 2023–06–01 on a daily basis. The downloaded data contains the following information:
You get a Pandas data frame as a return. The data frame contains the following columns:
Open: Daily opening price in dollar
High: Highest price of the day in dollar
Low: Lowest price of the day in dollar
Close: Daily closing price in dollar
Adj Close: Adjusted closing price in relation to dividends or stock splits
Volume: Number of shares traded
Dividends: Dividend paid
Stock Splits: Stock splits performed
We now know how the data looks. Next, we want to create a candlestick chart. We don’t need an external library for the plot because the OpenBB SDK already contains a corresponding functionality. Look at the following example:
openbb.stocks.candle(
data = data,
asset_type = 'Candlestick: Tesla - Daily',
symbol = 'TSLA'
)
The plot shows an interactive candlestick chart over the selected period. You can analyse the share by zooming in and looking at certain parts. The OpenBB SDK offers a module for technical analysis. Take a look at it. Now we know the SDK basics. It’s time to move on to the practical example.
Practical Example — Comparison of two ETF
In this section, we use the OpenBB SDK to compare the iShares MSCI World ETF and the Vanguard FTSE All-World ETF. Let’s start!
The first thing we do is pick out the ETF’s symbol. For this, you can use the function openbb.etf.etf_by_name()
.
openbb.etf.etf_by_name("MSCI World ETF")
openbb.etf.etf_by_name("Vanguard FTSE All-World")
Outputs:
Now we have the symbols for the two ETFs. We can use the ETF symbols to show the top 7 positions in the ETF.
holdings = openbb.etf.holdings("URTH")
holdings.head(7)
Output:
The biggest positions in the MSCI World ETF are technology stocks (Apple, Microsoft, Amazon, Nvidia, Alphabet (Ex-Google), Tesla). Apple and Microsoft are by far the biggest positions. Now let’s look at the top 7 positions in the FTSE All World.
holdings = openbb.etf.holdings("VEU")
holdings.head(7)
Output:
The biggest positions in the FTSE All-World ETF are not only technology stocks. The Nestle stock is the biggest position in the ETF. In addition, the biggest position is proportionally smaller than in the MSCI World ETF. Big Tech stocks are not in the top 7 holdings.
Next, we compare the two ETFs with the SDK function openbb.etf.compare()
:
compare_etfs = openbb.etf.compare(["URTH", "VEU"])
compare_etfs
Output:
The comparison shows that the FTSE All-World ETF has a lower expense ratio. That means that the fees are lower than for the MSCI World ETF. We can also see that the FTSE All-World ETF has a larger volume. Another important point is that the FTSE All-World contains more than twice as many shares. It is up to you to decide which stocks, ETFs, etc. you buy, but OpenBB offers a programmatic way to do your own research.
Conclusion
In this article we have introduced the basic functions of the OpenBB SDK. You now know how to install and use the OpenBB SDK. We also went through a practical example comparing two ETFs. Overall, the OpenBB SDK is easy to use, and the documentation is well-structured. It offers an easy way to do investment research programmatically in Python.
👉🏽 Join our free weekly Magic AI newsletter for the latest AI updates!
👉🏽 You can find all our Freebies on our digital products page!
Did you like our article and want to support us as writers? You can do it through buy me a coffee or become a member of Tinz Twins Hub. Don’t forget to follow us on X. Thanks for your support. 🙏🏽🙏🏽
Learn more about us on our About page. Thanks so much for reading. Have a great day!
* Disclosure: The links are affiliate links, which means we will receive a commission if you purchase through these links. There are no additional costs for you.