def test_noninteractive(self): "Test case for when agents don't interact with each other" # Copied these values from test_lqcontrol a = np.array([[.95, 0.], [0, .95]]) b1 = np.array([.95, 0.]) b2 = np.array([0., .95]) r1 = np.array([[-.25, 0.], [0., 0.]]) r2 = np.array([[0., 0.], [0., -.25]]) q1 = np.array([[-.15]]) q2 = np.array([[-.15]]) f1, f2, p1, p2 = nnash(a, b1, b2, r1, r2, q1, q2, 0, 0, 0, 0, 0, 0, tol=1e-8, max_iter=10000) alq = a[:1, :1] blq = b1[:1].reshape((1, 1)) rlq = r1[:1, :1] qlq = q1 lq_obj = LQ(qlq, rlq, alq, blq, beta=1.) p, f, d = lq_obj.stationary_values() assert_allclose(f1, f2[:, ::-1]) assert_allclose(f1[0, 0], f[0]) assert_allclose(p1[0, 0], p2[1, 1]) assert_allclose(p1[0, 0], p[0, 0])
def setUp(self): # Initial Values a_0 = 100 a_1 = 0.5 rho = 0.9 sigma_d = 0.05 beta = 0.95 c = 2 gamma = 50.0 theta = 0.002 ac = (a_0 - c) / 2.0 R = np.array([[0, ac, 0], [ac, -a_1, 0.5], [0., 0.5, 0]]) R = -R Q = gamma / 2 Q_pf = 0. A = np.array([[1., 0., 0.], [0., 1., 0.], [0., 0., rho]]) B = np.array([[0.], [1.], [0.]]) B_pf = np.zeros((3, 1)) C = np.array([[0.], [0.], [sigma_d]]) # the *_pf endings refer to an example with pure forecasting # (see p171 in Robustness) self.rblq_test = RBLQ(Q, R, A, B, C, beta, theta) self.rblq_test_pf = RBLQ(Q_pf, R, A, B_pf, C, beta, theta) self.lq_test = LQ(Q, R, A, B, C, beta) self.methods = ['doubling', 'qz']
def setUp(self): # Initial Values a_0 = 100 a_1 = 0.5 rho = 0.9 sigma_d = 0.05 beta = 0.95 c = 2 gamma = 50.0 theta = 0.002 ac = (a_0 - c) / 2.0 R = np.array([[0, ac, 0], [ac, -a_1, 0.5], [0., 0.5, 0]]) R = -R Q = gamma / 2 A = np.array([[1., 0., 0.], [0., 1., 0.], [0., 0., rho]]) B = np.array([[0.], [1.], [0.]]) C = np.array([[0.], [0.], [sigma_d]]) self.rblq_test = RBLQ(Q, R, A, B, C, beta, theta) self.lq_test = LQ(Q, R, A, B, C, beta) self.Fr, self.Kr, self.Pr = self.rblq_test.robust_rule()
def setUp(self): # Initial Values q = 1. r = 1. rf = 1. a = .95 b = -1. c = .05 beta = .95 T = 1 self.lq_scalar = LQ(q, r, a, b, C=c, beta=beta, T=T, Rf=rf) Q = np.array([[0., 0.], [0., 1]]) R = np.array([[1., 0.], [0., 0]]) RF = np.eye(2) * 100 A = np.ones((2, 2)) * .95 B = np.ones((2, 2)) * -1 self.lq_mat = LQ(Q, R, A, B, beta=beta, T=T, Rf=RF)
density=gaussian_kde(betaols) xs = np.linspace(-1,1) plt.plot(xs,density(xs)) plt.show() ############ # AD-HOC # ########### theta =2 R=-R F, P, K = quantecon.robustlq.RBLQ(Q,R,A,B,C,beta,theta).robust_rule() P = quantecon.solve_discrete_riccati(A, B, R, Q) from quantecon.lqcontrol import LQ I=np.eye(4) lq = LQ(-beta*I*theta, R, A, C, beta=beta) Ptest, ftest, dtest = lq.stationary_values() theta =901 A=np.matrix([[rho1,0,0,0], [0,rho2,0,0], [0,0,rho3,0], [0,0,0,rho4]]) B=np.zeros((4,4))
B = np.matrix([[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]) C = np.matrix([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]) Q = np.matrix([[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]) R = np.matrix([[r1, 0, 0, 0], [0, r2, 0, 0], [0, 0, r3, 0], [0, 0, 0, r4]]) P = np.ones(4) I = np.ones(4) Z = np.zeros(4) quantecon.robustlq.RBLQ(Q, R, A, B, C, beta, theta).robust_rule() F, K, P = quantecon.robustlq.RBLQ.robust_rule() lq = LQ(-beta * I * theta, R, A, C, beta=beta) P, f, d = lq.stationary_values() #Define M for Schur-Decomposition M11 = A + C * np.linalg.inv(beta * theta * A) * C.T * R M12 = C * np.linalg.inv(beta * theta * A) * C.T M21 = np.linalg.inv(A) * R M22 = np.linalg.inv(A) M1 = np.hstack((M11, M12)) M2 = np.hstack((M21, M22)) M = np.vstack((M1, M2)) [T, Z, sdim] = scipy.linalg.schur(M, output='real', sort='iuc')
q = 1e6 # == Formulate as an LQ problem == # Q = 1 R = np.zeros((2, 2)) Rf = np.zeros((2, 2)) Rf[0, 0] = q A = [[1 + r, -c_bar + mu], [0, 1]] B = [[-1], [0]] C = [[sigma], [0]] # == Compute solutions and simulate == # lq = LQ(Q, R, A, B, C, beta=beta, T=T, Rf=Rf) x0 = (0, 1) xp, up, wp = lq.compute_sequence(x0) # == Convert back to assets, consumption and income == # assets = xp[0, :] # a_t c = up.flatten() + c_bar # c_t income = wp[0, 1:] + mu # y_t # == Plot results == # n_rows = 2 fig, axes = plt.subplots(n_rows, 1, figsize=(12, 10)) plt.subplots_adjust(hspace=0.5) for i in range(n_rows): axes[i].grid()