Skip to content

Commit

Permalink
Merge pull request #1308 from quantopian/fix-pipeline-calendar
Browse files Browse the repository at this point in the history
BUG: Don't use calendar from daily bars in USEquityPricingLoader
  • Loading branch information
Andrew Daniels authored Jun 28, 2016
2 parents 43f4c3a + 5ac66aa commit c89e957
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 4 deletions.
49 changes: 48 additions & 1 deletion tests/pipeline/test_pipeline_algo.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,6 @@ class PipelineAlgorithmTestCase(WithBcolzDailyBarReaderFromCSVs,
ASSET_FINDER_EQUITY_SYMBOLS = 'AAPL', 'MSFT', 'BRK_A'
START_DATE = Timestamp('2014')
END_DATE = Timestamp('2015')
BCOLZ_DAILY_BAR_USE_FULL_CALENDAR = True

@classmethod
def make_daily_bar_data(cls):
Expand Down Expand Up @@ -592,3 +591,51 @@ def before_trading_start(context, data):
)

self.assertTrue(count[0] > 0)

def test_pipeline_beyond_daily_bars(self):
"""
Ensure that we can run an algo with pipeline beyond the max date
of the daily bars.
"""

# For ensuring we call before_trading_start.
count = [0]

current_day = default_nyse_schedule.next_execution_day(
self.pipeline_loader.raw_price_loader.last_available_dt,
)

def initialize(context):
pipeline = attach_pipeline(Pipeline(), 'test')

vwap = VWAP(window_length=10)
pipeline.add(vwap, 'vwap')

# Nothing should have prices less than 0.
pipeline.set_screen(vwap < 0)

def handle_data(context, data):
pass

def before_trading_start(context, data):
context.results = pipeline_output('test')
self.assertTrue(context.results.empty)
count[0] += 1

algo = TradingAlgorithm(
initialize=initialize,
handle_data=handle_data,
before_trading_start=before_trading_start,
data_frequency='daily',
get_pipeline_loader=lambda column: self.pipeline_loader,
start=self.dates[0],
end=current_day,
env=self.env,
)

algo.run(
FakeDataPortal(),
overwrite_sim_params=False,
)

self.assertTrue(count[0] > 0)
6 changes: 3 additions & 3 deletions zipline/pipeline/loaders/equity_pricing_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
)
from zipline.lib.adjusted_array import AdjustedArray
from zipline.errors import NoFurtherDataError
from zipline.utils.calendars import default_nyse_schedule

from .base import PipelineLoader

Expand All @@ -37,11 +38,10 @@ class USEquityPricingLoader(PipelineLoader):

def __init__(self, raw_price_loader, adjustments_loader):
self.raw_price_loader = raw_price_loader
# HACK: Pull the calendar off our raw_price_loader so that we can
# backshift dates.
self._calendar = self.raw_price_loader._calendar
self.adjustments_loader = adjustments_loader

self._calendar = default_nyse_schedule.all_execution_days

@classmethod
def from_files(cls, pricing_path, adjustments_path):
"""
Expand Down

0 comments on commit c89e957

Please sign in to comment.