In this notebook, we'll take a look at EventVestor's Impairments and Charges dataset, available on the Quantopian Store. This dataset spans January 01, 2007 through the current day, and documents goodwill impairments and other one time charges reported by companies.
Before we dig into the data, we want to tell you about how you generally access Quantopian Store data sets. These datasets are available through an API service known as Blaze. Blaze provides the Quantopian user with a convenient interface to access very large datasets.
Blaze provides an important function for accessing these datasets. Some of these sets are many millions of records. Bringing that data directly into Quantopian Research directly just is not viable. So Blaze allows us to provide a simple querying interface and shift the burden over to the server side.
It is common to use Blaze to reduce your dataset in size, convert it over to Pandas and then to use Pandas for further computation, manipulation and visualization.
Helpful links:
Once you've limited the size of your Blaze object, you can convert it to a Pandas DataFrames using:
from odo import odo
odo(expr, pandas.DataFrame)
One other key caveat: we limit the number of results returned from any given expression to 10,000 to protect against runaway memory usage. To be clear, you have access to all the data server side. We are limiting the size of the responses back from Blaze.
There is a free version of this dataset as well as a paid one. The free one includes about three years of historical data, though not up to the current day.
With preamble in place, let's get started:
In [1]:
# import the dataset
from quantopian.interactive.data.eventvestor import impairments_and_charges
# or if you want to import the free dataset, use:
# from quantopian.interactive.data.eventvestor import impairments_and_charges_free
# import data operations
from odo import odo
# import other libraries we will use
import pandas as pd
In [2]:
# Let's use blaze to understand the data a bit using Blaze dshape()
impairments_and_charges.dshape
Out[2]:
In [3]:
# And how many rows are there?
# N.B. we're using a Blaze function to do this, not len()
impairments_and_charges.count()
Out[3]:
In [4]:
# Let's see what the data looks like. We'll grab the first three rows.
impairments_and_charges[:3]
Out[4]:
Let's go over the columns:
amount_units
We've done much of the data processing for you. Fields like timestamp
and sid
are standardized across all our Store Datasets, so the datasets are easy to combine. We have standardized the sid
across all our equity databases.
We can select columns and rows with ease. Below, we'll fetch all 2012 charges greater than $200M.
In [5]:
twohundreds = impairments_and_charges[('2011-12-31' < impairments_and_charges['asof_date']) &
(impairments_and_charges['asof_date'] <'2013-01-01') &
(impairments_and_charges.charge_amount > 200)&
(impairments_and_charges.amount_units == "$M")]
# When displaying a Blaze Data Object, the printout is automatically truncated to ten rows.
twohundreds.sort('asof_date')
Out[5]:
Now suppose we want a DataFrame of the Blaze Data Object above, and we only want the sid, charge_amount and the asof_date.
In [6]:
df = odo(twohundreds, pd.DataFrame)
df = df[['sid', 'asof_date','charge_amount']].dropna()
# When printing a pandas DataFrame, the head 30 and tail 30 rows are displayed. The middle is truncated.
df
Out[6]: