step_cumret: Calculate cumulative returns based on specified actions

Description Usage Arguments Details Value Examples

View source: R/step_cumret.R

Description

step_cumret creates a specification of a recipe step that will calculate cumulative returns from a set of strategy actions and historical prices.

Usage

1
2
3
4
5
6
7
step_cumret(recipe, ..., prices, fee = 0.001, mult = FALSE,
  buy = "buy", sell = "sell", hold = "hold", prefix = "cumret",
  actions = NULL, role = "predictor", trained = FALSE,
  skip = FALSE, id = rand_id("cumret"))

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

Arguments

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.

prices

A quoted column name which will be used as historical price data.

fee

A numeric vector pf length one, which will be used as fee for each trade action.

mult

A logical vector to specify whether to return the cumulative returns as cash multiplier or just the return. Defaults to FALSE

buy

A character vector of length one which indicates buy action(s) inside the selected actions columns. Default to "buy".

sell

A character vector of length one which indicates sell action(s) inside the selected actions columns. Default to "sell".

hold

A character vector of length one which indicates hold action(s) inside the selected actions columns. Default to "hold".

prefix

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

actions

A container for selected actions columns. 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_cumret object.

info

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

Details

This step will return the calculated (log) cumulative returns, either just as a return, or as a cash multiplier for each selected columns.

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 = actions) %>%
  step_cumret(benchmark, portfolio, prices = "close") %>%
  step_naomit(all_predictors()) %>%
  prep()

# get preprocessed data
juice(rec)

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