We develop a framework that makes it possible to study, for the first time, the strategic interaction between the ex ante choice of exchange-rate regime and the likelihood of ex post currency attacks. The optimal regime is determined by a policymaker who trades off the loss from nominal exchange-rate uncertainty against the cost of adopting a given regime. This cost increases, in turn, with the fraction of speculators who attack the local currency. Searching for the optimal regime within the class of exchange-rate bands, we show that the optimal regime can be either a peg (a zero-width band), a free float (an infinite-width band), or a nondegenerate band of finite width. We study the effect of several factors on the optimal regime and on the probability of currency attacks. In particular, we show that a Tobin tax induces policymakers to set less flexible regimes. In our model, this generates an increase in the probability of currency attacks. (JEL: F31, D84)