@ =========================================================== @
@             COMPUTATION OF DECISION RULES                   @
@ =========================================================== @

@ IN THIS PROGRAM WE WILL COMPUTE MARKOV DECISION RULES (MDR)
  FOR THE LINEAR DYNAMIC MODEL @

@ THE EXOGENEOUS VARIABLES WILL BE ASSUMED TO BE GENERATED BY
  AR(1) PROCESSES WITH TRANSITION MATRIX RHO                  @

RHO=ZEROS(NN,NN);
/* FILL IN THE MATRIX */
 

@ USING THE COMPOSITE EXPRESSION, WE HAVE @

FL = SP1*RHO + SP2;
IRHO=EYE(ROWS(RHO));
 

I=1;
LEE=ZEROS(NS,NN);
 DO UNTIL I>NS;
  Q=FL[I,1:NN];
  MU2I=1/MU2[I,I];
  DSUM=INV((IRHO-MU2I*RHO));
  LEE[I,1:NN]=Q*DSUM;
  I=I+1;
 ENDO;

@ ================================================================= @
@                      CAPITAL DECISION RULES                       @
@ ================================================================= @

KEC=RKE*RHO+QKE+KTL*LEE;

ULE=(INV(PS22))*LEE;
ULK=-(INV(PS22))*PS21;

@ ================================================================= @
@                       SYSTEM DECISION RULES                       @
@ ================================================================= @

MKE=ZEROS(ROWS(KLK)+NN,COLS(KLK)+COLS(KEC));
MKE[1:ROWS(KLK),1:COLS(KLK)]=KLK;
MKE[ROWS(KLK)+1:ROWS(KLK)+NN,1:NS]=ZEROS(NN,NS);
MKE[1:ROWS(KEC),COLS(KLK)+1:COLS(KLK)+COLS(KEC)]=KEC;
MKE[ROWS(KEC)+1:ROWS(KEC)+ROWS(RHO),COLS(KLK)+1:COLS(KLK)+COLS(KEC)]=RHO;

@ ================================================================= @
@     INCORPORATION OF SHADOW PRICE, CONTROLS AND OTHER FLOWS       @
@ ================================================================= @

LKE=ZEROS(NS,NS+NN);
LKE[.,1:COLS(ULK)]=ULK; LKE[.,COLS(ULK)+1:COLS(ULK)+COLS(ULE)]=ULE;

Z=(INV(MCC))*MCS;

M0CK=Z[1:NC,1:NS];
M0CL=Z[1:NC,NS+1:2*NS];

M0CE=(INV(MCC))*MCE;

M0CKE=(M0CK+M0CL*ULK)~(M0CE+M0CL*ULE);

FKE=FVC*M0CKE+FVKE+FVL*LKE;

RRKE=(ULK-ULK*KLK)~(ULE-(ULK*KEC+ULE*RHO));

H=LKE|M0CKE|FKE|RRKE;

LOCATE 1,1;
FORMAT /LDS 4,3;
OUTPUT ON;
OUTPUT FILE=KPR.OUT RESET;
"-----------------------------------------------------------------------------";
"   NEAR STEADY STATE DYNAMICS AND PARAMETERIZATION                           ";
"-----------------------------------------------------------------------------";
"-----------------------------------------------------------------------------";
" ---------------  PI'S ----------------                                      ";
"          ";;$NAME[1:NS+NN,1]';
I=1;
DO UNTIL I>NS;
$NAME[I,1];;MKE[I,.];
I=I+1;
ENDO;

I=1;
DO UNTIL I>NS;
$NAME[I+NN+NS,1];;LKE[I,.];
I=I+1;
ENDO;

I=1;
DO UNTIL I>NC;
$NAME[I+2*NS+NN,1];;M0CKE[I,.];
I=I+1;
ENDO;

I=1;
DO UNTIL I>NXF;
$NAME[I+2*NS+NN+NC,1];;FKE[I,.];
I=I+1;
ENDO;

"-----------------------------------------------------------------------------";
WAIT;
FORMAT 4,4;
"-----------------------------------------------------------------------------";
" ------------------------- PARAMETERIZATION ---------------------------------"
"-----------------------------------------------------------------------------";

/* FILL IN THE PARAMETERS THAT ENTERS INTO YOUR PROBLEM */

"-----------------------------------------------------------------------------";
OUTPUT OFF;