Description
The MovingAverage function calculates the moving average of the
target columns based on the moving average types argument ("mvgtype").
Possible moving average types:
'C' - Cumulative moving average.
'E' - Exponential moving average.
'M' - Modified moving average.
'S' - Simple moving average.
'T' - Triangular moving average.
'W' - Weighted moving average.
Note: This function is only available when tdplyr is connected to Vantage 1.1 or later versions.
Usage
td_moving_average_sqle ( data = NULL, target.columns = NULL, alpha = 0.1, start.rows = 2, window.size = 10, include.first = FALSE, mavgtype = "C", data.partition.column = NULL, data.order.column = NULL )
Arguments
data |
Required Argument. |
data.partition.column |
Required Argument. |
data.order.column |
Required Argument. |
target.columns |
Optional Argument. |
alpha |
Optional Argument. |
start.rows |
Optional Argument. |
window.size |
Optional Argument. |
include.first |
Optional Argument. |
mavgtype |
Optional Argument.
Default Value: "C" |
Value
Function returns an object of class "td_moving_average_sqle" which is
a named list containing object of class "tbl_teradata".
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") loadExampleData("weightedmovavg_example", "stock_vol") # Create object(s) of class "tbl_teradata". ibm_stock <- tbl(con, "ibm_stock") # Example 1: Compute the exponential moving average td_exponential_mov_avg_out <- td_moving_average_sqle(data = ibm_stock, data.partition.column = c("name"), data.order.column = c("period"), target.columns = c("stockprice"), start.rows = 10, include.first = TRUE, mavgtype = "E" ) # Example 2: Compute the cumulative moving average for "stockprice". td_cumulative_mov_avg_out <- td_moving_average_sqle(data = ibm_stock, data.partition.column = c("name"), data.order.column = c("period"), target.columns = c("stockprice"), mavgtype = "C" ) # Example 3: Compute the simple moving average for "stockprice". td_simple_mov_avg_out <- td_moving_average_sqle(data = ibm_stock, data.partition.column = "name", data.order.column = "period", target.columns = "stockprice", include.first = TRUE, window.size = 10, mavgtype = "S" ) # The input table, stock_vol, contains hypothetical stock price and volume data of three # companies between 17 May 1961 and 21 June 1961. stock_vol <- tbl(con, "stock_vol") # Example 4: This example computes the weighted moving average for stockprice and volume # for three companies. td_weighted_mov_avg_out <- td_moving_average_sqle(data = stock_vol, data.partition.column = c("id"), data.order.column = c("name"), target.columns = c("stockprice","volume"), include.first = TRUE, window.size = 5, mavgtype = "W" ) # Example 5: Triangular Moving Average td_triangular_mov_avg_out <- td_moving_average_sqle(data = stock_vol, data.partition.column = "name", data.order.column = "period", target.columns = c("stockprice"), include.first = TRUE, window.size = 3, mavgtype = "T" ) # Example 6: Modified Moving Average. td_modified_mov_avg_out <- td_moving_average_sqle(data = stock_vol, data.partition.column = "name", data.order.column = "period", target.columns = c("stockprice"), include.first = TRUE, window.size = 3, mavgtype = "M" )