Teradata R Package Function Reference | 17.00 - 17.00 - ExponentialMovAvg - Teradata R Package

Teradata® R Package Function Reference

Teradata R Package
September 2020
Programming Reference


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


  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



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


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


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


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.
Types: character OR vector of Strings (character)


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
Types: numeric


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.
Default Value: 2
Types: integer


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


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.
Types: character OR vector of Strings (character)


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


    # Get the current context/connection
    con <- td_get_context()$connection
    # Load example data.
    loadExampleData("exponentialmovavg_example", "ibm_stock")

    # Create object(s) of class "tbl_teradata".
    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