Description Usage Arguments Details Value Examples
step_bbands
creates a specification of a recipe
step that will extract Bollinger Bands features from an asset price
historical data.
1 2 3 4 5 6 7 8 9 10 11 | step_bbands(recipe, ..., ma_fun = TTR::SMA, n = 20, sd_mult = 2,
weights = NULL, ma_options = list(), state = FALSE,
previous = TRUE, thresholds = bbands_thresholds(),
prefix = "bbands", h = NULL, l = NULL, c = NULL, type = NULL,
role = "predictor", trained = FALSE, skip = FALSE,
id = rand_id("bbands"))
bbands_thresholds(high = 1, medhigh = 0.75, medlow = 0.25, low = 0)
## S3 method for class 'step_bbands'
tidy(x, info = "terms", ...)
|
recipe |
A recipe object. The step will be added to the sequence of operations for this recipe. |
... |
Either three or one (unquoted) column name(s). If three columns
are given, it will represent the |
ma_fun |
A |
n |
A |
sd_mult |
A |
weights |
A |
ma_options |
A |
state |
An option to specify whether to return
the current states of the Bollinger Bands. Defaults to |
previous |
An option to specify whether to return
the summary of previous states. Defaults to |
thresholds |
A |
prefix |
A |
h |
A container for the names of |
l |
A container for the names of |
c |
A container for the names of |
type |
A container for the final series type that
would be used ( |
role |
For model terms created by this step, what analysis
role should they be assigned? By default, the function assumes
that the created columns will be used
as |
trained |
A logical to indicate if the necessary informations for preprocessing have been estimated. |
skip |
A logical. Should the step be skipped when the
recipe is baked by bake()? While all operations are baked
when prep() is run, some operations may not
be able to be conducted on new data (e.g. processing
the outcome variable(s)). Care should be taken when using |
id |
A character string that is unique to this step to identify it. |
high |
Threshold for |
medhigh |
Threshold for |
medlow |
Threshold for |
low |
Threshold for |
x |
A |
info |
Options for |
The output from this step are several new columns which contains the extracted Bollinger Bands features.
For basic output, this step will produces:
dn
: lower band
ma
: moving average
up
: upper band
pctb
: calculated percentage B
If state
argument is TRUE
, it will also produces:
state
: current percentage B state
state_count
: cumulative count in current state
These states are determined using four different threshold, which listed
in thresholds
arguments. These are the default threshold values:
high
: pctb > high
(the default is high = 1
)
medhigh
: high > pctb > medhigh
(the default is medhigh = 0.75
)
medlow
: low < pctb < medlow
(the default is medlow = 0.25
)
low
: pctb < low
(the default is low = 0
)
Note: that the rest values would be categorized as "medium"
.
Those default values are produced from bbands_thresholds()
helper functions; any modification to the threshold could be made through
this helper functions. See examples for some demonstrations.
Additionally, if previous
argument is TRUE
, it will also provides
some summary regarding previous Bollinger Bands states:
prev_state
: previous state
prev_medium
: previous medium-state ("medhigh"
, "medlow"
)
prev_break
: previous break-state ("high"
, "low"
)
An updated version of recipe
with the new step
added to the sequence of existing steps (if any).
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 | # import libs
library(quantrecipes)
# basic usage
rec <- recipe(. ~ ., data = btcusdt) %>%
step_bbands(high, low, close) %>%
step_naomit(all_predictors()) %>%
prep()
# get preprocessed data
juice(rec)
# using state argument
rec <- recipe(. ~ ., data = btcusdt) %>%
step_bbands(high, low, close, state = TRUE) %>%
step_naomit(all_predictors()) %>%
prep()
# get preprocessed data
juice(rec)
# modify the threshold
rec <- recipe(. ~ ., data = btcusdt) %>%
step_bbands(high, low, close, state = TRUE, thresholds = bbands_thresholds(
high = 0.9, medhigh = 0.65, medlow = 0.35, low = 0.1
)) %>%
step_naomit(all_predictors()) %>%
prep()
# get preprocessed data
juice(rec)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.