  Contemporary deep learning based solution methods used to compute approximate
equilibria of high-dimensional dynamic stochastic economic models are often
faced with two pain points. The first problem is that the loss function
typically encodes a diverse set of equilibrium conditions, such as market
clearing and households' or firms' optimality conditions. Hence the training
algorithm trades off errors between those -- potentially very different --
equilibrium conditions. This renders the interpretation of the remaining errors
challenging. The second problem is that portfolio choice in models with
multiple assets is only pinned down for low errors in the corresponding
equilibrium conditions. In the beginning of training, this can lead to
fluctuating policies for different assets, which hampers the training process.
To alleviate these issues, we propose two complementary innovations. First, we
introduce Market Clearing Layers, a neural network architecture that
automatically enforces all the market clearing conditions and borrowing
constraints in the economy. Encoding economic constraints into the neural
network architecture reduces the number of terms in the loss function and
enhances the interpretability of the remaining equilibrium errors. Furthermore,
we present a homotopy algorithm for solving portfolio choice problems with
multiple assets, which ameliorates numerical instabilities arising in the
context of deep learning. To illustrate our method we solve an overlapping
generations model with two permanent risk aversion types, three distinct
assets, and aggregate shocks.
