Description Usage Arguments Details Value Functions Examples
Compute attribute values of stocks and add them to indicator timeseries.
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)
)
|
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. |
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:
add attribute directly:
use attr_indicators_indcd
, attr_indicators_trdstat
to add attribute directly. The pros is easy to use, the cons is slow since
it have to load data from stock database each calling. The method is
mainly used to add one attribute to one indicator timeseries.
add attribute indirectly:
use ind_attr_def_indcd
, ind_attr_def_trdstat
and
modify_indicator
. The pros is that it can be faster by dividing
defining attribute(load data from database once) and modifying indicators
(can modify repeatedly by using same attribute definition). The cons is that it is more complex than direct method. The method is mainly
used to add same attribute to multi-indicators timeseries.
A dataframe of indicator timeseries with new attribute if succeed, otherwise NULL.
attr_indicators
: add customized attribute to indicators
timeseries of stocks.
attr_indicators_indcd
: add attribute of industry code to indicator
timeseries of stocks.
attr_indicators_trdstat
: add attribute of trading status to indicator
timeseries of stocks.
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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.