We derive the optimal exchange rate policy for a small open economy subject to terms-oftrade shocks. Firm owners and workers are risk averse but workers more so. Wages are given or partially indexed in the short run, and capital markets are imperfect. The government sets the exchange rate to allocate risk between workers and owners. With less risk-averse firms, and greater difference in risk aversion between workers and firms, the optimal exchange rate should vary little with pure terms-of-trade shocks but more with general shocks to prices. Optimal exchange rate variation is greater with indexed wages, but is smaller when firms behave monopolistically and when wage taxes (profit taxes) change procyclically (countercyclically) with export prices (import prices). The model gives policy rules for determining optimal variations of the exchange rate, and indicates when it is, and is not, optimal to join a currency union with trading partners, implying zero exchange rate variation.JEL Code: F31, F33, F41.