Exemplo n.º 1
0
#------------------------------------------------------------------------------------------------------
#Simulate
# generate a history of Z's
T = 1000  # number of observations to generate
# initialize Z
zhist = np.zeros((T,1))
# generate a history of epsilon shocks with mean zero and variance sigma-squared
epshist = np.random.randn(T,1)*sigma
# iteratively generate Z's starting with the first value of Z = 0
for t in range (1,T):
    zhist[t,:] = abs(rho*zhist[t-1,:] + epshist[t,:])
# generate a history of k's
kbar2 = np.array([[kbar]])
takelogs = False
khist, temp = LinApp_SSL(kbar2, zhist, kbar2, takelogs, PP, QQ, RR, SS)
# initialize histories of all other variables
yhist = np.zeros(T)
rhist = np.zeros(T)
whist = np.zeros(T)
chist = np.zeros(T)
ihist = np.zeros(T)
uhist = np.zeros(T)
# set initial values noting we started at the steady state
#Ybar, wbar, rbar, cbar, ubar
yhist[0] = Ybar
rhist[0] = rbar
whist[0] = wbar
chist[0] = cbar
uhist[0] = ubar
# compute values for all other time periods
Exemplo n.º 2
0
# uncomment for simulation
eps = sig * np.random.randn(nobs, nz)
# uncomment for IRF
# eps = zeros(nobs,nz)
# eps(3,1) = sig
for t in xrange(1, nobs):
    Z[t, :] = Z[t - 1, :].dot(NN) + eps[t, :]

# set starting values and simulate
XYbar = Xbar
X0 = Xbar

empty_vec = np.zeros(0)
empty_mat = np.zeros((0, nz))

XSSL, temp_SSL = LinApp_SSL(X0,Z,XYbar,logX,PP,QQ,UU,\
                            [], empty_mat,empty_mat,empty_vec)

XCSL, temp_CSL = LinApp_CSL(Hansen_dyn, param, X0, Z, NN, logX, 0, [])

if do3:
    XCSL2, temp_sylv = LinApp_CSL(Hansen_dyn, param, X0, Z, NN, logX, 1, [])

print "XSSL", XSSL
print "Difference with CSL", XSSL - XCSL
print "Difference with CSL2", XSSL - XCSL2
'''
# plot results
if do3
    plotdatak = [XSSL(:,1) XCSL(:,1) XCSL2(:,1)]
    plotdatah = [XSSL(:,2) XCSL(:,2) XCSL2(:,2)]
else
Exemplo n.º 3
0
    print('QQ value is ', QQ)

# perform simulation
eps = np.random.randn(nobs) * sigma
z = np.zeros((nobs + 1, 1))
y = np.zeros(nobs)
c = np.zeros(nobs)
i = np.zeros(nobs)
r = np.zeros(nobs)
w = np.zeros(nobs)

z[0] = eps[0]
for t in range(0, nobs):
    z[t + 1, :] = phi * z[t, :] + eps[t]

k, blank = LinApp_SSL(kstart * kbar, z, kbar, logX, PP, QQ, UU, 0., RR, SS, VV)
for t in range(0, nobs):
    y[t], c[t], i[t], r[t], w[t] = example_def(k[t + 1], k[t], z[t], param)

# delete last observation for k and z
k = k[0:nobs]
z = z[0:nobs]

# plot data
t = range(0, nobs)
plt.plot(t, z, label='z')
plt.plot(t, k, label='k')
plt.plot(t, y, label='y')
plt.plot(t, c, label='c')
plt.plot(t, i, label='i')
plt.plot(t, r, label='r')
Exemplo n.º 4
0
#print ('R: ', RR)
#print ('S: ', SS)

# generate a history of Z's
nobs = 250
Zhist = np.zeros((nobs + 1, 1))
for t in range(1, nobs + 1):
    Zhist[t, 0] = rho * Zhist[t, 0] + sigma * np.random.normal(0., 1.)

# put SS values and starting values into numpy vectors
XYbar = kbar
X0 = kbar

# simulate the model
Xhist, Yhist = \
    LinApp_SSL(X0, Zhist, XYbar, logX, PP, QQ, RR, SS)

# generate non-state variables
Khist = np.zeros(nobs)
Yhist = np.zeros(nobs)
whist = np.zeros(nobs)
rhist = np.zeros(nobs)
Thist = np.zeros(nobs)
chist = np.zeros((nobs, S))
Chist = np.zeros(nobs)
uhist = np.zeros((nobs, S))

for t in range(0, nobs):
    Khist[t], Yhist[t], whist[t], rhist[t], Thist[t], chist[t,:], uhist[t,:] \
        = Modeldefs(Xhist[t+1,:], Xhist[t,:], Zhist[t,:], params)
    Chist[t] = np.sum(chist[t, :])
Exemplo n.º 5
0
def runsim(Zhist, nobs, params, LinCoeffs, bars):
    '''
    This function simulates the model once.
    
    Inputs:
        Zhist - a numpy array with the history of Z
        nobs - the number of observations to simulate
        params - list of model parameters
        LinCoeffs - list of linear coefficients for the policy and jump
            functions (PP, QQ, RR, SS)
        bars - list of steady state values
        
    Outputs:
        Khist - history of capital stock
        Nhist - history of hours worked
        Shist - history of sleep hours 
        Lhist - history of leisure hours
        dhist - history of waking pressure
        bhist - history of effectiveness due to sleep
        Yhist - history of output
        whist - history of hourly wage
        vhist - history of per worker fixed payments
        rhist - history of rental rate
        Chist - history of consumption
        Ihist - history of investment
        uChist - history of conumption utility
        uLhist - history of lesiure utility
        uShist - history of sleep utility
        uhist - history of total utility per period
    '''
    
    # create a history using polynomial coefficients.
    Khist = np.zeros(nobs+1)
    Nhist = np.zeros(nobs)
    Shist = np.zeros(nobs)
    Lhist = np.zeros(nobs)
    dhist = np.zeros(nobs)
    bhist = np.zeros(nobs)
    Yhist = np.zeros(nobs)
    whist = np.zeros(nobs)
    rhist = np.zeros(nobs)
    Chist = np.zeros(nobs)
    Ihist = np.zeros(nobs)
    uChist = np.zeros(nobs)
    uLhist = np.zeros(nobs)
    uShist = np.zeros(nobs)
    uhist = np.zeros(nobs)
            
    # set starting values
    X0 = np.array([Kbar])   
    Y0 = np.array([Nbar, Sbar])
    
    # simulate
    X, Y = LinApp_SSL(X0, Zhist, bar, False, PP, QQ, UU, Y0, RR, SS, VV)
    
    # unpack X & Y
    Khist = X
    Nhist = Y[:,0]
    Shist = Y[:,1]
    for t in range(0,nobs-1):
        Lhist[t], dhist[t], bhist[t], Yhist[t], whist[t], rhist[t], \
            Chist[t], Ihist[t], uChist[t], uLhist[t], uShist[t], uhist[t] = \
            mdefs(Khist[t+1], Khist[t], Nhist[t], Shist[t], zhist[t], *params)
    
    # delete last observation from Khist
    Khist = Khist[0:nobs]

    return Khist, Nhist, Shist, Lhist, dhist, bhist, Yhist, \
        whist, rhist, Chist, Ihist, uChist, uLhist, uShist, uhist