- Advertisement -Newspaper WordPress Theme
Algorithm tradingFinanceDatabase Guide - A Comprehensive Database of Financial Symbols (Python Package) -...

FinanceDatabase Guide – A Comprehensive Database of Financial Symbols (Python Package) – AlgoTrading101 Blog


FinanceDatabase is a Python package of 300.000+ symbols containing Equities, ETFs, Funds, Indices, Currencies, Cryptocurrencies, and Money Markets.

FinanceDatabase is mainly used for any type of financial product categorization. Moreover, it gives insights into the products that exist in each country, industry, and sector and gives the most essential information about each product.

This allows algorithmic traders and investors to analyze specific financial segments and helps them find assets that are hard to uncover. For example, it is used within the OpenBB terminal.

How to get general data with FinanceDatabase?

To get general data with FinanceDatabase, you will need to initialize the part of the database you want to use (e.g. equities) and use the filtering methods such as options, select and search.

For example, let’s initialize the equities database and obtain all industries from a specific country:

equities = fd.Equities()

equities_germany_industries = equities.options('industry', country='Singapore')
equities_germany_industries
array(['Aerospace & Defense', 'Air Freight & Logistics', 'Airlines',
       'Auto Components', 'Automobiles', 'Banks', 'Beverages', ...

We obtain all of the 55 industries in Singapore, feel free to experiment with other countries.

Now, let’s obtain all equities from a specific country such as the USA:

equities_united_states = equities.select(country="United States")
equities_united_states.head()

How to perform an advanced search on the FinanceDatabase?

To perform an advanced search on the Finance Databse, you can use the search method and pass multiple parameters to limit your search to a specific market segment.

For example, let’s obtain all Swedish software companies that have the word “cloud” in their summary and are part of the FRA exchange:

equities_sweden_software = equities.search(
    country='Sweden',
    industry='Software',
    summary="cloud",
    exchange="FRA"
)
equities_sweden_software

Feel free to try out other industries, sectors, and parameters to filter on.

How to obtain all US companies from different sectors using the FinanceDatabase?

To obtain all US companies from different sectors using the FinanceDatabase, you can utilize the options and select features to loop over all the sectors and aggregate the companies per each of them.

equities_sectors_us = {}

for sector in equities.options(selection='sector', country='United States'):
    try:
        equities_sectors_us[sector] = len(equities.select(country='United States', sector=sector))
    except ValueError as error:
        print(error)
{'Communication Services': 444,
 'Consumer Discretionary': 739,
 'Consumer Staples': 402,
 'Energy': 470,
 'Financials': 3919,
 'Health Care': 1559,
 'Industrials': 1044,
 'Information Technology': 1043,
 'Materials': 424,
 'Real Estate': 513,
 'Utilities': 190}

How to perform technical analysis with FinanceDatabase?

To perform technical analysis with FinanceDatabase, you will need to extend its features with other libraries such as yfinance, ta, talib, and similar. For example, let’s examine the french wine industry’s large caps in a post-covid market setting.

The first thing that we want to do is to install the libraries that are missing:

!pip install ta
!pip install yfinance

Now, we import everything that we’ll be using:

import pandas as pd
import yfinance as yf
from ta.volatility import BollingerBands
import matplotlib.pyplot as plt
%matplotlib inline

The next step that we want to do is to obtain all the french beverage industry equities that have “wine” inside their summary and that are large caps. We will obtain the data from Match 2020 up to the beginning of 2023:

french_wine_equities = equities.search(
    country="France",
    industry="Beverages",
    summary="wine",
    market_cap="Large Cap"
)
french_wine_equities

From the output, we can observe that Pernod Ricard SA is the main and only leader here. Now, let’s obtain the data on these tickers with yfinance to examine them further:

tickers = list(french_wine_equities.index)

stock_fr_wine = yf.download(tickers, start="2020-03-01", end="2023-01-01")['Adj Close']
stock_fr_wine.drop(["PER1.F", "PDRDY"], axis=1, inplace=True)
stock_fr_wine.head()

As yfinance didn’t have the two tickers above, I removed them. Now, we will fill in the missing data and calculate the difference between the daily returns as I’d like to examine the difference in volatility, if any, between these tickers:

stock_fr_wine.fillna(method = 'ffill', inplace = True)
stock_fr_wine = stock_fr_wine.diff()

Now, I’ll add a Bollinger Bands indicator to help us gauge the volatility between the returns and only plot the upper and lower band. I’ll also add a straight line on the 0 y-axes.

fig, axis = plt.subplots(3, 2)
row = 0
column = 0

for ticker in stock_fr_wine.columns:
    data_plot = pd.DataFrame(stock_fr_wine[ticker])

    indicator_bb = BollingerBands(close=stock_fr_wine[ticker], window=20, window_dev=2)

    data_plot['bb_bbh'] = indicator_bb.bollinger_hband()
    data_plot['bb_bbl'] = indicator_bb.bollinger_lband()

    axis[row, column].plot(data_plot)
    axis[row, column].set_title(ticker, fontsize=16)
    axis[row, column].axhline(0, c="purple")

    column += 1
    if column == 2:
        row += 1
        column = 0
        
fig.suptitle('Technical Analysis of Pernod Ricard SA')
fig.set_size_inches(18.5, 10.5)
fig.tight_layout()

As you can see, there are differences in volatility between these assets and their respective exchanges. Knowing this, a trading strategy pattern or investment plan might start to sprout. Feel free to extend this simple analysis and try out other assets.

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