16.20 - MovingAverage Example: Modified Moving Average - Teradata Database - Teradata Vantage NewSQL Engine

Teradata Vantage™ - NewSQL Engine Analytic Functions

Product
Teradata Database
Teradata Vantage NewSQL Engine
Release Number
16.20
Release Date
July 2019
Content Type
Programming Reference
Publication ID
B035-1206-162K
Language
English (United States)

This example computes the triangular moving average for the price of stock.

SQL Call

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

Output

id name period stockprice stockprice_mmavg
1 Company1 1961-05-17 00:00:00.000000 460.000000000000 460.000000000000
2 Company1 1961-05-18 00:00:00.000000 457.000000000000 459.700000000000
3 Company1 1961-05-19 00:00:00.000000 452.000000000000 458.930000000000
4 Company1 1961-05-22 00:00:00.000000 459.000000000000 458.937000000000
5 Company1 1961-05-23 00:00:00.000000 462.000000000000 459.243300000000
6 Company1 1961-05-24 00:00:00.000000 459.000000000000 459.218970000000
7 Company1 1961-05-25 00:00:00.000000 463.000000000000 459.597073000000
8 Company1 1961-05-26 00:00:00.000000 479.000000000000 461.537365700000
9 Company1 1961-05-29 00:00:00.000000 493.000000000000 464.683629130000
10 Company1 1961-05-31 00:00:00.000000 490.000000000000 467.215266217000
11 Company1 1961-06-01 00:00:00.000000 492.000000000000 469.693739595300
12 Company1 1961-06-02 00:00:00.000000 498.000000000000 472.524365635770
13 Company1 1961-06-05 00:00:00.000000 499.000000000000 475.171929072193
14 Company1 1961-06-06 00:00:00.000000 497.000000000000 477.354736164974
15 Company1 1961-06-07 00:00:00.000000 496.000000000000 479.219262548476
16 Company1 1961-06-08 00:00:00.000000 490.000000000000 480.297336293629
17 Company1 1961-06-09 00:00:00.000000 489.000000000000 481.167602664266
18 Company1 1961-06-12 00:00:00.000000 478.000000000000 480.850842397839
19 Company1 1961-06-13 00:00:00.000000 487.000000000000 481.465758158055
20 Company1 1961-06-14 00:00:00.000000 491.000000000000 482.419182342250
21 Company1 1961-06-15 00:00:00.000000 487.000000000000 482.877264108025
22 Company1 1961-06-16 00:00:00.000000 482.000000000000 482.789537697222
23 Company1 1961-06-19 00:00:00.000000 479.000000000000 482.410583927500
24 Company1 1961-06-20 00:00:00.000000 478.000000000000 481.969525534750
25 Company1 1961-06-21 00:00:00.000000 479.000000000000 481.672572981275