Source code for snowdrop.src.preprocessor.f_dynamic
from numba import njit
[docs]
@njit
def f_dynamic(x, p, exog=[0], order=1, ind=None):
### This code was generated by Python.
### Monetary policy model example
# First order derivatives are employed in most of the models to compute Jacobian.
# Higher order derivatives are used in nonlinear rational expectations models.
from scipy.special import lambertw as LambertW
from snowdrop.src.preprocessor.functions import Heaviside,Max,Min,Abs,DiracDelta
from snowdrop.src.preprocessor.condition import IfThenElse,IfThen,Derivative,Subs,Positive,Negative,myzif
import numpy as np
from numpy import exp, sin, cos, tan, sqrt, sign, log
# Initialize variables
_xi_1 = 0
_xi_2 = 0
_xi_3 = 0
PDOT__p1_ = x[0]
PDOT__ = x[4]
RR__ = x[5]
RS__ = x[6]
Y__ = x[7]
PDOT__m1_ = x[8]
RR__m1_ = x[9]
Y__m1_ = x[11]
ey__ = x[12]
err__ = x[13]
ers__ = x[14]
epdot__ = x[15]
# Set parameters
g = p[0]
p_pdot1 = p[1]
p_pdot2 = p[2]
p_pdot3 = p[3]
p_rs1 = p[4]
p_y1 = p[5]
p_y2 = p[6]
p_y3 = p[7]
# Set exogenous variables
exo__ = exog[0]
# Function:
function = np.zeros(4)
function[0] = PDOT__ - (epdot__ + PDOT__m1_*(1 - p_pdot1) + PDOT__p1_*p_pdot1 + p_pdot3*(-g + g**2/(-Y__m1_ + g)) + (-g + g**2/(-Y__ + g))*p_pdot2)
function[1] = RR__ - (RS__ + err__ - PDOT__m1_*(1 - p_pdot1) - PDOT__p1_*p_pdot1)
function[2] = RS__ - (Y__ + ers__ + exo__ + p_rs1*PDOT__)
function[3] = Y__ - (ey__ + p_y1*Y__m1_ - p_y2*RR__ - p_y3*RR__m1_)
if order == 0:
return function
# Jacobian:
jacobian = np.zeros((4,16))
jacobian[0,0] = -p_pdot1
jacobian[0,4] = 1
jacobian[0,7] = -g**2*p_pdot2/(-Y__ + g)**2
jacobian[0,8] = -1 + p_pdot1
jacobian[0,11] = -g**2*p_pdot3/(-Y__m1_ + g)**2
jacobian[0,15] = -1
jacobian[1,0] = p_pdot1
jacobian[1,5] = 1
jacobian[1,6] = -1
jacobian[1,8] = 1 - p_pdot1
jacobian[1,13] = -1
jacobian[2,4] = -p_rs1
jacobian[2,6] = 1
jacobian[2,7] = -1
jacobian[2,14] = -1
jacobian[3,5] = p_y2
jacobian[3,7] = 1
jacobian[3,9] = p_y3
jacobian[3,11] = -p_y1
jacobian[3,12] = -1
if order == 1:
return [function, jacobian]