MovingAverage Function Example | Teradata Vantage - Example: Exponential Moving Average - Analytics Database

Database Analytic Functions

Deployment
VantageCloud
VantageCore
Edition
Enterprise
IntelliFlex
VMware
Product
Analytics Database
Release Number
17.20
Published
June 2022
Language
English (United States)
Last Update
2024-04-06
dita:mapPath
gjn1627595495337.ditamap
dita:ditavalPath
ayr1485454803741.ditaval
dita:id
jmh1512506877710
Product Category
Teradata Vantageā„¢

This example computes an exponential moving average for the price of stock.

MovingAverage SQL Call for Exponential Moving Average

SELECT * FROM MovingAverage (
  ON company1_stock PARTITION BY name ORDER BY period
  USING
  MAvgType ('E')
  TargetColumns ('stockprice')
  StartRows (10)
  Alpha (0.1)
  IncludeFirst ('true')
) AS dt ORDER BY id;

MovingAverage Output for Exponential Moving Average

id name period stockprice stockprice_emavg
1 Company1 1961-05-17 00:00:00.000000 460.000000000000 ?
2 Company1 1961-05-18 00:00:00.000000 457.000000000000 ?
3 Company1 1961-05-19 00:00:00.000000 452.000000000000 ?
4 Company1 1961-05-22 00:00:00.000000 459.000000000000 ?
5 Company1 1961-05-23 00:00:00.000000 462.000000000000 ?
6 Company1 1961-05-24 00:00:00.000000 459.000000000000 ?
7 Company1 1961-05-25 00:00:00.000000 463.000000000000 ?
8 Company1 1961-05-26 00:00:00.000000 479.000000000000 ?
9 Company1 1961-05-29 00:00:00.000000 493.000000000000 ?
10 Company1 1961-05-31 00:00:00.000000 490.000000000000 467.400000000000
11 Company1 1961-06-01 00:00:00.000000 492.000000000000 469.860000000000
12 Company1 1961-06-02 00:00:00.000000 498.000000000000 472.674000000000
13 Company1 1961-06-05 00:00:00.000000 499.000000000000 475.306600000000
14 Company1 1961-06-06 00:00:00.000000 497.000000000000 477.475940000000
15 Company1 1961-06-07 00:00:00.000000 496.000000000000 479.328346000000
16 Company1 1961-06-08 00:00:00.000000 490.000000000000 480.395511400000
17 Company1 1961-06-09 00:00:00.000000 489.000000000000 481.255960260000
18 Company1 1961-06-12 00:00:00.000000 478.000000000000 480.930364234000
19 Company1 1961-06-13 00:00:00.000000 487.000000000000 481.537327810600
20 Company1 1961-06-14 00:00:00.000000 491.000000000000 482.483595029540
21 Company1 1961-06-15 00:00:00.000000 487.000000000000 482.935235526586
22 Company1 1961-06-16 00:00:00.000000 482.000000000000 482.841711973927
23 Company1 1961-06-19 00:00:00.000000 479.000000000000 482.457540776535
24 Company1 1961-06-20 00:00:00.000000 478.000000000000 482.011786698881
25 Company1 1961-06-21 00:00:00.000000 479.000000000000 481.710608028993