quant-econ Solutions: Vectors, Arrays and Matrices

Exercise 1

Here's the iterative approach


In [1]:
function compute_asymptotic_var(A, Sigma, tolerance=1e-6)
    V = Sigma * Sigma'
    S = V
    err = tolerance + 1
    while err > tolerance
        next_S = A * S * A' + V
        err = norm(S - next_S)
        S = next_S
    end
    return S
end


Out[1]:
compute_asymptotic_var (generic function with 2 methods)

In [2]:
A =     [0.8 -0.2; 
        -0.1 0.7]
Sigma = [0.5 0.4;
         0.4 0.6]


Out[2]:
2x2 Array{Float64,2}:
 0.5  0.4
 0.4  0.6

Note that all eigenvalues of $A$ lie inside the unit disc:


In [3]:
eigmax(A)


Out[3]:
0.9

Let's compute the asymptotic variance:


In [4]:
compute_asymptotic_var(A, Sigma)


Out[4]:
2x2 Array{Float64,2}:
 0.671228  0.633476
 0.633476  0.858874

Now let's do the same thing using QuantEcon's solve_discrete_lyapunov() function and check we get the same result


In [6]:
using QuantEcon

In [7]:
solve_discrete_lyapunov(A, Sigma * Sigma')


Out[7]:
2x2 Array{Float64,2}:
 0.671231  0.633474
 0.633474  0.858874