Time Series Analysis: Exponential Smoothing

Date: 198x
Type: Program
Platform(s): TS 2068

Smooth out data points.

Appears on

One of a series of library tapes. Programs on these tapes were renamed to a number series. This tape contained programs 20001 to 20050. These tapes were compiled by Tony Willing.

Gallery

Time Series Analysis: Exponential Smoothing

Source Code

    2 REM "EXP SMOOTH"
    4 PRINT "VARIABLES :": PRINT 
    5 PRINT "A   CONSTANT ALPHA"
    6 PRINT "E(I)  QUADRATIC ERROR"
    7 PRINT "F   VALUE ESTIMATED BY"
    8 PRINT "   THE EXPONENTIAL SMOOTHING"
    9 PRINT "M(K)  VALUE ESTIMATED BY THE"
   10 PRINT "   EXPONENTIAL SMOOTHING FOR"
   11 PRINT "    A SPECIFC ALPHA"
   12 PRINT "N   NUMBER OF OBSERVATIONS-line      900"
   13 PRINT "P   NUMBER OF PERIODS TO"
   14 PRINT "    BASE THE SMOOTHING ON--line     920"
   15 PRINT "V(I)  OBSERVED VALUE FOR PERIOD      I--line 910"
   20 PAUSE 340: CLS : PRINT 
   30 PRINT "TIME SERIES ANALYSIS:"
   40 PRINT "EXPONENTIAL SMOOTHING"
   50 PRINT "-------------------------------"
   60 PRINT : PRINT 
   65 READ N
   70 PRINT "NUMBER OF OBSERVATIONS ";N
   80 DIM V(10): DIM M(20): DIM E(20)
   90 PRINT 
  100 FOR I=1 TO N
  105 READ V(I)
  110 PRINT "VALUE FOR PERIOD ";I;TAB ( 22);V(I)
  130 NEXT I
  140 PRINT 
  150 PRINT "NUMBER OF PERIODS RETAINED"
  154 READ P
  155 PRINT "FOR THE SMOOTHING? ";P
  160 REM    CALCULATION OF THE AVERAGES WITH DIFFERENT ALPHAS.
  170 LET V1=0
  180 IF P<1 OR P>=N THEN GO TO 140
  190 FOR I=1 TO 10
  200 LET M(I)=0: LET E(I)=0
  210 NEXT I
  220 FOR I=1 TO P
  230 LET V1=V1+V(I)
  240 NEXT I
  250 LET V2=V1/P
  260 LET A=0.01: LET I4=2
  270 GO SUB 730
  280 LET A=0.05: LET I4=3
  290 GO SUB 730
  300 FOR J=1 TO 9
  310 LET A=J/10
  320 LET I4=3+J
  330 GO SUB 730
  340 NEXT J
  350 REM   FIND THE MINIMUM SUM OF ERROES SQUARED
  360 LET I3=2
  370 LET E3=E(2)
  380 FOR I=3 TO 12
  390 IF E(I)>E3 THEN GO TO 420
  400 LET E3=E(I)
  410 LET I3=I
  420 NEXT I
  430 IF I3=3 THEN GO TO 470
  440 IF I3>3 THEN GO TO 490
  450 LET A=0.01
  460 GO TO 510
  470 LET A=0.05
  480 GO TO 510
  490 LET A=0.1*(I3-3)
  500 PRINT : PRINT : PRINT 
  510 PRINT "BEST SMOOTHING CONSTANT (ALPHA)"
  520 PRINT "(DETERMINED BY FINDING THE MINIMUM OF"
  525 PRINT "THE SUM OF THE ERRORS SQUARED) = ";A
  530 REM  FORECAST OF N+1
  540 PRINT : PRINT 
  550 PRINT "FORECAST FOR PERIOD ";N+1;":"
  560 PRINT "------------------------"
  570 PRINT "   ALPHA       VALUE"
  580 PRINT "------------------------"
  585 DEF FN A(X)=INT (100*X+.5)/100
  590 PRINT TAB ( 4);.01;TAB ( 15);FN A(M(2))
  600 PRINT TAB ( 4);.05;TAB ( 15);FN A(M(3))
  610 FOR I=1 TO 9
  620 LET A=I/10
  630 LET K=3+I
  640 PRINT TAB ( 4);A;TAB ( 15);FN A(M(K))
  650 NEXT I
  660 PRINT "-------------------------------"
  670 PRINT : PRINT 
  680 PRINT "CHANGE NUMBER OF PERIODS"
  690 INPUT "RETAINED FOR THE SMOOTHING? (Y/N) ";C$
  700 PRINT 
  710 IF C$<>"N" THEN RESTORE : GO TO 140
  720 GO TO 850
  730 REM   EXPONENTIAL SMOOTHING SUBROUTINE
  740 LET P1=P+1
  750 LET E1=0
  760 LET F=V2
  770 FOR I=P1 TO N
  775 LET Z=(F-V(I))^2
  780 LET E1=E1+Z
  790 LET F=A*V(I)+(1-A)*F
  800 IF I<>N THEN GO TO 830
  810 LET M(I4)=F
  820 LET E(I4)=E1
  830 NEXT I
  840 RETURN 
  850 STOP 
  900 DATA 10
  910 DATA 4.30,4.10,3.81,3.14,2.95,2.58,2.49,2.39,1.75,1.66
  920 DATA 9

People

No people associated with this content.

Scroll to Top