Description
The function computes the moving average over a number of points in a series
based on the selected moving average type.
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 |
Types: character |
Value
Function returns an object of class "td_moving_average_sqle" 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") loadExampleData("weightedmovavg_example", "stock_vol") # Create remote tibble objects. ibm_stock <- tbl(con, "ibm_stock") # 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" ) # 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" ) # 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: 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" ) # 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" ) # 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" )