I develop an algorithm for solving dynamic models in which individualdecision rules and the cross-sectional distribution of agents'characteristics influence each other. To illustrate the algorithm, Isolve an endowment economy with incomplete markets, a continuum ofheterogeneous agents, and aggregate shocks. The key innovation of thealgorithm is to parameterize the (cross-sectional) density with aflexible functional form, which makes it possible to avoid simulationtechniques. The paper shows how to check for accuracy and establisheslinks between the properties of the incomplete-markets economy andthe aspects involved in obtaining a numerical solution.