The neoclassical growth model predicts that emerging countries with higher TFP growth should receive larger capital inflows. Gourinchas and Jeanne (2007) document that, in fact, countries that exhibited higher productivity catch-up received less capital inflows, even though they invested more in their domestic technology. This is the allocation puzzle. I show that introducing investment risk in the same neoclassical framework qualifies the predictions in terms of capital flows: countries with higher TFP growth invest more in their own production but they have to hold external bonds for precautionary savings motives. Contrary to the riskless approach, the portfolio approach predicts accurately the allocation of capital flows across developing countries.