Skip to main content

equities aims to democratize access to publically avaliable financial data.

Project description

🦈 Equities

Overview:

equities is a python library that allows easy access to the SEC's XLBR dataset.
Parsed data is stored locally for ease of use. Data is returned in pandas
dataframes. 

TUTORIAL:

The library consists of two central objects, Universe and Company.

Universe:

A Universe should be thought of as a set of Companies. The universe object gives us the ability to download, access and purge our data.

from equities.objects import Universe

universe = Universe()

Downloading Data:

On first use the universe is empty as we have not downloaded data. Before calling the download function we can optionally supply the universe with an array of quarters and or an array of "CIK" (explained below) ints.

quarters = ["2019q1","2019q2","2019q3","2019q4","2020q1"] # quarters to be downloaded
ciks = 50 # limits parsing to first 50 companies. 

If no optional arguments are supplied, we will proceed to download the entire dataset and parse all companies.

To download data we call

universe.download(quarters=quarters,ciks=ciks)

The requested data will then be downloaded and saved locally. This means that anytime you reinstantiate the universe object, python remembers what you have already parsed.

Core Functionality:

To see the number of companies in the universe we can do:

print(len(universe))

Universe objects are indexable by a "CIK" or "Central Index Key" number. This is the unique identifier used by the sec to identify companies. To get a full list of the cik numbers in the universe one can do:

print(universe.ciks)

A dataframe summary of all companies in the universe is included in:

print(universe.properties())

To access the first company in the above list you can do:

first_cik = universe.ciks[0]
print(universe[first_cik])

This returns a Company Object.

Company:

A Company object should be thought of as an abstract representation of a real company. Every company must have an associated Universe of origin.

from equities.object import Company

Accessing the Financial Statements

Consider the first Company in our universe, universe[first_cik]. It is a Company object.

company = universe[first_cik]

Dataframes of the company's financial statements over the universe in question is given by:

company.income()      # income statement dataframe

company.balance()     # Balancesheet dataframe

company.cash()        # Cash Flow Statement dataframe

company.equity()      # Consolidatad Equity dataframe

Additional Company Methods

company.name()        # Returns company name
company.sic()         # Returns company sic group

Example

This is a start to finish example of how one might plot the first quarter income statements of the following companies in the universe from 2015-2020.

Company CIKS:

1556593
1499200
1220754
917520
1040593
24741

Code:

# Import modules
import matlotlib.pyplot as plt
from equities.objects import Universe, Company

# Instantiate universe
u = Universe()

# Download data
quarters = ["2017q1","2018q","2019q1","2020q1"]
ciks = [1556593,1499200,1220754,917520,1040593,24741]
u.download(quarters=quarters,ciks=ciks)

# Plot Income Statements
for cik in ciks:
    income_df = u[cik].income()
    income_df.plot(kind="bar",
                   stacked=True,
                   fig_size=(20,10))
plt.show()

Project details


Release history Release notifications | RSS feed

This version

1.3.5

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

equities-1.3.5.tar.gz (377.0 kB view hashes)

Uploaded Source

Built Distribution

equities-1.3.5-py3-none-any.whl (392.7 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page