Hello,
I am reading the Python codes replicating Arellano (2008) in the series of Quant lecture
Link for the code: https://lectures.quantecon.org/py/arellano.html
There are some codes I could not understand,
-
Allocate memory
self.Vd = np.zeros(ny) self.Vc = np.zeros((ny, nB)) self.V = np.zeros((ny, nB)) self.Q = np.ones((ny, nB)) * .95 # Initial guess for prices self.default_prob = np.empty((ny, nB)) # Compute the value functions, prices, and default prob self.solve(tol=tol, maxit=maxit) # Compute the optimal savings policy conditional on no default self.compute_savings_policy()
def solve(self, tol=1e-8, maxit=10000):
# Iteration Stuff
it = 0
dist = 10.# Alloc memory to store next iterate of value function V_upd = np.zeros((self.ny, self.nB)) # == Main loop == # while dist > tol and maxit > it: # Compute expectations for this iteration Vs = self.V, self.Vd, self.Vc EV, EVd, EVc = (self.Py @ v for v in Vs) # Run inner loop to update value functions Vc and Vd. # Note that Vc and Vd are updated in place. Other objects # are not modified. _inner_loop(self.ygrid, self.def_y, self.Bgrid, self.Vd, self.Vc, EVc, EVd, EV, self.Q, self.β, self.θ, self.γ)
I do not understand what “inner_loop” actually do here? I googled but could not find this syntax.
-
Update prices
Vd_compat = np.repeat(self.Vd, self.nB).reshape(self.ny, self.nB)
default_states = Vd_compat > self.Vc
I don’t know what will be returned from “default_states= Vd > Vc”? I guess it is kind of a matrix which assign 1 for position whose element in Vd is greater than Vc, and 0 other wise; but I am not so sure, I searched but could not find similar code to see its meaning.
Is there anyone having an idea?
Any help is really appreciated.
Thank you!