MAINT: Removes static calendar from schedule_function rules

This commit is contained in:
jfkirk
2016-06-08 13:34:19 -04:00
committed by Jean Bredeche
parent 591ae02a02
commit 31f9f06c9a
4 changed files with 95 additions and 50 deletions
+21 -4
View File
@@ -53,8 +53,12 @@ from zipline.errors import (
UnsupportedDatetimeFormat,
UnsupportedOrderParameters,
UnsupportedSlippageModel,
CannotOrderDelistedAsset, UnsupportedCancelPolicy, SetCancelPolicyPostInit,
OrderInBeforeTradingStart)
CannotOrderDelistedAsset,
UnsupportedCancelPolicy,
SetCancelPolicyPostInit,
OrderInBeforeTradingStart,
ScheduleFunctionWithoutCalendar,
)
from zipline.finance.trading import TradingEnvironment
from zipline.finance.blotter import Blotter
from zipline.finance.commission import PerShare, CommissionModel
@@ -94,7 +98,10 @@ from zipline.utils.api_support import (
from zipline.utils.input_validation import ensure_upper_case, error_keywords
from zipline.utils.cache import CachedObject, Expired
from zipline.utils.calendars import default_nyse_schedule
from zipline.utils.calendars import (
default_nyse_schedule,
ExchangeTradingSchedule,
)
import zipline.utils.events
from zipline.utils.events import (
EventManager,
@@ -981,8 +988,18 @@ class TradingAlgorithm(object):
# If we are in daily mode the time_rule is ignored.
time_rules.every_minute())
# Check the type of the algorithm's schedule before pulling calendar
# Note that the ExchangeTradingSchedule is currently the only
# TradingSchedule class, so this is unlikely to be hit
# TODO The calendar should be a required arg for schedule_function
if not isinstance(self.trading_schedule, ExchangeTradingSchedule):
raise ScheduleFunctionWithoutCalendar(
schedule=self.trading_schedule
)
cal = self.trading_schedule._exchange_calendar
self.add_event(
make_eventrule(date_rule, time_rule, half_days),
make_eventrule(date_rule, time_rule, cal, half_days),
func,
)