This paper presents a perfect foresight model of speculative attacks on emerging markets. Credit constrained governments are assumed to have two objectives: to accumulate liquid assets in order to self-insure against shocks to national consumption and to insure poorly regulated domestic financial markets. This policy regime generates endogenous fiscal deficits defined to include the growth of contingent liabilities. The model sets out a sequence of yield differentials consistent with capital inflows followed by anticipated speculative attacks. The model suggests that a common shock generated capital inflows to emerging markets in Asia and Latin America after 1989.