indicator_attribute: Add attribute to indicator timeseries of stocks

Description Usage Arguments Details Value Functions Examples

Description

Compute attribute values of stocks and add them to indicator timeseries.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
attr_indicators(
  ts_indicators,
  new_attr_def,
  parallel = getOption("zstmodelr.common.parallel", TRUE)
)

attr_indicators_indcd(
  stock_db,
  ts_indicators,
  parallel = getOption("zstmodelr.common.parallel", TRUE)
)

attr_indicators_trdstat(
  stock_db,
  ts_indicators,
  parallel = getOption("zstmodelr.common.parallel", TRUE)
)

Arguments

ts_indicators

A dataframe of indicator timeseries.

new_attr_def

A function to compute attribute value for stock indicator.

parallel

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

stock_db

A stock database object to get data.

Details

attr_indicators is a working horse behind attr_indicators_indcd,attr_indicators_trdstat, which is mainly used to develop customized attribute function to add attribute to indicator timeseries.

attr_indicators_indcd, attr_indicators_trdstat, etc. are used to add predefined attribute to indicator timeseries by using data from stock_db.

There are two way to add attribute to timeseries of indicators of stocks:

Value

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

Functions

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
34
35
36
37
38
39
40
41
42
43
44
## Not run: 

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


# --- add attribute directly ---

# add attribute of indcd
ts_indicators_with_indcd <- attr_indicators_indcd(stock_db,
  ts_indicators = ts_indicators
)

# add attribute of trdstats
ts_indicators_wide_with_attr <- attr_indicators_trdstat(stock_db,
  ts_indicators = ts_indicators
)

# --- add attribute indirectly ---

# create attr defs by using data from stock
new_attr_indcd <- ind_attr_def_indcd(stock_db)

# use attribute def to modify multi-indicators
for (i in seq_len(NROW(ds_ts_indicators))) {
  ts_indicator <- ds_ts_indicators$data[[i]]

  ts_indicator <- modify_indicator(
    ts_indicator = ts_indicator,
    modify_fun = new_attr_indcd,
    replace_exist = FALSE,
    date_index_field = "date",
    key_fields = "stkcd",
    parallel = parallel
  )
}

## End(Not run)

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