mirror of
https://github.com/wassname/catalyst.git
synced 2026-08-12 11:50:11 +08:00
TST: add test for 13d filings dataset
MAINT: add 13d filings to factors init MAINT: rename constant MAINT: add event_date_col field
This commit is contained in:
@@ -1,12 +1,8 @@
|
|||||||
"""
|
"""
|
||||||
Tests for the reference loader for 13d filings.
|
Tests for the reference loader for 13d filings.
|
||||||
"""
|
"""
|
||||||
from unittest import TestCase
|
|
||||||
|
|
||||||
from contextlib2 import ExitStack
|
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
|
|
||||||
from .base import EventLoaderCommonMixin
|
|
||||||
from zipline.pipeline.common import(
|
from zipline.pipeline.common import(
|
||||||
DAYS_SINCE_PREV_DISCLOSURE,
|
DAYS_SINCE_PREV_DISCLOSURE,
|
||||||
DISCLOSURE_DATE,
|
DISCLOSURE_DATE,
|
||||||
@@ -25,11 +21,25 @@ from zipline.pipeline.loaders.utils import (
|
|||||||
zip_with_floats,
|
zip_with_floats,
|
||||||
zip_with_dates
|
zip_with_dates
|
||||||
)
|
)
|
||||||
from zipline.testing import tmp_asset_finder
|
from zipline.testing.fixtures import WithPipelineEventDataLoader
|
||||||
|
from zipline.testing.fixtures import ZiplineTestCase
|
||||||
|
|
||||||
date_intervals = [[None, '2014-01-04'], ['2014-01-05', '2014-01-09'],
|
date_intervals = [[None, '2014-01-04'],
|
||||||
|
['2014-01-05', '2014-01-09'],
|
||||||
['2014-01-10', None]]
|
['2014-01-10', None]]
|
||||||
|
|
||||||
|
empty_df = pd.DataFrame(
|
||||||
|
columns=[NUM_SHARES,
|
||||||
|
PERCENT_SHARES,
|
||||||
|
DISCLOSURE_DATE,
|
||||||
|
TS_FIELD_NAME],
|
||||||
|
)
|
||||||
|
|
||||||
|
empty_df[NUM_SHARES] = empty_df[NUM_SHARES].astype('float')
|
||||||
|
empty_df[PERCENT_SHARES] = empty_df[PERCENT_SHARES].astype('float')
|
||||||
|
empty_df[TS_FIELD_NAME] = empty_df[TS_FIELD_NAME].astype('datetime64[ns]')
|
||||||
|
empty_df[DISCLOSURE_DATE] = empty_df[DISCLOSURE_DATE].astype('datetime64[ns]')
|
||||||
|
|
||||||
_13d_filngs_cases = [
|
_13d_filngs_cases = [
|
||||||
pd.DataFrame({
|
pd.DataFrame({
|
||||||
NUM_SHARES: [1, 15],
|
NUM_SHARES: [1, 15],
|
||||||
@@ -37,29 +47,25 @@ _13d_filngs_cases = [
|
|||||||
TS_FIELD_NAME: pd.to_datetime(['2014-01-05', '2014-01-10']),
|
TS_FIELD_NAME: pd.to_datetime(['2014-01-05', '2014-01-10']),
|
||||||
DISCLOSURE_DATE: pd.to_datetime(['2014-01-04', '2014-01-09'])
|
DISCLOSURE_DATE: pd.to_datetime(['2014-01-04', '2014-01-09'])
|
||||||
}),
|
}),
|
||||||
pd.DataFrame(
|
empty_df
|
||||||
columns=[NUM_SHARES,
|
|
||||||
PERCENT_SHARES,
|
|
||||||
DISCLOSURE_DATE,
|
|
||||||
TS_FIELD_NAME],
|
|
||||||
dtype='datetime64[ns]'
|
|
||||||
),
|
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
def get_expected_previous_values(zip_date_index_with_vals,
|
def get_expected_previous_values(zip_date_index_with_vals,
|
||||||
dates,
|
vals,
|
||||||
vals_for_date_intervals):
|
date_intervals,
|
||||||
|
dates):
|
||||||
return pd.DataFrame({
|
return pd.DataFrame({
|
||||||
0: get_values_for_date_ranges(zip_date_index_with_vals,
|
0: get_values_for_date_ranges(zip_date_index_with_vals,
|
||||||
vals_for_date_intervals,
|
vals,
|
||||||
date_intervals,
|
date_intervals,
|
||||||
dates),
|
dates),
|
||||||
1: zip_date_index_with_vals(dates, ['NaN'] * len(dates)),
|
1: zip_date_index_with_vals(dates, ['NaN'] * len(dates)),
|
||||||
}, index=dates)
|
}, index=dates)
|
||||||
|
|
||||||
|
|
||||||
class _13DFilingsLoaderTestCase(TestCase, EventLoaderCommonMixin):
|
class _13DFilingsLoaderTestCase(WithPipelineEventDataLoader,
|
||||||
|
ZiplineTestCase):
|
||||||
"""
|
"""
|
||||||
Test for _13_filings dataset.
|
Test for _13_filings dataset.
|
||||||
"""
|
"""
|
||||||
@@ -79,37 +85,27 @@ class _13DFilingsLoaderTestCase(TestCase, EventLoaderCommonMixin):
|
|||||||
return range(2)
|
return range(2)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def setUpClass(cls):
|
def get_dataset(cls):
|
||||||
cls._cleanup_stack = stack = ExitStack()
|
return {sid: frame
|
||||||
cls.finder = stack.enter_context(
|
for sid, frame
|
||||||
tmp_asset_finder(equities=cls.get_equity_info()),
|
in enumerate(_13d_filngs_cases)}
|
||||||
)
|
|
||||||
cls.cols = {}
|
|
||||||
cls.dataset = {sid:
|
|
||||||
frame
|
|
||||||
for sid, frame
|
|
||||||
in enumerate(_13d_filngs_cases)}
|
|
||||||
cls.loader_type = _13DFilingsLoader
|
|
||||||
|
|
||||||
@classmethod
|
loader_type = _13DFilingsLoader
|
||||||
def tearDownClass(cls):
|
|
||||||
cls._cleanup_stack.close()
|
|
||||||
|
|
||||||
def setup(self, dates):
|
def setup(self, dates):
|
||||||
_expected_previous_num_shares = get_expected_previous_values(
|
cols = {}
|
||||||
zip_with_floats, dates,
|
cols[
|
||||||
['NaN', 1, 15]
|
|
||||||
)
|
|
||||||
_expected_previous_percent_shares = get_expected_previous_values(
|
|
||||||
zip_with_floats, dates,
|
|
||||||
['NaN', 10, 20]
|
|
||||||
)
|
|
||||||
self.cols[
|
|
||||||
PREVIOUS_DISCLOSURE_DATE
|
PREVIOUS_DISCLOSURE_DATE
|
||||||
] = get_expected_previous_values(zip_with_dates, dates,
|
] = get_expected_previous_values(zip_with_dates,
|
||||||
['NaT', '2014-01-04', '2014-01-09'])
|
['NaT', '2014-01-04', '2014-01-09'],
|
||||||
self.cols[PREVIOUS_NUM_SHARES] = _expected_previous_num_shares
|
date_intervals, dates)
|
||||||
self.cols[PREVIOUS_PERCENT_SHARES] = _expected_previous_percent_shares
|
cols[PREVIOUS_NUM_SHARES] = get_expected_previous_values(
|
||||||
self.cols[DAYS_SINCE_PREV_DISCLOSURE] = self._compute_busday_offsets(
|
zip_with_floats, ['NaN', 1, 15], date_intervals, dates
|
||||||
self.cols[PREVIOUS_DISCLOSURE_DATE]
|
|
||||||
)
|
)
|
||||||
|
cols[PREVIOUS_PERCENT_SHARES] = get_expected_previous_values(
|
||||||
|
zip_with_floats, ['NaN', 10, 20], date_intervals, dates
|
||||||
|
)
|
||||||
|
cols[DAYS_SINCE_PREV_DISCLOSURE] = self._compute_busday_offsets(
|
||||||
|
cols[PREVIOUS_DISCLOSURE_DATE]
|
||||||
|
)
|
||||||
|
return cols
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ NUM_SHARES = 'number_shares'
|
|||||||
NEXT_RELEASE_DATE = 'next_release_date'
|
NEXT_RELEASE_DATE = 'next_release_date'
|
||||||
NEXT_STANDARD_DEVIATION = 'next_standard_deviation'
|
NEXT_STANDARD_DEVIATION = 'next_standard_deviation'
|
||||||
PAY_DATE_FIELD_NAME = 'pay_date'
|
PAY_DATE_FIELD_NAME = 'pay_date'
|
||||||
PERCENT_SHARES = 'percentage'
|
PERCENT_SHARES = 'percent_shares'
|
||||||
PREVIOUS_ACTUAL_VALUE = 'previous_actual_value'
|
PREVIOUS_ACTUAL_VALUE = 'previous_actual_value'
|
||||||
PREVIOUS_AMOUNT = 'previous_amount'
|
PREVIOUS_AMOUNT = 'previous_amount'
|
||||||
PREVIOUS_ANNOUNCEMENT = 'previous_announcement'
|
PREVIOUS_ANNOUNCEMENT = 'previous_announcement'
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ from .factor import (
|
|||||||
RecarrayField,
|
RecarrayField,
|
||||||
)
|
)
|
||||||
from .events import (
|
from .events import (
|
||||||
|
BusinessDaysSince13DFilingsDate,
|
||||||
BusinessDaysSinceCashBuybackAuth,
|
BusinessDaysSinceCashBuybackAuth,
|
||||||
BusinessDaysSinceDividendAnnouncement,
|
BusinessDaysSinceDividendAnnouncement,
|
||||||
BusinessDaysUntilNextExDate,
|
BusinessDaysUntilNextExDate,
|
||||||
@@ -28,6 +29,7 @@ from .technical import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
|
'BusinessDaysSince13DFilingsDate',
|
||||||
'BusinessDaysSinceCashBuybackAuth',
|
'BusinessDaysSinceCashBuybackAuth',
|
||||||
'BusinessDaysSinceDividendAnnouncement',
|
'BusinessDaysSinceDividendAnnouncement',
|
||||||
'BusinessDaysUntilNextExDate',
|
'BusinessDaysUntilNextExDate',
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ class _13DFilingsLoader(EventsLoader):
|
|||||||
expected_cols = frozenset([DISCLOSURE_DATE,
|
expected_cols = frozenset([DISCLOSURE_DATE,
|
||||||
PERCENT_SHARES,
|
PERCENT_SHARES,
|
||||||
NUM_SHARES])
|
NUM_SHARES])
|
||||||
|
event_date_col = DISCLOSURE_DATE
|
||||||
|
|
||||||
def __init__(self, all_dates, events_by_sid,
|
def __init__(self, all_dates, events_by_sid,
|
||||||
infer_timestamps=False,
|
infer_timestamps=False,
|
||||||
@@ -36,14 +37,12 @@ class _13DFilingsLoader(EventsLoader):
|
|||||||
def disclosure_date_loader(self):
|
def disclosure_date_loader(self):
|
||||||
return self._previous_event_date_loader(
|
return self._previous_event_date_loader(
|
||||||
self.dataset.disclosure_date,
|
self.dataset.disclosure_date,
|
||||||
DISCLOSURE_DATE
|
|
||||||
)
|
)
|
||||||
|
|
||||||
@lazyval
|
@lazyval
|
||||||
def percent_shares_loader(self):
|
def percent_shares_loader(self):
|
||||||
return self._previous_event_value_loader(
|
return self._previous_event_value_loader(
|
||||||
self.dataset.percent_shares,
|
self.dataset.percent_shares,
|
||||||
DISCLOSURE_DATE,
|
|
||||||
PERCENT_SHARES
|
PERCENT_SHARES
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -51,6 +50,5 @@ class _13DFilingsLoader(EventsLoader):
|
|||||||
def number_shares_loader(self):
|
def number_shares_loader(self):
|
||||||
return self._previous_event_value_loader(
|
return self._previous_event_value_loader(
|
||||||
self.dataset.number_shares,
|
self.dataset.number_shares,
|
||||||
DISCLOSURE_DATE,
|
|
||||||
NUM_SHARES
|
NUM_SHARES
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -65,4 +65,4 @@ class Blaze_13DFilingsLoader(BlazeEventsLoader):
|
|||||||
})
|
})
|
||||||
|
|
||||||
concrete_loader = _13DFilingsLoader
|
concrete_loader = _13DFilingsLoader
|
||||||
concrete_dataset=_13DFilings
|
concrete_dataset = _13DFilings
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
from ._13d_filings import _13DFilingsLoader
|
from ._13d_filings import Blaze_13DFilingsLoader
|
||||||
from .buyback_auth import (
|
from .buyback_auth import (
|
||||||
BlazeCashBuybackAuthorizationsLoader,
|
BlazeCashBuybackAuthorizationsLoader,
|
||||||
BlazeShareBuybackAuthorizationsLoader
|
BlazeShareBuybackAuthorizationsLoader
|
||||||
@@ -20,7 +20,7 @@ from .earnings import (
|
|||||||
from .consensus_estimates import BlazeConsensusEstimatesLoader
|
from .consensus_estimates import BlazeConsensusEstimatesLoader
|
||||||
|
|
||||||
__all__ = (
|
__all__ = (
|
||||||
'_13DFilingsLoader',
|
'Blaze_13DFilingsLoader',
|
||||||
'BlazeCashBuybackAuthorizationsLoader',
|
'BlazeCashBuybackAuthorizationsLoader',
|
||||||
'BlazeDividendsByAnnouncementDateLoader',
|
'BlazeDividendsByAnnouncementDateLoader',
|
||||||
'BlazeConsensusEstimatesLoader',
|
'BlazeConsensusEstimatesLoader',
|
||||||
|
|||||||
Reference in New Issue
Block a user