We develop a simple model of the exchange rate in which agents optimize their portfolio and use different forecasting rules. They check the profitability of these rules ex post and select the more profitable one. This model produces two kinds of equilibria, a fundamental and a bubble one. In a stochastic environment the model generates a complex dynamics in which bubbles and crashes occur at unpredictable moments. We contrast these behavioural bubbles with rational bubbles.