Smoothes a time series curve by computing the average of all the data points in a fixed-width sliding window and replacing those points with the computed value.
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
Source Code
2 REM "MOV AVGS" 4 PRINT " VARIABLES:": PRINT : PRINT 5 PRINT "N NUMBER OF PERIODS OBSERVED -Line 600" 6 PRINT "P RANGE OF PERIODS FOR THE MOVING AVERAGES- Line 610" 7 PRINT "R RATIO OF AVERAGE TO ORIGINAL OBSERVATION" 8 PRINT "V(I) OBSERVATION FOR PERIOD I -Line 620 to end" 9 PRINT "U(I) MOVING AVERAGE FOR PERIOD I" 10 REM 20 PAUSE 340: CLS : PRINT : PRINT 30 PRINT "TIME-SERIES ANALYSIS" 40 PRINT "BY MOVING AVERAGES" 50 PRINT "-------------------------------" 60 REM DATA INPUT 70 READ N,P 80 DIM V(N): DIM U(N) 100 FOR I=1 TO N 120 READ V(I) 130 NEXT I 140 LET C1=1 150 PRINT 160 PRINT "MOVING AVERAGE CALCULATION" 180 REM CALCULATION OF AVERAGES 190 LET M=N-P+1 200 FOR I=1 TO M 210 LET T=0 220 FOR J=1 TO P 230 LET T=T+V(I+J-1) 240 NEXT J 250 LET U(I)=INT (100*(T/P))/100 260 NEXT I 270 PRINT : PRINT 280 PRINT "CALCULATION #";C1;" BASED ON ";P; " PERIODS" 290 PRINT "-------------------------------" 300 PRINT "PER OBSERM SMOOTHED VALUE RATIO" 310 PRINT "-------------------------------" 320 LET M1=M 330 IF P<>2*INT (P/2) THEN GO TO 380 340 LET M1=M-1 350 FOR K=1 TO M1 360 LET U(K)=INT (100*(U(K)+U(K+1))/2)/100 370 NEXT K 380 FOR K=1 TO M1 390 LET R=INT (100*(V(K+INT (P/2))/U(K)))/100 400 PRINT TAB ( 2);K+INT (P/2);TAB ( 5);V(K+INT (P/2)); 410 PRINT TAB ( 16);U(K);TAB ( 28);R 420 NEXT K 430 PRINT "-------------------------------" 440 PRINT : PRINT : PRINT 450 PRINT "CHANGE THE BASE PERIOD===> TYPE <1>" 460 PRINT "CALCULATE A SECOND" 465 PRINT " MOVING AVERAGE ==> TYPE <2>" 467 PRINT 470 INPUT "QUIT ===> TYPE <3> ? ";C 480 IF C=1 THEN GO TO 150 481 IF C=2 THEN GO TO 490 482 IF C=3 THEN GO TO 550 490 LET C1=C1+1 500 LET N=M1 510 FOR I=1 TO N 520 LET V(I)=U(I): LET U(I)=0 530 NEXT I 540 GO TO 150 550 STOP 600 DATA 36 610 DATA 12 620 DATA 144.02,125.17,142.15,153.08,152.27,131.12,139.43,136.73,136.94,151.28 630 DATA 172.20,187.55,141.48,178.47,127.19,142.19,148.43,149.43,141.18,135.64 640 DATA 144.69,171.95,153.60,188.92,128.93,137.30,159.05,154.75,138.11,140.96 650 DATA 126.49,152.18,149.19,137.01,191.35,187.35