scheduling: Schedule a function to be called according to some timed...

Description Usage Arguments Zipline Documentation Examples

Description

fly_schedule_function() allows you to schedule an R function to run at timed iterations. Helpers are defined to declare the frequency at which to execute the function.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
fly_schedule_function(func, date_rule = NULL, time_rule = NULL,
  half_days = TRUE, calendar = NULL)

every_day()

month_end(days_offset = 0L)

month_start(days_offset = 0L)

week_end(days_offset = 0L)

week_start(days_offset = 0L)

every_minute()

market_close()

market_open()

Arguments

func

The function to execute at timed intervals. Must take context and data as its first and second arguments.

date_rule

One of: every_day(), month_end(), month_start(), week_start(), or week_end(). If NULL, the default is every_day().

time_rule

One of: every_minute(), market_close(), or market_open(). If NULL, the default is every_minute().

half_days

A boolean. Should this rule fire on half days?

calendar

Calendar used to reconcile date and time rules.

Zipline Documentation

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# Just print i at each iteration
scheduled_fn <- function(context, data) {
  print(context$i)
}

fly_initialize <- function(context) {

  # Init to 0
  context$i = 0L

  # No extra timing arguments means "Always" (every day / every minute)
  fly_schedule_function(scheduled_fn)
}

fly_handle_data <- function(context, data) {

  # Increment day
  context$i <- context$i + 1L
}

# You should see the context$i variable printed at each day
performance <- fly_run_algorithm(
  fly_initialize,
  fly_handle_data,
  start = as.Date("2015-01-01"),
  end   = as.Date("2016-01-01")
)

DavisVaughan/flyingfox documentation built on May 5, 2019, 12:28 a.m.