home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.barnyard.co.uk
/
2015.02.ftp.barnyard.co.uk.tar
/
ftp.barnyard.co.uk
/
cpm
/
walnut-creek-CDROM
/
CPM
/
MISC
/
FINANCE
/
INVEST.LBR
/
CGAF.BZS
/
CGAF.BAS
Wrap
BASIC Source File
|
2000-06-30
|
3KB
|
86 lines
5 REM PRINT CHR$(26) -- CLEAR THE SCREEN REPLACE IF NECESSARY
10 DIM X(174),W(12),E(150),X$(151)
20 REM N=NUMBER OF DATA POINTS IN THE TIME SERIES (MAXIMUM 150)
30 REM P=ORDER OF AUTOREGRESSIVE PROCESS, I.E. AR(P), (MAXIMUM 12)
40 REM K=LEARNING CONSTANT SET IT IN ANY OTHER VALUE THAN 1/P IF SO DESIRED
50 PRINT CHR$(26)
60 C = 0: PRINT "INPUT UP TO 150 DATA POINTS"
70 PRINT "TYPE IN 'X' TO DELETE LAST ENTRY"
80 PRINT "AND 'F' WHEN FINISHED INPUTTING DATA"
90 PRINT
100 PRINT "INPUT DATA POINT #";C + 1;: INPUT " ";X$(C + 1)
110 IF X$(C + 1) = "F" THEN GOTO 160
120 IF X$(C + 1) = "X" THEN C = C - 1: GOTO 100
130 X(C + 1) = VAL (X$(C + 1))
140 C = C + 1
150 GOTO 100
160 PRINT : PRINT : INPUT "ENTER THE NUMBER OF PARAMETERS (1-12):";P
170 IF P < 1 OR P > 12 THEN GOTO 160
180 N = C
190 K = 1 / P
200 FOR I = 1 TO P
210 W(I) = 1 / P
220 NEXT I
230 REM L1 = MAX NUMBER OF ITERATIONS (CYCLES)
240 L1 = 100
250 PRINT CHR$(26)
260 PRINT "ITERATION MSE PARAMETERS"
270 PRINT " OF ADAPTIVE"
280 PRINT " FILTERING"
290 PRINT " MODEL"
300 S1 = 1E+37
310 FOR L = 1 TO L1
320 S = 0
330 H1 = 0
340 FOR I = P + 1 TO N
350 F = 0
360 FOR J = 1 TO P
370 F = F + W(J) * X(I - J)
380 H1 = H1 + X(I - J) * X(I - J)
390 NEXT J
400 H1 = SQR (H1)
410 REM E(I)=ERROR,X(I)=ACTUAL VALUE,F=FORECAST,I=P+1 TO N
420 E(I) = X(I) - F
430 FOR J = 1 TO P
440 REM UPDATING THE PARAMETERS OF AR(P),H1=STANDARDIZATION
450 REM CONSTANT STANDARDIZING E(I) AND X(I-J) BEFORE USE
460 W(J) = W(J) + 2 * K * E(I) / H1 * X(I - J) / H1
470 NEXT J
480 S = S + E(I) ^ 2
490 NEXT I
500 PRINT TAB( 4);L; TAB( 14) INT ((S / (N - P + 1)) * 10000 + .5) / 10000;
510 PRINT TAB( 25);
520 FOR J = 1 TO P
530 PRINT INT (W(J) * 1000 + .5) / 1000;" ";
540 NEXT J
550 REM IF THE MSE DOES NOT DECREASE BY AT LEAST 1/1000 STOP PROGRAM
560 IF S + .0001 > S1 THEN 600
570 S1 = S
580 PRINT
590 NEXT L
600 REM M=NUMBER OF FORECASTS DESIRED, MAXIMUM 24
610 M = 6
620 PRINT : PRINT "PERIOD FORECAST"
630 FOR I = N + 1 TO N + M
640 F = 0
650 FOR J = 1 TO P
660 F = F + W(J) * X(I - J)
670 NEXT J
680 X(I) = F
690 PRINT I, INT (F * 10000 + .5) / 10000
700 NEXT I
710 PRINT
720 PRINT "THE PARAMETERS ARE :"
730 FOR X = 1 TO P
740 PRINT INT (W(X) * 1000 + .5) / 1000;" ";
750 NEXT X
760 PRINT
770 PRINT "THE MSE = "; INT (S / (N - P + 1) * 10000 + .5) / 10000
780 PRINT : PRINT
790 PRINT "DO YOU WANT TO RUN WITH SAME DATA (Y/N)": INPUT AN$
800 IF AN$ = "Y" OR AN$ = "y" THEN GOTO 160
810 PRINT : INPUT "DO YOU WANT TO RUN THIS PROGRAM AGAIN (Y/N) ";AN$
820 IF AN$ = "Y" OR AN$ = "y" THEN GOTO 50
830 END
10 PRINT : INPUT "DO YOU WANT TO RUN THIS PROGRAM AGAIN (Y/N) ";AN$
820 IF AN$ = "Y"