Notebook

EventVestor: Dividend Announcements

In this notebook, we'll take a look at EventVestor's Cash Dividend Announcement dataset, available on the Quantopian Store. This dataset spans January 01, 2007 through the current day, and documents cash dividend announcements, including special dividends.

Notebook Contents

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.

  • Interactive overview: This is only available on Research and uses blaze to give you access to large amounts of data. Recommended for exploration and plotting.
  • Pipeline overview: Data is made available through pipeline which is available on both the Research & Backtesting environment. Recommended for custom factor development and moving back & forth between research/backtesting.

Free samples and limits

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:

</a>

Interactive Overview

Accessing the data with Blaze and Interactive on Research

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)

To see how this data can be used in your algorithm, search for the Pipeline Overview section of this notebook or head straight to Pipeline Overview

In [1]:
# import the dataset
# from quantopian.interactive.data.eventvestor import dividends as dataset
# or if you want to import the free dataset, use:
from quantopian.interactive.data.eventvestor import dividends_free  as dataset

# 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()
dataset.dshape
Out[2]:
dshape("""var * {
  event_id: float64,
  trade_date: ?datetime,
  symbol: string,
  event_type: ?string,
  event_headline: ?string,
  event_phase: ?string,
  div_type: ?string,
  div_amount: float64,
  div_currency: ?string,
  div_ex_date: ?datetime,
  div_record_date: ?datetime,
  div_pay_date: ?datetime,
  event_rating: float64,
  sid: int64,
  asof_date: datetime,
  timestamp: datetime
  }""")
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]:
48578
In [4]:
# Let's see what the data looks like. We'll grab the first three rows.
dataset[:3]
Out[4]:
event_id asof_date trade_date symbol event_type event_headline event_phase div_type div_amount div_currency div_ex_date div_record_date div_pay_date event_rating timestamp sid
0 151608 2007-01-02 2007-01-03 RPM Dividend RPM International Hikes Quarterly Dividend 9% NaN Increase 0.175 $ 2007-01-10 2007-01-12 2007-01-31 1 2007-01-03 6557
1 1071875 2007-01-02 2007-01-02 SUI Dividend Sun Communities Declares Quarterly Dividend of... NaN No Change QoQ 0.630 $ 2007-01-10 2007-01-12 2007-01-22 1 2007-01-03 10535
2 149674 2007-01-02 2007-01-03 AFG Dividend American Financial Increases Quarterly Dividen... NaN Increase 0.100 $ 2007-01-11 2007-01-15 2007-01-25 1 2007-01-03 12980

Let's go over the columns:

  • event_id: the unique identifier for this event.
  • asof_date: EventVestor's timestamp of event capture.
  • trade_date: for event announcements made before trading ends, trade_date is the same as event_date. For announcements issued after market close, trade_date is next market open day.
  • symbol: stock ticker symbol of the affected company.
  • event_type: this should always be Dividend.
  • event_headline: a brief description of the event
  • event_phase: the inclusion of this field is likely an error on the part of the data vendor. We're currently attempting to resolve this.
  • div_type: dividend type. Values include no change, increase, decrease, initiation, defer, suspend, omission, stock, special.
    Note QoQ = quarter-on-quarter.
  • div_amount: dividend payment amount in local currency
  • div_currency: dividend payment currency code. Values include $, BRL, CAD, CHF, EUR, GBP, JPY.
  • div_ex_date: ex-dividend date
  • div_record_date: dividend payment record date
  • div_pay_date: dividend payment date
  • event_rating: this is always 1. The meaning of this is uncertain.
  • timestamp: this is our timestamp on when we registered the data.
  • sid: the equity's unique identifier. Use this instead of the symbol.

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 fifty-cent dividends.

In [7]:
fiftyc = dataset[(dataset.div_amount==0.5) & (dataset['div_currency']=='$')]
# When displaying a Blaze Data Object, the printout is automatically truncated to ten rows.
fiftyc.sort('timestamp')
Out[7]:
event_id asof_date trade_date symbol event_type event_headline event_phase div_type div_amount div_currency div_ex_date div_record_date div_pay_date event_rating timestamp sid
0 132448 2007-01-18 2007-01-18 PPG Dividend PPG Industries Raises Quarterly Dividend 4.2% NaN Increase 0.5 $ 2007-02-14 2007-02-16 2007-03-12 1 2007-01-19 6116
1 145007 2007-01-23 2007-01-23 CFFN Dividend Capitol Federal Declares Quarterly Dividend of... NaN No Change QoQ 0.5 $ 2007-01-31 2007-02-02 2007-02-16 1 2007-01-24 19962
2 144819 2007-01-25 2007-01-25 IMB Dividend IndyMac Declares Quarterly Dividend of $0.50 p... NaN No Change QoQ 0.5 $ 2007-02-06 2007-02-08 2007-03-08 1 2007-01-26 17256
3 132424 2007-02-21 2007-02-21 NUE Dividend Nucor Declares Supplemental Dividend of $0.50 ... NaN Special 0.5 $ 2007-03-28 2007-03-30 2007-05-11 1 2007-02-22 5488
4 131771 2007-02-22 2007-02-22 HIG Dividend Hartford Declares Quarterly Dividend of $0.50 ... NaN No Change QoQ 0.5 $ 2007-02-27 2007-03-01 2007-04-02 1 2007-02-23 14064
5 132961 2007-02-27 2007-02-27 PSA Dividend Public Storage Declares Dividend of $0.50 per ... NaN No Change QoQ 0.5 $ 2007-03-13 2007-03-15 2007-03-29 1 2007-02-28 24962
6 524735 2007-03-01 2007-03-01 GLNG Dividend Golar LNG Declares Quarterly Dividend of $0.50... NaN No Change QoQ 0.5 $ 2007-03-08 2007-03-12 2007-03-26 1 2007-03-02 24489
7 130886 2007-03-02 2007-03-02 FRE Dividend Freddie Mac Declares Quarterly Dividend of $0.... NaN No Change QoQ 0.5 $ 2007-03-08 2007-03-12 2007-03-30 1 2007-03-03 2988
8 1066749 2007-03-05 2007-03-05 EGP Dividend EastGroup Properties Increases Dividend by 2% NaN Increase 0.5 $ 2007-03-16 2007-03-20 2007-03-30 1 2007-03-06 2471
9 1070046 2007-03-09 2007-03-09 NHI Dividend National Health Hikes Quarterly Dividend by 4.2% NaN Increase 0.5 $ 2007-03-28 2007-03-30 2007-05-10 1 2007-03-10 5303
10 150309 2007-03-14 2007-03-14 AYR Dividend Aircastle Raises Quarterly Dividend to $0.50 p... NaN Increase 0.5 $ 2007-03-28 2007-03-30 2007-04-13 1 2007-03-15 32475

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 fifty-cent dividends.

In [8]:
fifty_df = odo(fiftyc, pd.DataFrame)
reduced = fifty_df[['sid','div_type','timestamp']]
# When printed: pandas DataFrames display the head(30) and tail(30) rows, and truncate the middle.
reduced
Out[8]:
sid div_type timestamp
0 6116 Increase 2007-01-19 00:00:00
1 19962 No Change QoQ 2007-01-24 00:00:00
2 17256 No Change QoQ 2007-01-26 00:00:00
3 5488 Special 2007-02-22 00:00:00
4 14064 No Change QoQ 2007-02-23 00:00:00
5 24962 No Change QoQ 2007-02-28 00:00:00
6 24489 No Change QoQ 2007-03-02 00:00:00
7 2988 No Change QoQ 2007-03-03 00:00:00
8 2471 Increase 2007-03-06 00:00:00
9 5303 Increase 2007-03-10 00:00:00
10 32475 Increase 2007-03-15 00:00:00
11 17850 No Change QoQ 2007-03-23 00:00:00
12 27370 Decrease 2007-04-19 00:00:00
13 6116 No Change QoQ 2007-04-20 00:00:00
14 19962 No Change QoQ 2007-04-26 00:00:00
15 17256 No Change QoQ 2007-04-27 00:00:00
16 27577 Increase 2007-04-27 00:00:00
17 22792 Decrease 2007-05-02 00:00:00
18 24962 No Change QoQ 2007-05-04 00:00:00
19 5219 Increase 2007-05-10 00:00:00
20 14064 No Change QoQ 2007-05-18 00:00:00
21 24489 No Change QoQ 2007-05-25 00:00:00
22 2471 No Change QoQ 2007-05-31 00:00:00
23 5488 Special 2007-06-06 00:00:00
24 2988 No Change QoQ 2007-06-09 00:00:00
25 5303 No Change QoQ 2007-06-12 00:00:00
26 27830 Increase 2007-06-13 00:00:00
27 17850 No Change QoQ 2007-07-18 00:00:00
28 14064 No Change QoQ 2007-07-20 00:00:00
29 11044 Increase 2007-07-24 00:00:00
... ... ... ...
499 7242 No Change QoQ 2014-02-19 00:00:00
500 3620 Special 2014-02-20 00:00:00
501 33317 Special 2014-02-21 00:00:00
502 27819 Special 2014-02-27 00:00:00
503 1274 Increase 2014-02-28 00:00:00
504 11472 No Change QoQ 2014-03-01 00:00:00
505 7657 Special 2014-03-07 00:00:00
506 32367 No Change QoQ 2014-03-07 00:00:00
507 9540 Decrease 2014-03-14 00:00:00
508 17448 No Change QoQ 2014-03-14 00:00:00
509 36111 No Change QoQ 2014-03-19 00:00:00
510 38531 No Change QoQ 2014-03-19 00:00:00
511 45578 Increase 2014-03-19 00:00:00
512 13508 No Change QoQ 2014-04-15 00:00:00
513 7242 No Change QoQ 2014-04-16 00:00:00
514 45397 No Change QoQ 2014-04-18 00:00:00
515 3714 No Change QoQ 2014-04-19 00:00:00
516 5621 Increase 2014-04-19 00:00:00
517 43982 Increase 2014-04-22 00:00:00
518 161 No Change QoQ 2014-04-23 00:00:00
519 43450 Increase 2014-04-25 00:00:00
520 6190 No Change QoQ 2014-04-29 00:00:00
521 26882 No Change QoQ 2014-05-01 00:00:00
522 23906 No Change QoQ 2014-05-07 00:00:00
523 42788 Increase 2014-05-08 00:00:00
524 3620 Special 2014-05-15 00:00:00
525 5651 Increase 2014-05-22 00:00:00
526 553 No Change QoQ 2014-05-23 00:00:00
527 11472 No Change QoQ 2014-05-23 00:00:00
528 8580 Increase 2016-02-17 23:30:42.139389

529 rows × 3 columns

Finally, suppose we want a DataFrame of that data, but we only want the sid, timestamp, and div_type:

In [9]:
fifty_df = odo(fiftyc, pd.DataFrame)
reduced = fifty_df[['sid','div_type','timestamp']]
# When printed: pandas DataFrames display the head(30) and tail(30) rows, and truncate the middle.
reduced
Out[9]:
sid div_type timestamp
0 6116 Increase 2007-01-19 00:00:00
1 19962 No Change QoQ 2007-01-24 00:00:00
2 17256 No Change QoQ 2007-01-26 00:00:00
3 5488 Special 2007-02-22 00:00:00
4 14064 No Change QoQ 2007-02-23 00:00:00
5 24962 No Change QoQ 2007-02-28 00:00:00
6 24489 No Change QoQ 2007-03-02 00:00:00
7 2988 No Change QoQ 2007-03-03 00:00:00
8 2471 Increase 2007-03-06 00:00:00
9 5303 Increase 2007-03-10 00:00:00
10 32475 Increase 2007-03-15 00:00:00
11 17850 No Change QoQ 2007-03-23 00:00:00
12 27370 Decrease 2007-04-19 00:00:00
13 6116 No Change QoQ 2007-04-20 00:00:00
14 19962 No Change QoQ 2007-04-26 00:00:00
15 17256 No Change QoQ 2007-04-27 00:00:00
16 27577 Increase 2007-04-27 00:00:00
17 22792 Decrease 2007-05-02 00:00:00
18 24962 No Change QoQ 2007-05-04 00:00:00
19 5219 Increase 2007-05-10 00:00:00
20 14064 No Change QoQ 2007-05-18 00:00:00
21 24489 No Change QoQ 2007-05-25 00:00:00
22 2471 No Change QoQ 2007-05-31 00:00:00
23 5488 Special 2007-06-06 00:00:00
24 2988 No Change QoQ 2007-06-09 00:00:00
25 5303 No Change QoQ 2007-06-12 00:00:00
26 27830 Increase 2007-06-13 00:00:00
27 17850 No Change QoQ 2007-07-18 00:00:00
28 14064 No Change QoQ 2007-07-20 00:00:00
29 11044 Increase 2007-07-24 00:00:00
... ... ... ...
499 7242 No Change QoQ 2014-02-19 00:00:00
500 3620 Special 2014-02-20 00:00:00
501 33317 Special 2014-02-21 00:00:00
502 27819 Special 2014-02-27 00:00:00
503 1274 Increase 2014-02-28 00:00:00
504 11472 No Change QoQ 2014-03-01 00:00:00
505 7657 Special 2014-03-07 00:00:00
506 32367 No Change QoQ 2014-03-07 00:00:00
507 9540 Decrease 2014-03-14 00:00:00
508 17448 No Change QoQ 2014-03-14 00:00:00
509 36111 No Change QoQ 2014-03-19 00:00:00
510 38531 No Change QoQ 2014-03-19 00:00:00
511 45578 Increase 2014-03-19 00:00:00
512 13508 No Change QoQ 2014-04-15 00:00:00
513 7242 No Change QoQ 2014-04-16 00:00:00
514 45397 No Change QoQ 2014-04-18 00:00:00
515 3714 No Change QoQ 2014-04-19 00:00:00
516 5621 Increase 2014-04-19 00:00:00
517 43982 Increase 2014-04-22 00:00:00
518 161 No Change QoQ 2014-04-23 00:00:00
519 43450 Increase 2014-04-25 00:00:00
520 6190 No Change QoQ 2014-04-29 00:00:00
521 26882 No Change QoQ 2014-05-01 00:00:00
522 23906 No Change QoQ 2014-05-07 00:00:00
523 42788 Increase 2014-05-08 00:00:00
524 3620 Special 2014-05-15 00:00:00
525 5651 Increase 2014-05-22 00:00:00
526 553 No Change QoQ 2014-05-23 00:00:00
527 11472 No Change QoQ 2014-05-23 00:00:00
528 8580 Increase 2016-02-17 23:30:42.139389

529 rows × 3 columns

</a>

Pipeline Overview

Accessing the data in your algorithms & research

The only method for accessing partner data within algorithms running on Quantopian is via the pipeline API. Different data sets work differently but in the case of this data, you can add this data to your pipeline as follows:

Import the data set here > from quantopian.pipeline.data.eventvestor import ( > DividendsByExDate, > DividendsByPayDate, > DividendsByAnnouncement > )

Then in intialize() you could do something simple like adding the raw value of one of the fields to your pipeline: > pipe.add(DividendsByExDate.next_date.latest, 'next_dividends')

In [1]:
# Import necessary Pipeline modules
from quantopian.pipeline import Pipeline
from quantopian.research import run_pipeline
from quantopian.pipeline.factors import AverageDollarVolume
In [1]:
# Import the datasets available
from quantopian.pipeline.data.eventvestor import (
    DividendsByExDate,
    DividendsByPayDate,
    DividendsByAnnouncementDate,
)
from quantopian.pipeline.factors.eventvestor import (
    BusinessDaysSincePreviousExDate,
    BusinessDaysUntilNextExDate,
    BusinessDaysSinceDividendAnnouncement,
)

Now that we've imported the data, let's take a look at which fields are available for each dataset.

You'll find the dataset, the available fields, and the datatypes for each of those fields.

In [29]:
print "Here are the list of available fields per dataset:"
print "---------------------------------------------------\n"

def _print_fields(dataset):
    print "Dataset: %s\n" % dataset.__name__
    print "Fields:"
    for field in list(dataset.columns):
        print "%s - %s" % (field.name, field.dtype)
    print "\n"

for data in (DividendsByExDate, DividendsByPayDate, DividendsByAnnouncementDate):
    _print_fields(data)


print "---------------------------------------------------\n"
Here are the list of available fields per dataset:
---------------------------------------------------

Dataset: DividendsByExDate

Fields:
previous_date - datetime64[ns]
next_currency - object
previous_type - object
next_date - datetime64[ns]
previous_currency - object
next_amount - float64
previous_amount - float64
next_type - object


Dataset: DividendsByPayDate

Fields:
previous_amount - float64
previous_type - object
next_currency - object
previous_date - datetime64[ns]
next_date - datetime64[ns]
next_amount - float64
previous_currency - object
next_type - object


Dataset: DividendsByAnnouncementDate

Fields:
previous_amount - float64
previous_currency - object
previous_type - object
previous_announcement_date - datetime64[ns]


---------------------------------------------------

Now that we know what fields we have access to, let's see what this data looks like when we run it through Pipeline.

This is constructed the same way as you would in the backtester. For more information on using Pipeline in Research view this thread: https://www.quantopian.com/posts/pipeline-in-research-build-test-and-visualize-your-factors-and-filters

In [37]:
# Let's see what this data looks like when we run it through Pipeline
# This is constructed the same way as you would in the backtester. For more information
# on using Pipeline in Research view this thread:
# https://www.quantopian.com/posts/pipeline-in-research-build-test-and-visualize-your-factors-and-filters
pipe = Pipeline()
       
pipe.add(DividendsByExDate.next_date.latest, 'next_ex_date')
pipe.add(DividendsByExDate.previous_date.latest, 'prev_ex_date')
pipe.add(DividendsByExDate.next_amount.latest, 'next_amount')
pipe.add(DividendsByExDate.previous_amount.latest, 'prev_amount')
pipe.add(DividendsByExDate.next_currency.latest, 'next_currency')
pipe.add(DividendsByExDate.previous_currency.latest, 'prev_currency')
pipe.add(DividendsByExDate.next_type.latest, 'next_type')
pipe.add(DividendsByExDate.previous_type.latest, 'prev_type')
In [39]:
# Setting some basic liquidity strings (just for good habit)
dollar_volume = AverageDollarVolume(window_length=20)
top_1000_most_liquid = dollar_volume.rank(ascending=False) < 1000

pipe.set_screen(top_1000_most_liquid & DividendsByExDate.previous_amount.latest.notnan())
In [40]:
# The show_graph() method of pipeline objects produces a graph to show how it is being calculated.
pipe.show_graph(format='png')
Out[40]:
In [41]:
# run_pipeline will show the output of your pipeline
pipe_output = run_pipeline(pipe, start_date='2013-11-01', end_date='2013-11-25')
pipe_output
Out[41]:
next_amount next_currency next_ex_date next_type prev_amount prev_currency prev_ex_date prev_type
2013-11-01 00:00:00+00:00 Equity(312 [ALOT]) NaN None NaT None 0.0700 $ 2013-09-11 No Change QoQ
Equity(548 [ASBI]) NaN None NaT None 0.0100 $ 2013-10-02 Decrease
Equity(717 [BAMM]) NaN None NaT None 0.0500 $ 2011-04-01 No Change QoQ
Equity(925 [BKSC]) NaN None NaT None 0.1300 $ 2013-10-03 Increase
Equity(1088 [BRID]) NaN None NaT None 0.0500 $ 2012-11-23 Special
Equity(2526 [EML]) 0.110 $ 2013-11-18 No Change QoQ 0.1100 $ 2013-08-19 Increase
Equity(3068 [FUNC]) NaN None NaT None 0.0100 $ 2010-10-11 No Change QoQ
Equity(3353 [GROW]) 0.005 $ 2013-11-07 No Change QoQ 0.0050 $ 2013-10-03 No Change QoQ
Equity(3536 [HFFC]) NaN None NaT None 0.1125 $ 2013-08-07 No Change QoQ
Equity(4292 [KOSS]) 0.060 $ 2013-12-26 No Change QoQ 0.0600 $ 2013-09-26 No Change QoQ
Equity(5859 [PEBK]) NaN None NaT None 0.0300 $ 2013-08-29 No Change QoQ
Equity(6270 [PWX]) NaN None NaT None 0.0400 $ 2013-05-06 No Change QoQ
Equity(6362 [RBPA_A]) NaN None NaT None 0.1500 $ 2008-04-28 No Change QoQ
Equity(6483 [ARKR]) NaN None NaT None 0.2500 $ 2013-09-24 No Change QoQ
Equity(6924 [SKY]) NaN None NaT None 0.0900 $ 2011-09-14 No Change QoQ
Equity(7510 [PULS]) NaN None NaT None 0.0250 $ 2011-10-05 No Change QoQ
Equity(7736 [UG]) NaN None NaT None 0.4700 $ 2013-05-28 Increase
Equity(7899 [VALU]) NaN None NaT None 0.1500 $ 2013-10-24 No Change QoQ
Equity(8759 [UBCP]) NaN None NaT None 0.0700 $ 2013-09-06 No Change QoQ
Equity(9849 [TLF]) NaN None NaT None 0.2500 $ 2012-02-28 Special
Equity(10034 [SAL]) 0.280 $ 2013-11-06 No Change QoQ 0.2800 $ 2013-08-07 No Change QoQ
Equity(10833 [RGCO]) NaN None NaT None 0.1800 $ 2013-10-11 No Change QoQ
Equity(10981 [LARK]) NaN None NaT None 0.1900 $ 2013-08-12 No Change QoQ
Equity(11695 [THRD]) 0.100 $ 2013-11-06 No Change QoQ 0.1000 $ 2013-08-06 Increase
Equity(12664 [FWV]) NaN None NaT None 0.1900 $ 2013-08-29 No Change QoQ
Equity(12667 [ALLB]) 0.050 $ 2013-11-06 No Change QoQ 0.0500 $ 2013-08-07 No Change QoQ
Equity(13499 [AUBN]) NaN None NaT None 0.2100 $ 2013-09-06 No Change QoQ
Equity(14098 [LTRE]) NaN None NaT None 2.2000 $ 2010-08-18 Special
Equity(14410 [OVBC]) NaN None NaT None 0.2100 $ 2013-10-23 No Change QoQ
Equity(14996 [PFBI]) NaN None NaT None 0.1100 $ 2013-09-12 No Change QoQ
... ... ... ... ... ... ... ... ... ...
2013-11-25 00:00:00+00:00 Equity(25600 [LPHI]) NaN None NaT None 0.0500 $ 2013-09-13 No Change QoQ
Equity(25785 [OLBK]) 0.040 $ 2013-12-11 No Change QoQ 0.0400 $ 2013-08-22 No Change QoQ
Equity(25834 [CHEV]) 0.090 $ 2013-12-11 No Change QoQ 0.0900 $ 2013-09-11 No Change QoQ
Equity(26281 [OPHC]) NaN None NaT None 0.0000 NaN 2009-06-09 Stock
Equity(26348 [FFKY]) NaN None NaT None 0.0500 $ 2009-09-11 Decrease
Equity(26420 [FCLF]) NaN None NaT None 0.0600 $ 2013-11-13 No Change QoQ
Equity(26484 [QCCO]) NaN None NaT None 0.0500 $ 2013-08-20 No Change QoQ
Equity(26914 [OSHC]) NaN None NaT None 0.0600 $ 2013-11-06 No Change QoQ
Equity(26990 [SMMF]) NaN None NaT None 0.0600 $ 2009-05-28 Decrease
Equity(27082 [KFFB]) NaN None NaT None 0.1000 $ 2013-10-29 No Change QoQ
Equity(27513 [OFLX]) NaN None NaT None 1.0000 $ 2012-11-28 Special
Equity(28256 [UCBA]) NaN None NaT None 0.0600 $ 2013-11-06 No Change QoQ
Equity(28305 [TRCB]) NaN None NaT None 0.0200 $ 2013-11-06 No Change QoQ
Equity(28613 [DVCR]) NaN None NaT None 0.0550 $ 2013-09-26 No Change QoQ
Equity(29090 [CZWI]) NaN None NaT None 0.0200 $ 2013-04-02 Initiation
Equity(29152 [DNBF]) 0.070 $ 2013-12-06 No Change QoQ 0.0700 $ 2013-09-06 No Change QoQ
Equity(29353 [FBMS]) NaN None NaT None 0.0375 $ 2013-11-08 No Change QoQ
Equity(29723 [HUSA]) NaN None NaT None 0.2000 $ 2010-12-15 Special
Equity(30955 [SSFN]) NaN None NaT None 0.0100 $ 2013-10-30 No Change QoQ
Equity(32347 [NECB]) NaN None NaT None 0.0300 $ 2013-10-09 No Change QoQ
Equity(32391 [SSBI]) NaN None NaT None 0.1100 $ 2013-05-13 No Change QoQ
Equity(32624 [PBIB]) NaN None NaT None 0.0100 $ 2011-06-15 No Change QoQ
Equity(32818 [SONA]) NaN None NaT None 0.0700 $ 2013-11-08 No Change QoQ
Equity(33132 [MSBF]) NaN None NaT None 0.0300 $ 2012-06-28 No Change QoQ
Equity(33774 [ATV]) NaN None NaT None 0.2300 $ 2010-11-11 Special
Equity(35160 [EDS]) NaN None NaT None 0.0500 $ 2008-08-13 No Change QoQ
Equity(35396 [SFBC]) NaN None NaT None 0.0500 $ 2013-11-11 No Change QoQ
Equity(36240 [VRS]) NaN None NaT None 0.0300 $ 2008-11-14 No Change QoQ
Equity(41415 [ZX]) NaN None NaT None 0.0600 $ 2012-03-28 Initiation
Equity(41893 [PBSK]) NaN None NaT None 0.0500 $ 2013-10-29 Increase

1538 rows × 8 columns

Taking what we've seen from above, let's see how we'd move that into the backtester.

In [1]:
# This section is only importable in the backtester
from quantopian.algorithm import attach_pipeline, pipeline_output

# General pipeline imports
from quantopian.pipeline import Pipeline
from quantopian.pipeline.factors import AverageDollarVolume

# Import the datasets available
from quantopian.pipeline.data.eventvestor import (
    DividendsByExDate,
    DividendsByPayDate,
    DividendsByAnnouncementDate,
)
from quantopian.pipeline.factors.eventvestor import (
    BusinessDaysSincePreviousExDate,
    BusinessDaysUntilNextExDate,
    BusinessDaysSinceDividendAnnouncement,
)

def make_pipeline():
    # Create our pipeline
    pipe = Pipeline()
    
    # Screen out penny stocks and low liquidity securities.
    dollar_volume = AverageDollarVolume(window_length=20)
    is_liquid = dollar_volume.rank(ascending=False) < 1000
    
    # Create the mask that we will use for our percentile methods.
    base_universe = (is_liquid)

    # Add pipeline factors
    pipe.add(DividendsByExDate.next_date.latest, 'next_ex_date')
    pipe.add(DividendsByExDate.previous_date.latest, 'prev_ex_date')
    pipe.add(DividendsByExDate.next_amount.latest, 'next_amount')
    pipe.add(DividendsByExDate.previous_amount.latest, 'prev_amount')
    pipe.add(DividendsByExDate.next_currency.latest, 'next_currency')
    pipe.add(DividendsByExDate.previous_currency.latest, 'prev_currency')
    pipe.add(DividendsByExDate.next_type.latest, 'next_type')
    pipe.add(DividendsByExDate.previous_type.latest, 'prev_type')
    pipe.add(BusinessDaysUntilNextExDate(), 'business_days')

    # Set our pipeline screens
    pipe.set_screen(is_liquid)
    return pipe

def initialize(context):
    attach_pipeline(make_pipeline(), "pipeline")
    
def before_trading_start(context, data):
    results = pipeline_output('pipeline')
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-1-3168cdf5a6e5> in <module>()
      7 
      8 # Import the datasets available
----> 9 from quantopian.pipeline.data.eventvestor import (
     10     DividendsByExDate,
     11     DividendsByPayDate,

ImportError: cannot import name DividendsByExDate

Now you can take that and begin to use it as a building block for your algorithms, for more examples on how to do that you can visit our data pipeline factor library