% Run this file to find the steady state

%This version of find_ss has been modified to allow the declaration of policy instruments as arguments of the
%function. Still, if no policy tools arguments are provided the function will solve the usual version
 
function [x,flag] = find_ss(taxes)

    x0 = abs(randn(1,30));

    %init values: solution with taxes = 0
    x0 = [2.0327    1.8507    1.8507    0.7875    0.9337    0.9337    2.2788    2.5736    2.5736   19.1448   19.6126   19.6126    1.0146 ...
     1.0187    1.0187    6.8523    3.7255    3.7255   15.8871   15.8871   44.0666    1.0101    1.0146    1.0146    2.8237    2.0005 ...
     2.0005    0.0323    0.0206    0.0206];

    x0 = abs(x0);
    tol = 1e-8;
    %options = optimset('Display', 'iter', 'MaxFunEvals', 25000, 'MaxIter', 5000, 'TolFun', tol, 'TolX', tol);
    options = optimoptions('fsolve', 'Display', 'none', 'MaxFunctionEvaluations', 30000, 'MaxIterations', 3500, 'FunctionTolerance', tol, 'StepTolerance', tol);
    %options.Algorithm = 'levenberg-marquardt'; %trust-region-dogleg, trust-region; 'trust-region'; %

    %Declaration of objective function 
    if nargin == 0       %usual SS equations function w/o declaring policy tools as arguments
           obj = 'model_sseqs';
    else %when taxes are provided as arguments
           obj = @(x)model_sseqs(x,taxes); %function that takes 'taxes' as arguments and computes SS
    end

    [x,fval,flag] = fsolve(obj,x0,options); %'MaPCoord_sseqs'
end


%a= ["eq1 = - Lambdac(+1)*R + 1 + eta*Bc;";
%"eq2 = - Lambdaa(+1)*R + 1 + eta*Ba;";
%"eq3 = - Lambdab(+1)*R + 1 + eta*Bb;"]

