step_zigzag: Extract ZigZag features

Description Usage Arguments Details Value Examples

View source: R/step_zigzag.R

Description

step_zigzag creates a specification of a recipe step that will extract ZigZag features from an asset price historical data.

Usage

1
2
3
4
5
6
7
step_zigzag(recipe, ..., change = 1, percent = TRUE, retrace = FALSE,
  state = FALSE, span = c(0, 0), prefix = "zigzag", h = NULL,
  l = NULL, c = NULL, type = NULL, role = "predictor",
  trained = FALSE, skip = FALSE, id = rand_id("zigzag"))

## S3 method for class 'step_zigzag'
tidy(x, info = "terms", ...)

Arguments

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 "high", and "low" prices, respectively. Otherwise, if only one column name is given, it will treated as "close" price.

change

A numeric vector of length one, to specify the minimum price change to be considered as the change from peak or trough.

percent

A logical to specify whether the change argument should be interpreted as percentage change (TRUE) or absolute change (FALSE)

retrace

A logical to specify whether the change argument should be interpreted as a change from previous move, or from last peak/trough.

state

An option to specify whether to return the current states of the ZigZag. Defaults to FALSE.

span

A numeric vector of length one to specify the swing span. Default to c(0, 0); zero addition to backward and forward. See details.

prefix

A character vector of length one that would be used as a prefix to the created columns.

h

A container for the names of "high". Leave to NULL as it will be populated by prep() function.

l

A container for the names of "low". Leave to NULL as it will be populated by prep() function.

c

A container for the names of "close". Leave to NULL as it will be populated by prep() function.

type

A container for the final series type that would be used ("hl" or "c"). Leave to NULL as it will be populated by prep() function.

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 "predictors" in a model.

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 skip = TRUE as it may affect the computations for subsequent operations

id

A character string that is unique to this step to identify it.

x

A step_zigzag object.

info

Options for tidy() method; whether to return tidied information for used "terms" or "params"

Details

The output from this step are several new columns which contains the extracted moving average features.

For basic output, this step will produces:

If state argument is TRUE, it will also produces:

Note that the "up" and "down" are positioned at the time before the trend change; you can control its wide and position using span arguments.

Value

An updated version of recipe with the new step added to the sequence of existing steps (if any).

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# import libs
library(quantrecipes)

# basic usage
rec <- recipe(. ~ ., data = btcusdt) %>%
  step_zigzag(close) %>%
  step_naomit(all_predictors()) %>%
  prep()

# get preprocessed data
juice(rec)

bagasbgy/quantrecipes documentation built on Dec. 25, 2019, 7:54 a.m.