
% Provides steady state values to dynamic problem solver
%function [ys,check] = dyn_main_steadystate(ys,exe) %#ok<INUSD> FOR DYNARE
%4.5.x (any version before 4.6.x)
function [ys,param,check] = dyn_main_steadystate(ys,exo,M_,options)
        %function [ys,params,check] =
        %NK_baseline_steadystate(ys,exo,M_,options_) is an example in https://git.dynare.org/Dynare/dynare/-/wikis/BreakingFeaturesIn4.6

  % global M_ %newss NEEDED FOR DYNARE 4.5.X
  
  
  par = cell2struct(...
        num2cell(M_.params),...
        cellstr(M_.param_names)...
        );
      
  alfH = par.alfH;
  alfF = par.alfF;
  bet  = par.bet;
  nu   = par.nu;
  tau  = par.tau;

  % Initial guess
   %     X0 = [0.34; 0.34; 0.02; 0.02; 1.8; 1.8];
 X0 = [0.34; 0.34; 1; 1; 2.5; 2.5]; %last used by Diego

  
  options = optimset('fsolve');
  options = optimset(options,'Display','off');
  X  = fsolve(@(X) dyn_det(X),X0,options);
  
  nH = X(1);
  nF = X(2);
  xH = X(3);
  xF = X(4);
  wH = X(5);
  wF = X(6);

  [cH YH WH qH pH dH mH yH lHy lHq IH UcH kH RH ...
   cF YF WF qF pF dF mF yF lFy lFq IF UcF kF RF] = sseqs(X);

    bH  = 0;
    bF  = 0;  

    r   = bet;
    
    zH = 1; 
    zF = 1; 
    
  % Terms of trade
    totH = 1;
    totF = 1;
    
  % Price index (P)
    PH = 1; %(alfH*IH*pH^nu + (1-alfH)*IF*tau*pF^nu)^(1/nu);
    PF = 1; %(alfF*IF*pF^nu + (1-alfF)*IH*tau*pH^nu)^(1/nu);
  
  % Real exchange rate
    rerH = PF./PH;
    rerF = PH./PF;
    
  % Exports
    exH = tau*IH.*mF.*pH;
    exF = tau*IF.*mH.*pF;
    
  % GDP
    gdpH = YH + exH - exF;
    gdpF = YF + exF - exH;
    
  % Net exports
    nxH = (exH-exF)./gdpH;
    nxF = (exF-exH)./gdpF;
    
  % Measured aggregates (coincide in ss)
    mYH = YH;
    mYF = YF;
    mcH = cH;
    mcF = cF;
    mxH = xH;
    mxF = xF;
    
  % Relative output (RY)
    RYH = gdpH./gdpF;
    RYF = gdpF./gdpH;
    
  % Relative consumption (RC)
    RCH = mcH./mcF;
    RCF = mcF./mcH;
    
  % Quality adjusted variables
    qadjH = 1;
    qYH   = YH;
    qcH   = cH;
    qxH   = xH;
    qtotH = totH;
    qPH   = PH;
    qrerH = rerH;
    qexH  = exH;
    qgdpH = gdpH;
    qnxH  = nxH;
    qRYH  = RYH;
    qRCH  = RCH;
    qadjF = 1;
    qYF   = YF;
    qcF   = cF;
    qxF   = xF;
    qtotF = totF;
    qPF   = PF;
    qrerF = rerF;
    qexF  = exF;
    qgdpF = gdpF;
    qnxF  = nxF;
    qRYF  = RYF;
    qRCF  = RCF;
    

  ys = [r cH YH WH qH pH dH mH yH lHy lHq IH UcH nH xH kH RH bH wH zH mYH mcH mxH totH PH rerH exH gdpH nxH RYH RCH qadjH qYH qcH qxH qtotH qPH qrerH qexH qgdpH qnxH qRYH qRCH ...
          cF YF WF qF pF dF mF yF lFy lFq IF UcF nF xF kF RF bF wF zF mYF mcF mxF totF PF rerF exF gdpF nxF RYF RCF qadjF qYF qcF qxF qtotF qPF qrerF qexF qgdpF qnxF qRYF qRCF]';

  check = 0;

end

