In this notebook, we'll take a look at EventVestor's Mergers and Acquisitions dataset, available on the Quantopian Store. This dataset spans January 01, 2007 through the current day.
There are two ways to access the data and you'll find both of them listed below. Just click on the section you'd like to read through.
One 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 sample includes data until 2 months prior to the current date.
To access the most up-to-date values for this data set for trading a live algorithm (as with other partner sets), you need to purchase acess to the full set.
With preamble in place, let's get started:
Partner datasets are available on Quantopian Research through an API service known as Blaze. Blaze provides the Quantopian user with a convenient interface to access very large datasets, in an interactive, generic manner.
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)
Pipeline Overview section of this notebook or head straight to Pipeline Overview
In [1]:
# import the dataset
from quantopian.interactive.data.eventvestor import mergers_and_acquisitions_free as dataset
# or if you want to import the free dataset, use:
#from quantopian.data.eventvestor import buyback_auth_free
# import data operations
from odo import odo
# import other libraries we will use
import pandas as pd
import matplotlib.pyplot as plt
In [2]:
# Let's use blaze to understand the data a bit using Blaze dshape()
dataset.dshape
Out[2]:
In [3]:
# And how many rows are there?
# N.B. we're using a Blaze function to do this, not len()
dataset.count()
Out[3]:
In [4]:
dataset.asof_date.min()
Out[4]:
In [5]:
# Let's see what the data looks like. We'll grab the first three rows.
dataset[:3]
Out[5]:
In [6]:
dataset.is_crossboarder.distinct()
Out[6]:
Let's go over the columns:
Announcement, Close, Proposal, Termination, Rumor, Rejection, NoneTarget or AcquirerMixed Offer, Cash Offer, Other, Stock Offer, NonePublic, Private, PE Holding, VC Funded, NoneNone, National, Other, Cross BorderWe'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 entries for Microsoft. We're really only interested in the buyback amount, the units, and the date, so we'll display only those columns.
In [7]:
# get the sid for MSFT
symbols('MSFT')
Out[7]:
In [8]:
# knowing that the MSFT sid is 5061:
msft = dataset[dataset.sid==5061]
msft[:5]
Out[8]:
The only method for accessing partner data within algorithms running on Quantopian is via the pipeline API.
There are a few factors available using the M&A dataset through Pipeline. They allow you to identify securities that are the current target of an acquisition. You can also view the payment mode used in the offer as well as the number of business days since the offer was made.
In [9]:
# Import necessary Pipeline modules
from quantopian.pipeline import Pipeline
from quantopian.research import run_pipeline
from quantopian.pipeline.factors import AverageDollarVolume
In [11]:
from quantopian.pipeline.classifiers.eventvestor import (
AnnouncedAcqTargetType,
ProposedAcqTargetType,
)
from quantopian.pipeline.factors.eventvestor import (
BusinessDaysSinceAnnouncedAcquisition,
BusinessDaysSinceProposedAcquisition
)
from quantopian.pipeline.filters.eventvestor import (
IsAnnouncedAcqTarget
)
from quantopian.pipeline import Pipeline
from quantopian.research import run_pipeline
def screen_ma_targets_by_type(target_type='cash'):
"""
target_type:
(string) Available options are 'cash', 'stock', 'mixed', 'all'.
This will filter all offers of type target_type.
"""
if target_type == 'all':
return (~IsAnnouncedAcqTarget())
else:
if target_type == 'cash':
filter_offer = 'Cash Offer'
elif target_type == 'stock':
filter_offer = 'Stock Offer'
elif target_type == 'mixed':
filter_offer = 'Mixed Offer'
return (~AnnouncedAcqTargetType().eq(filter_offer))
def screen_ma_targets_by_days(days=200):
"""
days:
(int) Filters out securities that have had an announcement
less than X days. So if days is 200, all securities
that have had an announcement less than 200 days ago will be
filtered out.
"""
b_days = BusinessDaysSinceAnnouncedAcquisition()
return ((b_days > days) | b_days.isnull())
pipe = Pipeline(
columns={
'AnnouncedAcqTargetType': AnnouncedAcqTargetType(),
'BusinessDays': BusinessDaysSinceAnnouncedAcquisition()
},
screen=(screen_ma_targets_by_days(60) &
screen_ma_targets_by_type(target_type='stock'))
)
output = run_pipeline(pipe, start_date='2016-07-28', end_date='2016-07-28')
In [12]:
"""
Similar functions for M&A Proposals (different from Announcements)
"""
def screen_ma_proposal_targets_by_type(target_type='cash'):
"""
target_type:
(string) Available options are 'cash', 'stock', 'mixed', 'all'.
This will filter all offers of type target_type.
"""
if target_type == 'all':
return (ProposedAcqTargetType().isnull() &
BusinessDaysSinceProposedAcquisition().isnull())
if target_type == 'cash':
filter_offer = 'Cash Offer'
elif target_type == 'stock':
filter_offer = 'Stock Offer'
elif target_type == 'mixed':
filter_offer = 'Mixed Offer'
return (~ProposedAcqTargetType().eq(filter_offer))
def screen_ma_proposal_targets_by_days(days=200):
"""
days:
(int) Filters out securities that have had an announcement
less than X days. So if days is 200, all securities
that have had an announcement less than 200 days ago will be
filtered out.
"""
b_days = BusinessDaysSinceProposedAcquisition()
return ((b_days > days) | b_days.isnull())