#! /usr/bin/octave --no-gui
#! ~/octave/RD/Fiscal/newyork235.m
# An Octave program to verify model of firms and bank accounts
# including use of the the Phillips curve for non linearities, 
# as published by Prof Keen, his Model, MonetaryMinsky03  
# Octave Program author Richard A Lough. Published under the GPL License
# ver 101
# This model is a development model, to be used to develop a closer 
# approximation of ponzi financing in New York from 1990 onwards.
# ver 101 is taken from ver01 - upgraded to 5 sectors and international flows
# with code copied from FED02
# ver 235 modelling 2018-2019
# ver 235c modelling 2018-2019 with file output
##############constants and initial conditions ############################ 
# Set up the E matrix, initialise with ones
ME= ones(6,80);
E= ones(1,80); 
########################################################################
######################read the first emperor in#########################
########################################################################
 pkg load general   # the autoload for general is unset usually
 pkg load parallel   # the autoload for parallel is unset usually
 pkg load database   # the autoload for database is unset usually
 conn = pq_connect (setdbopts ("host", "localhost", "dbname", "newyork2", "user", "richard", "password", "whatever"));
####################################################################################

S = pq_exec_params (conn, "select * from ematrix01 where E00='Trump-3';");
j=1; while (j< 70) 
       ME(1,j)= cell2mat(S.data(1,j+1));
#printf ("# 17   =: %8.4f\n", ME(1,j));
j++;
endwhile

S = pq_exec_params (conn, "select * from ematrix02 where E00='Trump-3';");
j=1; while (j< 70) 
       ME(2,j)= cell2mat(S.data(1,j+1));
#printf ("# 17   =: %8.4f\n", ME(2,j));
j++;
endwhile

S = pq_exec_params (conn, "select * from ematrix03 where E00='Trump-3';");
j=1; while (j< 70) 
       ME(3,j)= cell2mat(S.data(1,j+1));
#printf ("# 17   =: %8.4f\n", ME(3,j));
j++;
endwhile

S = pq_exec_params (conn, "select * from ematrix04 where E00='Trump-3';");
j=1; while (j< 70) 
       ME(4,j)= cell2mat(S.data(1,j+1));
#printf ("# 17   =: %8.4f\n", ME(4,j));
j++;
endwhile

S = pq_exec_params (conn, "select * from ematrix05 where E00='Trump-3';");
j=1; while (j< 70) 
       ME(5,j)= cell2mat(S.data(1,j+1));

j++;
endwhile
#printf ("# 17   =: %8.4f\n", ME(4,43));
S = pq_exec_params (conn, "select * from ematrix06 where E00='Trump-3';");
j=1; while (j< 70) 
       ME(6,j)= cell2mat(S.data(1,j+1));
#printf ("# 17   =: %8.4f\n", ME(4,j));
j++;
endwhile
#printf ("# 17   =: %8.4f\n", ME(4,43));

pq_close(conn);

########################################################################
########################################################################
for n = columns(ME);
   for k=1:n
     E(1,k)= ME(1,k);
   endfor
endfor

########################################################################
# Set up the steps per year fr the model (interval)
   interval=120; 
# Set up the X matrix, initialise with ones
  n = 120;
# n = 12;
MX= ones(n,20,6);
X=ones(n,20);
Y=zeros(n,20); # Added for graphic output
Z= ones(n,20);

#X= ones(12,20); # Change this to ones(7202,16) to replicate Keen's model 
#Y=zeros(12,20); # Added for graphic output
#Z= ones(12,20);
#for j = 1: 10      # this loop added to Keen's model for development work
#Minsky = 12/(2+j); # Keen's model had a fixed value of 1.0
Minsky = 0.1;
# Note: writing the following values as a matrix may be more efficient, this is more descriptive

for i=1:6

MX(1,1,i)= 24.56;    # Firms debts 
MX(1,2,i)= 1.91;        # Money in Bank Vault 
MX(1,3,i)= 33.35;     # Firms deposit in banks account 
MX(1,4,i)= 0.7819;         # Bank Capital 
MX(1,5,i)= 0.6220;        # Wages deposited in a Bank account 
MX(1,6,i)= 0.1064;         # Wages =1.0
MX(1,7,i)= 26.81;       # Capital 
MX(1,8,i)= 0.0575;        # Labour productivity conversion factor 
MX(1,9,i)= 1.2911;       # Population (workforce) relative to t=0  
MX(1,10,i)= 2.2864;      # Inflation relative to t=0 
MX(1,11,i)= 0.959;      # Employment ratio
MX(1,12,i)= .1;       # Federal 
MX(1,13,i)= 0.0;       # Government spending pa
MX(1,14,i)= 0.0;       # Government tax revenue pa
MX(1,15,i)= 21.14;      # Treasury Liabilities - Bond sales, government purchases
MX(1,16,i)= 0;      # Primary Bank Treasury Bonds (assets)
MX(1,17,i)= -0;      # Primary Bank Central Liabilities
MX(1,18,i)= 0;      # Central Bank Primary Assets (Treasuries? Government bonds?)

endfor

### set up one overall economy
n= rows(MX);
for i = 1 : n
  for k= 1:20
  X(i,k) = MX(i,k,1); 
  endfor
endfor

########################################################################################


#ME(3,54) = -2;

## Economies Process, Mining, Construction, I+FIRE+P, EHAO 
### set up specific economies 0.341, 0.030, 0.044, 0.422, 0.163.
## sectors are as 2014 values
MX(1,1,2)= MX(1,1,1)*0.341; MX(1,1,3)= MX(1,1,1)*0.030; MX(1,1,4)= MX(1,1,1)*0.044; MX(1,1,5)= MX(1,1,1)*0.422; MX(1,1,6)= MX(1,1,1)*0.163; 
MX(1,2,2)= MX(1,2,1)*0.341; MX(1,2,3)= MX(1,2,1)*0.030; MX(1,2,4)= MX(1,2,1)*0.044; MX(1,2,5)= MX(1,2,1)*0.422; MX(1,2,6)= MX(1,2,1)*0.163;
MX(1,3,2)= MX(1,3,1)*0.341; MX(1,3,3)= MX(1,3,1)*0.030; MX(1,3,4)= MX(1,3,1)*0.044; MX(1,3,5)= MX(1,3,1)*0.422; MX(1,3,6)= MX(1,3,1)*0.163;
MX(1,4,2)= MX(1,4,1)*0.341; MX(1,4,3)= MX(1,4,1)*0.030; MX(1,4,4)= MX(1,4,1)*0.044; MX(1,4,5)= MX(1,4,1)*0.422; MX(1,4,6)= MX(1,4,1)*0.163; 
MX(1,5,2)= MX(1,5,1)*0.341; MX(1,5,3)= MX(1,5,1)*0.030; MX(1,5,4)= MX(1,5,1)*0.044; MX(1,5,5)= MX(1,5,1)*0.422; MX(1,5,6)= MX(1,5,1)*0.163;
MX(1,6,2)= MX(1,6,1);     
MX(1,7,2)= MX(1,7,1)*0.341; MX(1,7,3)= MX(1,7,1)*0.030; MX(1,7,4)= MX(1,7,1)*0.044; MX(1,7,5)= MX(1,7,1)*0.422; MX(1,7,6)= MX(1,7,1)*0.163;
MX(1,8,2)= MX(1,8,1);MX(1,8,3)= MX(1,8,1);MX(1,8,4)= MX(1,8,1);MX(1,8,5)= MX(1,8,1);MX(1,8,6)= MX(1,8,1);
MX(1,9,2)= MX(1,9,1);
MX(1,10,2)= MX(1,10,1);
MX(1,11,2)= MX(1,11,1);
MX(1,12,2)= 0.1*0.341; MX(1,12,3)= 0.1*0.030; MX(1,12,4)= 0.1*0.044;MX(1,12,5)= 0.1*0.422;MX(1,12,6)= 0.1*0.163;
MX(1,13,2)= 0.0*0.341; MX(1,13,3)= 0.0*0.030; MX(1,13,4)= 0.0*0.044;MX(1,13,5)= 0.0*0.422;MX(1,13,6)= 0.0*0.163;
MX(1,14,2)= 0.0*0.341; MX(1,14,3)= 0.0*0.030; MX(1,14,4)= 0.0*0.044;MX(1,14,5)= 0.0*0.422;MX(1,14,6)= 0.0*0.163;
MX(1,15,2)= MX(1,15,1)*0.341;MX(1,15,3)=MX(1,15,1)*0.030;MX(1,15,4)=MX(1,15,1)*0.044;MX(1,15,5)=MX(1,15,1)*0.422;MX(1,15,6)=MX(1,15,1)*0.163;
MX(1,16,2)= -0*0.341; MX(1,16,3)= -0*0.030;MX(1,16,4)= -0*0.044;MX(1,16,5)= -0*0.422;MX(1,16,6)= -0*0.163;
MX(1,17,2)= -0*0.341; MX(1,17,3)= -0*0.030;MX(1,17,4)= -0*0.044;MX(1,17,5)= -0*0.422;MX(1,17,6)= -0*0.163;
MX(1,18,2)= -0*0.341; MX(1,18,3)= -0*0.030;MX(1,18,4)= -0*0.044;MX(1,18,5)= -0*0.422;MX(1,18,6)= -0*0.163;



#printf ("# 17   =: %8.4f\n", ME(4,43));

###############################################################################
################ main loop starts here ########################################
###############################################################################
# loop through the desired range of time, say 100 years at tenths of months 

t= 1/interval;

function Xdot = increment (X, Minsky,E)
  Yr = X(:,7)./ E(1,5) ;
dummy1 = +E(1,44)*X(:,15)/E(1,59)+E(1,42)+(E(1,48))*X(:,10)/E(1,47)-(E(1,43)+E(1,55))*Yr*X(:,10)/E(1,59)+E(1,49)*(-E(1,50)-1/E(1,51))/E(1,59); 
  L  = Yr./ X(:,8);
  Ph = (E(1,23)-E(1,25)).*exp((X(:,11)-E(1,22)).*E(1,24)./(E(1,23)-E(1,25))) +E(1,25); # Rate of change of wages
  PIr= (Yr.*X(:,10)+E(1,2).*X(:,3)-X(:,6).*L-E(1,1).*X(:,1)+E(1,44).*X(:,15)+E(1,56)*(E(1,54)+E(1,42))*E(1,59)+(E(1,48)*E(1,59)).*X(:,10)./E(1,47)+(E(1,52)-E(1,43)).*Yr.*X(:,10)+E(1,45)*E(1,59))./( E(1,5).*X(:,10).*Yr); 
  Inv = (E(1,27)-E(1,29)).*exp((PIr-E(1,26)).*E(1,28)./(E(1,27)-E(1,29)))+E(1,29);
  E(1,7)= Inv./E(1,5)-E(1,14);
  Taurl = (E(1,31)-E(1,33)).*exp((PIr-E(1,30)).*E(1,32)/(E(1,31)-E(1,33)))+E(1,33); # Firms time lag
  Taulc = (E(1,35)-E(1,37)).*exp((PIr-E(1,34)).*E(1,36)/(E(1,35)-E(1,37)))+E(1,37); # Bank (Capital or Vault) time lag
  Pricedot = (X(6)/(X(8)*(1-E(1,4)) -E(1,56)*E(1,54)*E(1,59)/L)-X(10))/E(1,16);
#  Torpw = (E(1,39)-E(1,41)).*exp((((X(:,6)./(X(:,8).*(1-E(1,4)))-X(:,10))./E(1,16))-E(1,38)).*E(1,40)./(E(1,39)-E(1,41)))+E(1,41); # lag between prices and wages
   Torpw = (Pricedot*8+0.04);
 if (Torpw < 0.35) Torpw = 0.35; endif;
  if (Torpw > 0.6) Torpw = 0.6; endif; 
if (X(:,6)<0) X(:,6)=0; endif;
  ## Start simply and add components to understand the effects 
  Xdot = [(-X(1) / Taurl + X(2) / Taulc + X(10) * Yr * Inv * Minsky );             # Firms Loan
   	  (X(1)/Taurl-X(2)/Taulc+E(1,49)*E(1,59)*(-E(1,50)-1/E(1,51)));                 # Bank Vault 
	  (-X(1)*(E(1,1)+1/Taurl)+X(2)/Taulc+E(1,2)*X(3)+X(4)/E(1,17)+X(5)/E(1,15)-X(6)*L+X(10)*(Yr*(Inv*Minsky+E(1,52)-E(1,43))+E(1,48)*E(1,59)/E(1,47))+E(1,42)*E(1,59)); # Firms Deposit
          (E(1,1)*X(1)-E(1,2)*X(3)-X(4)/E(1,17)-E(1,2)*X(5)); # Bank Capital
          (+(E(1,2)-1/E(1,15))*X(5)+X(6)*L ); # Workers Deposit 
          ((Ph+E(1,3)*(E(1,7)-(E(1,12)+E(1,13)))+(X(6)/(X(10)*X(8)*(1-E(1,4)))-1)*Torpw)*X(6)); # Wages 
          (X(7)*E(1,7)-X(7)/E(1,21)-E(1,53)); # Capital
          (E(1,12)*X(8)); # Rate of labour productivity growth
          (E(1,13)*X(9)); # Rate of population growth
 	  (Pricedot);     # change of Price Level (inflation)
         (X(11)*(E(1,7)-(E(1,12)+E(1,13)))); # change of employment Ld(t)
	  (-E(1,45)*E(1,59)+ E(1,46)*E(1,59)-E(1,52)*Yr*X(10));                   # Federal transactions
          (-E(1,42)*E(1,59)+(- E(1,48)*E(1,59))*X(10)/ E(1,47)-E(44)*X(15));      # government spending
	  (E(1,43)*Yr*X(10)); # government tax revenue
	  (+E(1,44)*X(15)+E(1,42)*E(1,59)+(E(1,48)*E(1,59))*X(10)/E(1,47)-(E(1,43)+E(1,55))*Yr*X(10)+E(1,49)*E(1,59)*(-E(1,50)-1/E(1,51))); # Treasury A/C Debt - excludes Federal contribution
	  (+dummy1); # Primary dealers Treasury Assets
	  (-dummy1); # Primary dealers Central Bank Liabilities
	  (dummy1)].' ; # Central bank Primary assets
endfunction

function Q = postprocess (X, Minsky,E)
 
  Yr = X(:, 7) ./ E(1,5); 
  L  = Yr ./ X(:, 8); 
  II = X(:, 11);
  
  Ph = (E(1,23)-E(1,25)) .*exp((II-E(1,22)).*E(1,24) ./(E(1,23)-E(1,25))) +E(1,25); # Rate of change of wages
  if (X(:, 10) < 0.001) PIr = 0; else 
  PIr= (Yr .* X(:, 10) + E(1,2) .* X(:, 3) - X(:, 6) .* L - E(1,1) .* X(:, 1)) ./ (E(1,5) .* X(:, 10) .* Yr); 
# if (X(:, 10) = 0) PIr = 0;
   endif;
  Inv = (E(1,27)-E(1,29)) .*exp((PIr-E(1,26)) .*E(1,28) ./(E(1,27)-E(1,29))) +E(1,29);
  g     = Inv ./ E(1,5) - E(1,14); 
  Taurl = (E(1,31)-E(1,33)) .*exp((PIr-E(1,30)) .*E(1,32) ./(E(1,31)-E(1,33))) +E(1,33); # Firms time lag
  Taulc = (E(1,35)-E(1,37)) .*exp((PIr-E(1,34)) .*E(1,36) ./(E(1,35)-E(1,37))) +E(1,37); # Bank (Capital or Vault) time lag
    z= 0.000001 + Inv ./E(1,5);
  
  ## Some things that need watching 
  Q = [((X(:, 6) ./ (X(:, 11) .* X(:, 8) .* (1 - E(1,4))) - 1) ./ E(1,16)), Yr ];

# X17 - part of wages calculation
# X18 z - investment including maintenance costs 

endfunction

incfun = @(XX, Minsky,E) increment (XX,Minsky,E);

postfun = @(XX, Minsky) postprocess (XX,Minsky,E);
  
function X = main_loop (X, t,Minsky, incfun, MX, ME)
  n = rows (MX);
  for i = 2 : n
    for k = 1:6
      q=columns(ME)
     for m = 1:q
    E(1,m) = ME(k,m); 
     endfor
     for l =i-1 : i
      for m= 1:18
      X(l,m) = MX(l,m,k); 
      endfor
     endfor
    ##Still in the k loop
    ##Start with wages X6
     if k==6 
	a=2;b=3;c=4;d=5;
     endif
     if k==5 
	a=2;b=3;c=4;d=6;
     endif
     if k==4 
	a=2;b=3;c=5;d=6;
     endif
     if k==3 
	a=2;b=4;c=5;d=6;
     endif
     if k==2 
	a=3;b=4;c=5;d=6;
     endif
# use inter as a temporary store for transferred intermediate goods
	inter = MX(i-1,7,k)/(MX(i-1,8,k)*ME(1,5)); # =L
     if k==1
       inter = inter*MX(i-1,6,k); # plain vanilla (L * wage rate)
     else
# X60+ is the wages coefficient  
       inter = -(ME(a,(60+k))+ME(b,(60+k))+ME(c,(60+k))+ME(d,(60+k)))*MX(i-1,3,k)*(ME(k,4)-1)/ME(k,61)+ME(k,(60+a))*MX(i-1,3,a)*(ME(a,4)-1)/ME(a,61)+ME(k,(60+b))*MX(i-1,3,b)*(ME(b,4)-1)/ME(b,61)+ME(k,(60+c))*MX(i-1,3,c)*(ME(c,4)-1)/ME(c,61)+ME(k,(60+d))*MX(i-1,3,d)*(ME(d,4)-1)/ME(d,61);
inter = inter -MX(i-1,3,k)*(1/ME(k,70+a)+1/ME(k,70+b)+1/ME(k,70+c)+1/ME(k,70+d))+MX(i-1,3,a)/ME(a,70+k)+MX(i-1,3,b)/ME(b,70+k)+MX(i-1,3,c)/ME(c,70+k)+MX(i-1,3,d)/ME(d,70+k);
     endif
# adjust for intermediate goods
X(i-1,3)= X(i-1,3) +0.0*inter/120;
##Increment the X variables by one step in time
     X(i,1:18) = X(i-1,1:18) + t * incfun (X(i-1,1:18),Minsky, E); 
        
     for l = i-1 : i
      for m= 1:18
      MX(l,m,k) = X(l,m);
      endfor
     endfor
    endfor
#sum some variables, average others
    MX(i,1,1) = (MX(i,1,2)+MX(i,1,3)+MX(i,1,4)+MX(i,1,5)+MX(i,1,6))/1;
    MX(i,2,1) = (MX(i,2,2)+MX(i,2,3)+MX(i,2,4)+MX(i,2,5)+MX(i,2,6))/1;
    MX(i,3,1) = (MX(i,3,2)+MX(i,3,3)+MX(i,3,4)+MX(i,3,5)+MX(i,3,6))/1;
    MX(i,4,1) = (MX(i,4,2)+MX(i,4,3)+MX(i,4,4)+MX(i,4,5)+MX(i,4,6))/1;
    MX(i,5,1) = (MX(i,5,2)+MX(i,5,3)+MX(i,5,4)+MX(i,5,5)+MX(i,5,6))/1;
    MX(i,6,1) = (MX(i,6,2)*0.341+MX(i,6,3)*0.030+MX(i,6,4)*0.044+MX(i,6,5)*0.422+MX(i,6,6)*0.163)/1;
    MX(i,7,1) = (MX(i,7,2)+MX(i,7,3)+MX(i,7,4)+MX(i,7,5)+MX(i,7,6))/1;
    MX(i,8,1) = (MX(i,8,2)*0.341+MX(i,8,3)*0.030+MX(i,8,4)*0.044+MX(i,8,5)*0.422+MX(i,8,6)*0.163)/1;
    MX(i,9,1) = (MX(i,9,2)*0.341+MX(i,9,3)*0.030+MX(i,9,4)*0.044+MX(i,9,5)*0.422+MX(i,9,6)*0.163)/1;
    MX(i,10,1) = (MX(i,10,2)*0.341+MX(i,10,3)*0.030+MX(i,10,4)*0.044+MX(i,10,5)*0.422+MX(i,10,6)*0.163)/1;
    MX(i,11,1) = (MX(i,11,2)*0.341+MX(i,11,3)*0.030+MX(i,11,4)*0.044+MX(i,11,5)*0.422+MX(i,11,6)*0.163)/1;
    MX(i,12,1) = (MX(i,12,2)+MX(i,12,3)+MX(i,12,4)+MX(i,12,5)+MX(i,12,6))/1;
    MX(i,13,1) = (MX(i,13,2)+MX(i,13,3)+MX(i,13,4)+MX(i,13,5)+MX(i,13,6))/1;
    MX(i,14,1) = (MX(i,14,2)+MX(i,14,3)+MX(i,14,4)+MX(i,14,5)+MX(i,14,6))/1;
    MX(i,15,1) = (MX(i,15,2)+MX(i,15,3)+MX(i,15,4)+MX(i,15,5)+MX(i,15,6))/1;
    MX(i,16,1) = (MX(i,16,2)+MX(i,16,3)+MX(i,16,4)+MX(i,16,5)+MX(i,16,6))/1;
    MX(i,17,1) = (MX(i,17,2)+MX(i,17,3)+MX(i,17,4)+MX(i,17,5)+MX(i,17,6))/1;
    MX(i,18,1) = (MX(i,18,2)+MX(i,18,3)+MX(i,18,4)+MX(i,18,5)+MX(i,18,6))/1;
  endfor 
  for i = 2 : n
# note : change k to select final figures for each sector 
    for k = 1:1
	l = i;
      for m= 1:18
	X(l,m) = MX(l,m,k);
      endfor
    endfor
  endfor
endfunction

Minsky = 12 ./ (89 + (1:4)'); # Keen's model had a fixed value of 1.0 now reduced x10

## main loop starts here
## parallel version needs the package "general"
ncpus = 1;
X = pararrayfun (ncpus, @(M) main_loop (X(:, 1:18), t, M, incfun,MX,ME), Minsky, 'UniformOutput', false);
Z = parcellfun (ncpus, @(XX, M) postfun (XX, M), X, mat2cell (ones (4, 1), ones (4, 1)), 'UniformOutput', false);
Y = cellfun (@(XX) XX(:,10), X, 'UniformOutput', false);
Y = [Y{:}];
X = ([X{end}(:, 1:18) ones(rows (X{end}), 1) Z{end}]);

## serial version with arrayfun/cellfun
#X = arrayfun (@(M) main_loop (X(:, 1:18), t, M, incfun,MX,ME), Minsky, 'UniformOutput', false);
#Z = cellfun (@(XX, M) postfun (XX, M), X, mat2cell (ones (4, 1), ones (4, 1)), 'UniformOutput', false);
#Y = cellfun (@(XX) XX(:, 3), X, 'UniformOutput', false);
#Y = [Y{:}];
#X = ([X{end}(:, 1:18) ones(rows (X{end}), 1) Z{end}]);

#for j = 1:10  # this loop added to Keen's model for development work
# serial version with outer loop
#X(:, 1:18)  =  main_loop (X(:, 1:18), t, Minsky(j), incfun,MX,ME);
#X(:, 19,20) =  postfun (X(:, 1:18), Minsky(j));
#Y(:, j) = X(1:end-0, 4); # Note : is 0 (vs 1) a bug or a feature? <<<<<<<<<<<<<<<<<<<<<<<<
#endfor 

h = rows (X) - 1;
printf ("# Firms Loan: %8.4f\n",                        X(h, 1));
printf ("# Bank Vault: %8.4f\n",                        X(h, 2));
printf ("# Firms Deposit: %8.4f\n",                     X(h, 3));
printf ("# Bank Capital: %8.4f\n",                      X(h, 4));
printf ("# Workers Deposit: %8.4f\n",                   X(h, 5));
printf ("# wage : %8.4f\n",                             X(h, 6));
printf ("# Capital = : %8.4f\n",                        X(h, 7));
printf ("# Alpha = : %8.4f\n",                          X(h, 8));
printf ("# Beta =: %8.4f\n",                            X(h, 9));
printf ("# change of Price Level (inflation): %8.4f\n", X(h, 10));
printf ("# Employment ratio : %8.4f\n",                 X(h, 11));
printf ("# 12 Federal   =: %8.4f\n",                    X(h, 12));
printf ("# 13 Government spending   =: %8.4f\n",        X(h, 13));
printf ("# 14 Government tax revenue  =: %8.4f\n",      X(h, 14));
printf ("# 15 Government Debt  =: %8.4f\n",             X(h, 15));
printf ("# 16   =: %8.4f\n",                            X(h, 16));
printf ("# 17   =: %8.4f\n",                            X(h, 17));
#printf ("%8.4f, %8.4f, %8.4f,%8.4f, %8.4f, %8.4f,%8.4f, %8.4f, %8.4f,%8.4f, %8.4f, %8.4f\n", X);
#
ax = plot(Y);

#W = ones (n,2);
#for i = 1:n
#W(i,1) = 2017+i/120;
#W(i,2) = X(i,10);
#endfor
#save /home/richard/octave/RD/Fiscal/NewYork2/myfile.mat W;
#save ./myfile.mat W;

#W = ones (20,1);
#for i =1 : 20
#W(i,1) = X(h,i);
#endfor;
#save /home/richard/octave/RD/Fiscal/NewYork2/myfile.mat W;



#ax = plotyy (X, Y, X, Z, @plot);
# xlabel ("Year");
#ylabel (ax(2), "Costs pa"); 
#ylabel ( "Costs pa");
############################################################################################ 
##################### figures for newyork232c modelling 2017-2018
# Final results: a reasonable approximation for the US economy 2017-2018 (1 year)
###########################################################
# Firms Loan:  24.5599
# Bank Vault:   1.9090
# Firms Deposit:  33.3539
# Bank Capital:   0.7819
# Workers Deposit:   0.6220
# wage :   0.1040
# Capital = :  26.8091
# Alpha = :   0.0574
# Beta =:   1.2911
# change of Price Level (inflation):   2.2864
# Employment ratio :   0.9590
# 12 Federal   =:   0.1000
# 13 Government spending   =:  -4.8090
# 14 Government tax revenue  =:   3.4746
# 15 Government Debt  =:  21.1444
# 16   =:   6.6720
# 17   =:  -6.6720
#! End~/octave/RD/Fiscal/newyork234.m

