1 REM OPTLOSS  
5 CLEAR  1000  
10 CLS:PRINT  TAB(10);"OPPORTUNITY LOSS TABLE  "  
20 PRINT "THIS PROGRAM ASSUMES THERE ARE FROM 1 TO 6 STATES OF NATURE.  
25 PRINT "THERE ARE ALSO FROM 1 TO 6 POSSIBLE ACTIONS WE CAN TAKE. IF THE  
30 PRINT "STATE OF NATURE(S OF N) IS KNOWN THEN EACH ACTION LEADS TO  
35 PRINT "A KNOWN MONETARY RESULT. THIS RESULT IS A CONDITIONAL PROFIT.  
40 PRINT "FOR EXAMPLE, IF ACTION 3 LEADS TO A $35 PAYOFF WHEN STATE OF  
45 PRINT "NATURE 4 IS TRUE THEN 35 IS THE CONDITIONAL PROFIT OF ACTION  
50 PRINT "3 GIVEN STATE OF NATURE 4. IF WE LOOK AT THE CONDITIONAL  
55 PRINT "PROFIT OF EACH ACTION WITH RESPECT TO A PARTICULAR S OF N  
60 PRINT "THEN THERE IS A LARGEST PROFIT. THE AMOUNT BY WHICH EACH OF  
65 PRINT "THE OTHER PROFITS DIFFER FROM THE MAXIMUM IS CALLED THE  
70 PRINT "OPPORTUNITY LOSS OF THE CORRESPONDING ACTION FOR THE  
75 PRINT "PARTICULAR STATE OF NATURE. IN THIS PROGRAM ALL OF THE  
80 PRINT "CONDITIONAL PROFITS ARE ENTERED AND AN OPPORTUNITY LOSS  
85 PRINT "TABLE IS CONSTRUCTED. EXPECTED OPORTUNITY LOSSES ARE ALSO COMP."  
95 INPUT "PRESS ENTER TO BEGIN";Z9$  
100 D=6:REM MAXIMUM DIMENSION  
102 DIM  A(D+2,D+2),P(D),E(D)  
105 P=0  
110 CLS  
120 INPUT "ENTER NUMBER OF POSSIBLE STATES OF NATURE";N  
125 IF  N<2  OR  N>D  OR  N<>INT(N)  THEN  GOSUB  10000:GOTO  120  
127 PRINT   
130 FOR  I=1  TO  N  
135 PRINT "ENTER PROBABILITY OF S OF N";I;:INPUT  P(I)  
140 P=P+P(I)  
150 NEXT  I  
160 IF  P=1  THEN  PRINT :GOTO  200  
170 PRINT :PRINT "PROBABILITIES DO NOT SUM TO 1."  
175 INPUT "ENTER 1 TO STANDARDIZE,0 TO BEGIN OVER";Z9  
180 IF  Z9<>0  AND  Z9<>1  THEN  GOSUB  10000:GOTO  170  
185 IF  Z9=0  THEN  GOTO  105  
190 FOR  I=1 TO N:P(I)=P(I)/P:NEXT :P=1  
200 PRINT :INPUT "ENTER NUMBER OF POSSIBLE ACTIONS(<=5)";M  
205 IF  M<2  OR  M>6  OR  M<>INT(M)  THEN  GOSUB  10000:GOTO  200  
210 PRINT  "NO PAYOFF MORE THAN 9999.99":PRINT   
220 FOR  J=1  TO  M  
225 PRINT   
230 PRINT "ACTION";J  
240 FOR  I=1  TO  N  
250 PRINT  TAB(5);"PAYOFF WHEN S OF N IS";I;:INPUT  A(I,J)  
260 NEXT  I  
270 NEXT  J  
300 REM COMPUTATION  
310 CLS:PRINT  @  340,"COMPUTING"  
320 FOR  I=1  TO  N  
325 MM(I)=A(I,1)  
330 FOR  J=2  TO  M  
335 IF  A(I,J)>MM(I)  THEN  MM(I)=A(I,J)  
340 NEXT  J  
345 NEXT  I  
350 REM OPPORTUNITY LOSSES COMPUTED NEXT  
355 FOR  I=1 TO N:FOR J=1 TO M: A(I,J)=MM(I)-A(I,J):NEXT :NEXT   
400 FOR  J=1  TO  M  
410 FOR I=1 TO N:E(J)=E(J)+A(I,J)*P(I):NEXT I:REM EXP. VAL.   
420 NEXT  J  
495 REM PRINT  
500 CLS  
510 F$(1)=" ACTION # "  
515 F$(2)=" #####.## "  
520 F$(3)=" OPPORTUNITY LOSSES OF ACTION GIVEN S OF N "  
521 F$(4)="S N  PR                  ACTION"  
525 PRINT :INPUT "IS LINE PRINTER OUTPUT DESIRED(Y/N)";Z2$  
527 IF  Z2$<>"Y"  AND  Z2$<>"N"  THEN  GOSUB  10000:GOTO  525  
530 PRINT  F$(3):PRINT :PRINT  F$(4):IF  Z2$="Y"  THEN  LPRINT  F$(3):LPRINT " ":LPRINT  F$(4)  
535 PRINT  TAB(9);"";:FOR  I=1 TO M:PRINT USING  F$(1);I;:NEXT :PRINT   
537 IF  Z2$="Y"  THEN  LPRINT  TAB(9);"";:FOR  I=1 TO M:LPRINT  USING   F$(1);I;:NEXT :LPRINT " "  
540 FOR  I=1  TO  N  
550 PRINT USING  "##  #.## ";I,P(I);  
555 IF  Z2$="Y"  THEN  LPRINT  USING  "##  #.## ";I,P(I);  
560 FOR  J=1  TO  M:PRINT USING  F$(2);A(I,J);:NEXT :PRINT   
562 IF  Z2$="Y"  THEN  FOR  J=1  TO  M:LPRINT  USING  F$(2);A(I,J);:NEXT :LPRINT " "  
563 NEXT   
564 PRINT :IF  Z2$="Y"  THEN  LPRINT " "  
565 PRINT  "EXP EOL.";TAB(9);"";:  
570 IF  Z2$="Y"  THEN  LPRINT  "EXP VAL.";TAB(9);"";:  
575 FOR  I=1 TO M:PRINT USING  F$(2);E(I);:NEXT   
580 IF  Z2$="Y"  THEN  FOR  I=1 TO M:LPRINT  USING  F$(2);E(I);:NEXT   
600 PRINT :END  
10000 PRINT "INPUT ERROR!TRY AGAIN!":FOR  JJ=1 TO 300:NEXT :RETURN   
10100 INPUT "PRESS ENTER TO CONTINUE";Z9$:RETURN   

