Description Usage Arguments Details Value Examples
step_ma
creates a specification of a recipe
step that will extract moving average features from an asset price
historical data.
1 2 3 4 5 6 7 |
recipe |
A recipe object. The step will be added to the sequence of operations for this recipe. |
... |
One or more selector functions to choose which variables are affected by the step. See selections (from recipes package) for more details. |
ma_fun |
A |
n |
A |
weights |
A |
ma_options |
A |
state |
An option to specify whether to return
the current states of the calculated moving averages. See details for
more informations. Defaults to |
ratio |
Whether to return the moving average |
prefix |
A |
prices |
A container for selected prices columns. Leave to |
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. |
x |
A |
info |
Options for |
The output from this step are several new columns which contains the extracted moving average features.
For basic output, this step will produces:
value
: the moving average value
If state
argument is TRUE
, it will also produces:
spread
: current spread to the prices
variable
state
: current state of the spread; "bullish"
or "bearish"
Note that if ratio
argument is TRUE
, the spread
value would be
returned as a ratio to prices
variable instead of an absolute difference.
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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | # import libs
library(quantrecipes)
# basic usage
rec <- recipe(. ~ ., data = btcusdt) %>%
step_ma(close) %>%
step_naomit(all_predictors()) %>%
prep()
# get preprocessed data
juice(rec)
# using state argument
rec <- recipe(. ~ ., data = btcusdt) %>%
step_ma(close, state = TRUE) %>%
step_naomit(all_predictors()) %>%
prep()
# get preprocessed data
juice(rec)
# using pass-through options
rec <- recipe(. ~ ., data = btcusdt) %>%
step_ma(close,
ma_fun = TTR::EMA,
n = 10,
ma_options = list(wilder = TRUE),
state = TRUE
) %>%
step_naomit(all_predictors()) %>%
prep()
# get preprocessed data
juice(rec)
# using custom weights for weighted moving average
rec <- recipe(. ~ ., data = btcusdt) %>%
step_ma(close,
ma_fun = TTR::WMA,
n = 10,
weights = c(rep(1, 9), 10),
state = TRUE
) %>%
step_naomit(all_predictors()) %>%
prep()
# get preprocessed data
juice(rec)
# using volume-based moving average
rec <- recipe(. ~ ., data = btcusdt) %>%
step_ma(close,
ma_fun = TTR::VWMA,
n = 10,
weights = "volume",
state = TRUE
) %>%
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.