Teradata R Package Function Reference - ExponentialMovAvg - Teradata R Package - Look here for syntax, methods and examples for the functions included in the Teradata R Package.

Teradata® R Package Function Reference

Product
Teradata R Package
Release Number
16.20
Published
February 2020
Language
English (United States)
Last Update
2020-02-28
dita:id
B700-4007
lifecycle
previous
Product Category
Teradata Vantage

Description

The EMAVG function computes the exponential moving average of points in a time series, exponentially decreasing the weights of older values.

Usage

  td_exponential_mov_avg_mle (
      data = NULL,
      target.columns = NULL,
      alpha = 0.1,
      start.rows = 2,
      include.first = FALSE,
      data.sequence.column = NULL,
      data.partition.column = NULL,
      data.order.column = NULL
  )

Arguments

data

Required Argument.
Specifies the name of the tbl_teradata that contains the columns.

data.partition.column

Required Argument.
Specifies Partition By columns for data.
Values to this argument can be provided as vector, if multiple columns are used for partition.
Types: character OR vector of Strings (character)

data.order.column

Required Argument.
Specifies Order By columns for data.
Values to this argument can be provided as vector, if multiple columns are used for ordering.
Types: character OR vector of Strings (character)

target.columns

Optional Argument.
Specifies the input column names for which the moving average is to be computed. If you omit this argument, then the function copies every input column to the output tbl_teradata but does not compute moving average.

alpha

Optional Argument.
Specifies the damping factor, a value in the range [0, 1], which represents a percentage in the range [0, 100]. For example, if alpha is 0.2, then the damping factor is 20 older observations faster.
Default Value: 0.1

start.rows

Optional Argument.
Specifies the number of rows at the beginning of the time series that the function skips before it begins the calculation of the exponential moving average. The function uses the arithmetic average of these rows as the initial value of the exponential moving average. The value n must be an integer.
Default Value: 2

include.first

Optional Argument.
Specifies whether to include the starting rows in the output table. If you specify "TRUE", the output columns for the starting rows contain NULL, because their exponential moving average is undefined.
Default Value: FALSE

data.sequence.column

Optional Argument.
Specifies the vector of column(s) that uniquely identifies each row of the input argument "data". The argument is used to ensure deterministic results for functions which produce results that vary from run to run.

Value

Function returns an object of class "td_exponential_mov_avg_mle" which is a named list containing Teradata tbl object. Named list member can be referenced directly with the "$" operator using name: result.

Examples

    # Get the current context/connection
    con <- td_get_context()$connection
    
    # Load example data.
    loadExampleData("exponentialmovavg_example", "ibm_stock")
    
    # Create remote tibble objects.
    ibm_stock <- tbl(con, "ibm_stock")
    
    # Example - Compute the exponential moving average
    td_exponential_mov_avg_out <- td_exponential_mov_avg_mle(data = ibm_stock,
                                                         data.partition.column = c("name"),
                                                         data.order.column = c("period"),
                                                         target.columns = c("stockprice"),
                                                         start.rows = 10,
                                                         include.first = TRUE
                                                         )