create_indicator: Create indicator by definition function and variables...

Description Usage Arguments Value See Also Examples

View source: R/indicator-build.R

Description

Use definition function and variable timeseries to create indicator.

Usage

1
2
3
4
5
6
7
8
9
create_indicator(
  ts_def_vars,
  ind_def_fun,
  ...,
  debug = FALSE,
  date_index_field = c("date"),
  key_fields = NULL,
  parallel = getOption("zstmodelr.common.parallel", TRUE)
)

Arguments

ts_def_vars

A dataframe of variable timeseries to create indicator.

ind_def_fun

A function of defining indicator.

...

Params to ind_def_fun.

debug

A logic to determine whether to turn on debug in creating indicator. Default FALSE means not to use debug.

date_index_field

Name of date index field of ts_def_vars, default 'date'.

key_fields

A character vector of key fields, which identify unique observation in each date. Default NULL means to not divide data into groups.

parallel

A logic to determine whether to use parallel processing. Default TRUE means to use parallel processing.

Value

A dataframe of new indicator timeseries if succeed, otherwise NULL.

See Also

Other indicator build functions: compute_indicator(), modify_indicator()

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
28
29
30
31
32
33
## Not run: 

# load vars dataset for generating indicators
ds_all_vars <- get_indicator_vars(stock_db,
  indicator_defs = ds_indicator_defs
)

# create ind_expr
indicator_formula <- c("stock_return <- mretwd
                          market_return <- cmretwdtl
                          model <- lm(stock_return ~ market_return)
                          beta <- coef(model)['market_return']")
indicator_expr <- create_expr(!!indicator_formula)

# create def_fun for indicator
indicator_def_fun <- create_indicator_def_fun(
  indicator_code = "m_stock_beta1",
  indicator_expr = indicator_expr,
  rolly_window = 12,
  period = "month"
)

# create a indicator from vars dataset.
ts_indicator <- create_indicator(
  ds_def_vars,
  ind_def_fun = ind_def_fun,
  debug = FALSE,
  date_index_field = "date",
  key_fields = "stkcd",
  parallel = TRUE
)

## End(Not run)

chriszheng2016/zstmodelr documentation built on June 13, 2021, 8:59 p.m.