%BENCHPARS  These are benchmark parameters used in 
%
%             Technology Capital and the US Current Account
%             Staff Report 406, by Ellen McGrattan and Edward Prescott
%

%           Ellen McGrattan, 11-15-07
%           Revised, ERM, 1-23-08


%
% Fixed parameters
%
nyr     = 5;           % To find inputs, we sample every nyr years 
alphT   = .23;         % Based on business investment share of GDP 
alphI   = .07;         % Estimate requiring sensitivity check (with deltI)
beta    = .98^nyr;     % Interest rate of 4%
chidu   = 1.0;         % Full expensing at home
chifu   = .0;          % Full expensing at home
deltT   = 1-.94^nyr;   % Based on BEA data
deltM   = 1-.92^nyr;   % Chosen to get xMd/GDPu~=5%, vd/GDPu~=1.5 (see phi)
deltI   = 1-1^nyr;     % Estimate requiring sensitivity check (with alphI)
gamN    = 1.01^nyr-1;  % Growth in population
gamY    = 1.03^nyr-1;  % Growth in output
phi     = .07;         % Chosen to get xMd/GDPu~=5%, vd/GDPu~=1.5 (see deltM)
psi     = 1.32;        % Implies 1/4 to 1/3 time to market work
tauc    = .073;        % Based on US rates 
taul    = .290;        % Based on US rates
b0      = .0;          % Initial debt
sdu0    = .98;         % Initial shares of US companies by US citizens
sfu0    = .01;         % Initial shares of foreign companies by US citizens

%
% Time-varying parameters held fixed 
%
load inputs.dat        % Sampled every 5 years
[nr,nc]= size(inputs);
T0     = nr*5;
if nyr~=5;
  ninp  = zeros(5*nr,nc);
  for i=2:nc;
    ninp(:,i) = interp(inputs(:,i),5);
  end;
  ninp(:,1)   = [inputs(1,1):inputs(1,1)-1+5*nr]';
  inputs      = ninp(1:nyr:5*nr,:);
end;
t       = inputs(:,1);
T       = length(t);
bn      = inputs(:,2)/nyr;
taud    = inputs(:,3);
taupu   = inputs(:,4);
taupr   = inputs(:,5);
Nr      = inputs(:,6);
o       = ones(T,1);
Tran    = 0*o;
lnbu    = .06*o;         
lnbr    = .06*o;
xnbuy   = .154*o;
ynbuy   = .312*o;
xnbry   = .154*o;
ynbry   = .312*o;
Nu      = o;           % Normalization
Nrn     = [Nr(2:T);Nr(T)];
Nun     = [Nu(2:T);Nu(T)];

%
% The inputs to be determined are coefficients in the following relations
%
%   sigu(:) = x(1:nyr:T0),  where x  = a*(1+b*(tanh(c:d:c+d*(T0-1))'-tanh(c)))
%   sigr(:) = a+b*T
%   Adu(:)  = constant
%   Afr(:)  is found by getting exact match to trend in NXu/GNPu
%   sfun(:) is found by getting close match to trend in net PI income/GNPu
%           (because exact match by way of a fixed point solver didn't work)
%
a_sigu  = .69;
b_sigu  = .121;
c_sigu  = -1.5;
d_sigu  = .045;
sigu    = a_sigu*(1+b_sigu*(tanh(c_sigu:d_sigu:c_sigu+d_sigu*(T0-1))'- ...
          tanh(c_sigu)));
sigu    = sigu(1:nyr:T0);
sigr    = linspace(.835,.905,16)';
sfun    =[0.0322
          0.0500
          0.0700
          0.1132
          0.1776
          0.2200
          0.2600
          0.3000
         -0.0500
          0
          0
          0
          0
          0
          0
          0];
rsize   =[2.088253501306908
          2.142015309254713
          2.196155066704058
          2.249978611526425
          2.302986422387568
          2.354162715004282
          2.374669615350235
          2.364090867542559
          2.343602826392401
          2.318665933801904
          2.280832919900716
          2.239908517538884
          2.201886599198790
          2.169101479558619
          2.145657107857909
          2.125840468092870];

if nyr~=5;
  sfun  = interp(sfun,5);
  rsize = interp(rsize,5);
  sfun  = sfun(1:nyr:T0);
  rsize = rsize(1:nyr:T0);
end;
kTdu0   = 1.283023846733930/nyr;
kTdr0   = 0.012818500446457/nyr;
kTfu0   = 0.013567384847818/nyr;
kTfr0   = 0.342219655107459/nyr;
Md0     = 0.523507671860193/nyr;
Mf0     = 1.062636929049698/nyr;
kIdivkT = 0.902499219380348;
Adu0    = 3.354792042258440;
param   = [beta;chidu;chifu;deltT;deltM;deltI;gamN;gamY;phi;psi;
           tauc;taul;alphT;alphI;b0;sdu0;sfu0;T;bn;taud;taupu;taupr;Tran;
           lnbu;lnbr;xnbuy;ynbuy;xnbry;ynbry;Nr;Nu;sigr;sigu;sfun;
           rsize;Adu0;kTdu0;kTdr0;kTfu0;kTfr0;Md0;Mf0;kIdivkT];

%
% Initial guess for solution to first-order conditions in fdifoc.m
%

X=[0.722481963892170
   0.725526490851759
   0.729144697345273
   0.733654750206045
   0.739027036836585
   0.745094340131133
   0.751204040686276
   0.756723033938188
   0.761177729456870
   0.764249379306288
   0.765343798439700
   0.764939501988740
   0.763829830801830
   0.762667915875431
   0.762259225354388
   0.762492010891795
   0.197393458553767
   0.198225271299617
   0.199213822335088
   0.200446039853226
   0.201913833225715
   0.203571516103987
   0.205240782582017
   0.206748658515500
   0.207965751535371
   0.208804974682169
   0.209103987237011
   0.208993527075062
   0.208690347418837
   0.208372893949643
   0.208261233258499
   0.208324833935923
   0.245749691574947
   0.245687961707390
   0.245326875924419
   0.244500286671319
   0.243099371897126
   0.240985923849420
   0.238481853697560
   0.235894131961712
   0.234109647829889
   0.233473026640319
   0.235657662907936
   0.238720513423509
   0.241443276275585
   0.243368955956241
   0.243680458124736
   0.243769207505662
   0.246222922607528
   0.246992768181369
   0.247417153573183
   0.247240747199139
   0.246215993012238
   0.243921120522819
   0.242504500778095
   0.242940262715652
   0.243556621813392
   0.243950829529355
   0.242762656165738
   0.241130927660238
   0.239814421721545
   0.239205935696981
   0.240049745022322
   0.241784657440123
   0.972271155192507
   0.964240576629740
   0.942630176956532
   0.862781246095056
   0.761130292681457
   0.694477183775210
   0.621501254671556
   0.524526856503640
   1.360122575817083
   1.162427737387777
   1.082395392537670
   1.011782730020260
   0.964820260203593
   0.946206614813950
   0.923170631545179
   0.923170631545179
   0.258576881941162
   0.259997252298244
   0.261068637394335
   0.261715828283774
   0.261318802560531
   0.259882914885476
   0.256889195375087
   0.253184602286568
   0.249557462341516
   0.250225151247232
   0.252307732761756
   0.254229210548664
   0.255507884695940
   0.254435673654980
   0.254093468435392
   0.254093468435392
   0.002741951616958
   0.002927724671098
   0.003122992521169
   0.003326174295377
   0.003527291925432
   0.003781909849598
   0.004092082657432
   0.004422065691441
   0.004774443507501
   0.005246627768630
   0.005810240081269
   0.006450261445340
   0.007167886872324
   0.007920037737046
   0.008805254065340
   0.008805254065340
   0.002923030119142
   0.003409501255340
   0.004175148300319
   0.005411156828046
   0.007398297055074
   0.010469176936236
   0.014946913193497
   0.020866093582999
   0.027700922095279
   0.034188034964517
   0.039346606388343
   0.042768733852982
   0.044576764290457
   0.045299833552194
   0.045238070914744
   0.045238070914744
   0.069218616380318
   0.069871389738000
   0.070447939752669
   0.070924859257506
   0.071098034744189
   0.071761649839129
   0.073169431617707
   0.074530949190028
   0.075567965081900
   0.075618065380977
   0.074956523309213
   0.073959335826939
   0.072938788625654
   0.072333815609944
   0.072080485115168
   0.072080485115168
   0.106556372303870
   0.108132343809917
   0.109555552906841
   0.110491949621205
   0.110581789331835
   0.109611851717221
   0.107585319971791
   0.105308023726282
   0.103289405922335
   0.103429711547679
   0.104678978372241
   0.106382679860622
   0.108268945261133
   0.109651048991262
   0.111641048626075
   0.111641048626075
   0.221592773361164
   0.230103825041250
   0.238411567111577
   0.245803884213054
   0.251378466005060
   0.253458737522362
   0.253201126662774
   0.252220051202627
   0.250714368820206
   0.246618253113642
   0.240913826941348
   0.234559923462477
   0.228269884971675
   0.223483727824998
   0.219580467334240
   0.219580467334240];

X0 = zeros(16,11);X0(:)=X;
if nyr~=5;
  nX        = zeros(T,11);
  for i=1:5;
    nX(:,i) = interp(X0(:,i),5);
  end;
  for i=6:11;
    nX(:,i) = interp(X0(:,i),5)*5/nyr;
  end;
  X0        = nX(1:nyr:T,:);
end;
