Skip to content
This repository has been archived by the owner. It is now read-only.

Check detrending engine #1389

Open
JohannesPfeifer opened this issue Feb 5, 2017 · 10 comments

Comments

Projects
None yet
2 participants
@JohannesPfeifer
Copy link
Contributor

commented Feb 5, 2017

The mod-file


//-----------------------------------------------------------------------//
//---------------------- Declaring parameters ---------------------------//
//-----------------------------------------------------------------------//
parameters  delta	//depreciation
            sigma	//intertemporal elasticity
            beta	//discount factor
            alpha   //production function parameter
	        mu      //utility parameter
            theta   //Calvo parameter
            epsilon //elasticity
            chi     //indexation parameter (unused for now)
            ;

            alpha = 0.667;
            delta = 0.1;
            sigma = 0.25;
            beta = 0.96;
            mu = 0.2;
            theta = 0.5;
            epsilon = 15;
            chi = 0;

//-----------------------------------------------------------------------//
//----------------------- Declaring variables ---------------------------//
//-----------------------------------------------------------------------//
varexo omega //probability of remaining a worker in the next period
       gamma //probability of dieing (once retired)
       n     //populational growth
       x     //rate of technological change
       M_d   //exogenous money supply
       ;

var lambda      //asset distribution in the economy
    pi          //}these define the marginal propensity of consumption
    eps         //}by both retirees and workers (I'm using Gertler's notation)
    OMEGA       //higher case omega
    R           //gross interest rate
    PSI         //auxiliar variable
    mc          //marginal cost
    Pi          //inflation
    Df          //nominal dividends
    Pf          //nominal firm share price
    price_disp  //price dispersion index
    ;

//declaring nonstationary variables
trend_var(growth_factor= (1+x)*(1+n)/(1+n)) X; //technological progress
trend_var(growth_factor= (1+x)*(1+n)/(1+x)) N; //population

var(deflator = X*N)
                    Y            //product
                    C            //consumption
                    K            //financial capital
                    H            //non-financial capital
                    A            //assets
                    ;

var(deflator = X) W;             //real wage
var(deflator = 1/(X*N)) P PStar; //price level and optimal price set

var(deflator = (X*N)^(1-epsilon)) g1; //auxiliary Calvo variable
var(deflator = (X*N)^(2-epsilon)) g2; //auxiliary Calvo variable

predetermined_variables K; //timing convention

//-----------------------------------------------------------------------//
//------------------------------- Model ---------------------------------//
//-----------------------------------------------------------------------//

model;
    // Consumer side
    //1
    K(+1) = Y - C + (1 - delta)* K;
    //2
    (lambda - (1 - omega(+1)))*A = omega(+1)*(1-eps*pi)*lambda(-1)*R*A(-1);
    //3
    pi = 1 - PSI(+1) * (R(+1) * OMEGA(+1))^(sigma - 1) * beta^sigma * pi/pi(+1);
    //4
    eps * pi = 1 - PSI(+1) * ((R(+1))^(sigma-1)*beta^sigma*gamma(+1))*(eps*pi)/(eps(+1)*pi(+1));
    //5
    OMEGA = omega + (1-omega)*eps^(1/(1-sigma));
    //6
    H = N * W + H(+1)/((1+n(+1))*(1+x(+1))*R(+1)*OMEGA(+1)/omega(+1));
    //7
    C * (1 + mu^sigma * (R(+1)*Pi(+1)/(R(+1)*Pi(+1)-1))^(sigma-1)) = pi * ((1 + (eps/gamma-1) * lambda(-1)) * R * A(-1) + H(-1)); 
    //8  
    A = K + 1/R * M_d(+1)/P + Pf/P;
    //9
	PSI = (1 + ((R*Pi-1)/(R*Pi))^(sigma-1) * mu^sigma)^(-1) / (1 + (((R(+1)*Pi(+1))-1)/(R(+1)*Pi(+1)))^(sigma-1) * mu^sigma)^(-1);

    // Firm side
    //10	
    Y = (X * N)^alpha * (K)^(1-alpha)/price_disp;
    //11
    W = alpha * Y / N * mc;
    //12
    R = (1 - alpha) * Y / K * mc + 1 - delta; 
    //13
    mc = (1/(1-alpha))^(1-alpha)*(1/alpha)^alpha*(W/X)^(1-alpha)*(R-(1-delta))^alpha;
    
    // Calvo pricing
    //14
    PStar = epsilon/(epsilon-1) * g1/g2;
    //15
    g1 = P^epsilon * Y * mc + theta*beta * g1(+1);
    //16
    g2 = P^(epsilon-1) * Y + theta*beta * g2(+1);
    //17
    P = (theta * P(-1)^(1-epsilon) + (1-theta) * PStar^(1-epsilon))^(1/(1-epsilon));
    //18
    price_disp = theta*(PStar/P)^(-epsilon)*(P/P(-1))^(epsilon) + (1-theta)*(P/P(-1))^(epsilon)*price_disp(-1);
    //19
    Pi = P/P(-1);

    // Dividends and share prices
    Df = P * Y *(1-mc);
    Pf(+1) + Df(+1) = R(+1) * Pf;
end;

//-----------------------------------------------------------------------//
//--------------------------- Initial Values ----------------------------//
//-----------------------------------------------------------------------//

initval;
    M_d = 1; P =1;
    x = 0.01;
    n = 0.01;
    omega = 0.97;
    gamma = 0.9;
    
    lambda    =0.3878;
    pi        =0.2394;
    eps       =1.2832;
    OMEGA     =1.0124;
    R         =1.3968;
    PSI       =0.9988;
    mc        =0.9064;
    Y         =0.7407;
    C         =0.6857;
    K         =0.459;
    H         =1.4279;
    A         =1.365;
    P         =0.972;
    PStar     =0.9364;
    W         =0.448;
    Pi        =0.98;
    Df        =0.0681;
    Pf        =0.1732;
    price_disp=1.0336;
    g1        =0.601;
    g2        =0.6877;


end;
model_diagnostics;
steady;

endval;
    gamma = 0.94;
end;
steady;

simul(periods=300);

from http://www.dynare.org/phpBB3/viewtopic.php?f=1&t=14206 does not run with

ERROR: the second-order cross partial of equation 14 w.r.t. trend variable X and endogenous variable PStar is not null. 

but the relevant equation

    PStar = epsilon/(epsilon-1) * g1/g2;

should have the trends specified (as far as I can see). g1/g2=((X*N)^(1-epsilon))/((X*N)^(2-epsilon)=(XN)^(-1), which is the trend for PStar.

@houtanb houtanb self-assigned this Feb 6, 2017

@houtanb houtanb added this to the 4.5 milestone Feb 6, 2017

@JohannesPfeifer

This comment has been minimized.

Copy link
Contributor Author

commented Mar 10, 2017

@houtanb You assigned a bug label here. Did you already find out what is going on?

@houtanb

This comment has been minimized.

Copy link
Member

commented Mar 10, 2017

@houtanb

This comment has been minimized.

Copy link
Member

commented Apr 10, 2017

@JohannesPfeifer I don't see the error. If you agree with the following, I'll close the ticket.

The detrended equation being tested is (too many parenthesis because this output is rough code I wrote for debugging purposes):

(((1/(X*N))*PStar)-(((epsilon/(epsilon-1))*(((X*N)^(1-epsilon))*g1))/(((X*N)^(2-epsilon))*g2)))

The log of said equation:

log((((1/(X*N))*PStar)-(((epsilon/(epsilon-1))*(((X*N)^(1-epsilon))*g1))/(((X*N)^(2-epsilon))*g2))))

The first derivative wrt X:

(((PStar*(-(N)/((X*N)*(X*N))))-((((((X*N)^(2-epsilon))*g2)*((epsilon/(epsilon-1))*(g1*(N*power_deriv((X*N),(1-epsilon))))))-(((epsilon/(epsilon-1))*(((X*N)^(1-epsilon))*g1))*(g2*(N*power_deriv((X*N),(2-epsilon))))))/((((X*N)^(2-epsilon))*g2)*(((X*N)^(2-epsilon))*g2))))/(((1/(X*N))*PStar)-(((epsilon/(epsilon-1))*(((X*N)^(1-epsilon))*g1))/(((X*N)^(2-epsilon))*g2))))

The nonzero second derivative wrt Pstar:

((((-(N)/((X*N)*(X*N)))*(((1/(X*N))*PStar)-(((epsilon/(epsilon-1))*(((X*N)^(1-epsilon))*g1))/(((X*N)^(2-epsilon))*g2))))-((1/(X*N))*((PStar*(-(N)/((X*N)*(X*N))))-((((((X*N)^(2-epsilon))*g2)*((epsilon/(epsilon-1))*(g1*(N*power_deriv((X*N),(1-epsilon))))))-(((epsilon/(epsilon-1))*(((X*N)^(1-epsilon))*g1))*(g2*(N*power_deriv((X*N),(2-epsilon))))))/((((X*N)^(2-epsilon))*g2)*(((X*N)^(2-epsilon))*g2))))))/((((1/(X*N))*PStar)-(((epsilon/(epsilon-1))*(((X*N)^(1-epsilon))*g1))/(((X*N)^(2-epsilon))*g2)))*(((1/(X*N))*PStar)-(((epsilon/(epsilon-1))*(((X*N)^(1-epsilon))*g1))/(((X*N)^(2-epsilon))*g2)))))

NB: The function that does the test is DynamicModel::testTrendDerivativesEqualToZero in preprocessor/DynamicModel.cc.

@houtanb

This comment has been minimized.

Copy link
Member

commented Apr 13, 2017

From an email from @JohannesPfeifer dated 10 April 2017

What exactly is the logic behind the tests we are conducting? It seems we always take the log of an equation and then the derivative. But is this always correct? Say we have an equation
f(x,A)=g(x,A)
where A is the trend that grows over time. If A is multiplicative, then we should be able to write
A^b*f(x,1)=A^b*g(x,1)
Where b is some exponent involved in the equation. When taking the log, the trend A becomes additively separable and all cross-derivatives will drop out. This seems valid, except for the problem that we were taking log of
f(x,A)-g(x,A)=0
which can create problems because of the asymptote at 0.

However, Houtan’s change broke the fs2000_log_nonstationary.mod. But here the trend is additive:
f(x,A)=g(x,A)
can be written as
A+f(x,1)=A+b*g(x,1)
This expression is already additively separable and a test would involve testing whether the cross-derivatives w.r.t. to A are 0. But we again take the logs
Log(A+f(x,1))=log(A+b*g(x,1))
And then check the cross-derivatives. In this case, the log does introduce a non-separability. Could it be that we need to distinguish between additive and multiplicative trends?

@houtanb houtanb added the decision label Apr 13, 2017

@houtanb

This comment has been minimized.

Copy link
Member

commented Apr 20, 2017

With @stepan-a we decided to fix this in 4.6. But, for the 4.5 release, since we agree there is a problem with the test, we will change the error message to a warning and allow processing to continue.

@houtanb houtanb modified the milestones: 4.6, 4.5 Apr 20, 2017

@JohannesPfeifer

This comment has been minimized.

Copy link
Contributor Author

commented Apr 20, 2017

@houtanb @stepan-a Fine with me. But do we already have a problem diagnosis?

@houtanb

This comment has been minimized.

Copy link
Member

commented Apr 21, 2017

@JohannesPfeifer just that the test is not correct...

@JohannesPfeifer

This comment has been minimized.

Copy link
Contributor Author

commented Apr 21, 2017

@houtanb But in which cases? And what is the mistake in the test?

@houtanb

This comment has been minimized.

Copy link
Member

commented Apr 21, 2017

@JohannesPfeifer we have not gotten that far. Only that this change can wait until 4.6 and we want to make 4.5 soon. Since we know that in some situations it's not correct, we left the warning but removed the exit so that processing can continue.

@JohannesPfeifer

This comment has been minimized.

Copy link
Contributor Author

commented Apr 27, 2017

The logic of the test is described in http://www.dynare.org/DynareWiki/RemovingTrends

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.