mirror of
https://github.com/wassname/catalyst.git
synced 2026-08-11 05:42:18 +08:00
API: Add factory for calendars
This commit is contained in:
+21
-5
@@ -47,23 +47,24 @@ from zipline.data.data_portal import DataPortal
|
||||
from zipline.data.us_equity_pricing import PanelBarReader
|
||||
from zipline.errors import (
|
||||
AttachPipelineAfterInitialize,
|
||||
CannotOrderDelistedAsset,
|
||||
HistoryInInitialize,
|
||||
NoSuchPipeline,
|
||||
OrderDuringInitialize,
|
||||
OrderInBeforeTradingStart,
|
||||
PipelineOutputDuringInitialize,
|
||||
RegisterAccountControlPostInit,
|
||||
RegisterTradingControlPostInit,
|
||||
ScheduleFunctionInvalidCalendar,
|
||||
SetBenchmarkOutsideInitialize,
|
||||
SetCancelPolicyPostInit,
|
||||
SetCommissionPostInit,
|
||||
SetSlippagePostInit,
|
||||
UnsupportedCancelPolicy,
|
||||
UnsupportedCommissionModel,
|
||||
UnsupportedDatetimeFormat,
|
||||
UnsupportedOrderParameters,
|
||||
UnsupportedSlippageModel,
|
||||
CannotOrderDelistedAsset,
|
||||
UnsupportedCancelPolicy,
|
||||
SetCancelPolicyPostInit,
|
||||
OrderInBeforeTradingStart
|
||||
)
|
||||
from zipline.finance.trading import TradingEnvironment
|
||||
from zipline.finance.blotter import Blotter
|
||||
@@ -122,6 +123,7 @@ from zipline.utils.events import (
|
||||
make_eventrule,
|
||||
date_rules,
|
||||
time_rules,
|
||||
calendars,
|
||||
AfterOpen,
|
||||
BeforeClose
|
||||
)
|
||||
@@ -1081,6 +1083,8 @@ class TradingAlgorithm(object):
|
||||
The rule for the times to execute this function.
|
||||
half_days : bool, optional
|
||||
Should this rule fire on half days?
|
||||
calendar : Sentinel, optional
|
||||
Calendar used to reconcile date and time rules.
|
||||
|
||||
See Also
|
||||
--------
|
||||
@@ -1106,7 +1110,19 @@ class TradingAlgorithm(object):
|
||||
# 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
|
||||
cal = calendar or self.trading_calendar
|
||||
if calendar is None:
|
||||
cal = self.trading_calendar
|
||||
elif calendar is calendars.US_EQUITIES:
|
||||
cal = get_calendar('NYSE')
|
||||
elif calendar is calendars.US_FUTURES:
|
||||
cal = get_calendar('us_futures')
|
||||
else:
|
||||
raise ScheduleFunctionInvalidCalendar(
|
||||
given_calendar=calendar,
|
||||
allowed_calendars=(
|
||||
'[calendars.US_EQUITIES, calendars.US_FUTURES]'
|
||||
),
|
||||
)
|
||||
|
||||
self.add_event(
|
||||
make_eventrule(date_rule, time_rule, cal, half_days),
|
||||
|
||||
Reference in New Issue
Block a user