mirror of
https://github.com/wassname/catalyst.git
synced 2026-08-13 12:00:16 +08:00
MAINT: Removes static calendar from schedule_function rules
This commit is contained in:
+21
-4
@@ -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,
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user