MCPcopy Index your code
hub / github.com/quantopian/zipline / schedule_function

Method schedule_function

zipline/algorithm.py:893–960  ·  view source on GitHub ↗

Schedule a function to be called repeatedly in the future. Parameters ---------- func : callable The function to execute when the rule is triggered. ``func`` should have the same signature as ``handle_data``. date_rule : zipline.utils

(self,
                          func,
                          date_rule=None,
                          time_rule=None,
                          half_days=True,
                          calendar=None)

Source from the content-addressed store, hash-verified

891
892 @api_method
893 def schedule_function(self,
894 func,
895 date_rule=None,
896 time_rule=None,
897 half_days=True,
898 calendar=None):
899 """
900 Schedule a function to be called repeatedly in the future.
901
902 Parameters
903 ----------
904 func : callable
905 The function to execute when the rule is triggered. ``func`` should
906 have the same signature as ``handle_data``.
907 date_rule : zipline.utils.events.EventRule, optional
908 Rule for the dates on which to execute ``func``. If not
909 passed, the function will run every trading day.
910 time_rule : zipline.utils.events.EventRule, optional
911 Rule for the time at which to execute ``func``. If not passed, the
912 function will execute at the end of the first market minute of the
913 day.
914 half_days : bool, optional
915 Should this rule fire on half days? Default is True.
916 calendar : Sentinel, optional
917 Calendar used to compute rules that depend on the trading calendar.
918
919 See Also
920 --------
921 :class:`zipline.api.date_rules`
922 :class:`zipline.api.time_rules`
923 """
924
925 # When the user calls schedule_function(func, <time_rule>), assume that
926 # the user meant to specify a time rule but no date rule, instead of
927 # a date rule and no time rule as the signature suggests
928 if isinstance(date_rule, (AfterOpen, BeforeClose)) and not time_rule:
929 warnings.warn('Got a time rule for the second positional argument '
930 'date_rule. You should use keyword argument '
931 'time_rule= when calling schedule_function without '
932 'specifying a date_rule', stacklevel=3)
933
934 date_rule = date_rule or date_rules.every_day()
935 time_rule = ((time_rule or time_rules.every_minute())
936 if self.sim_params.data_frequency == 'minute' else
937 # If we are in daily mode the time_rule is ignored.
938 time_rules.every_minute())
939
940 # Check the type of the algorithm's schedule before pulling calendar
941 # Note that the ExchangeTradingSchedule is currently the only
942 # TradingSchedule class, so this is unlikely to be hit
943 if calendar is None:
944 cal = self.trading_calendar
945 elif calendar is calendars.US_EQUITIES:
946 cal = get_calendar('XNYS')
947 elif calendar is calendars.US_FUTURES:
948 cal = get_calendar('us_futures')
949 else:
950 raise ScheduleFunctionInvalidCalendar(

Callers 3

initializeMethod · 0.80
initializeMethod · 0.80

Calls 4

add_eventMethod · 0.95
make_eventruleFunction · 0.90
every_dayMethod · 0.80

Tested by 3

initializeMethod · 0.64
initializeMethod · 0.64