In mathematical finance, Margrabe's formula is an option pricing formula applicable to an option to exchange one risky asset for another risky asset at maturity. It was derived by William Margrabe (PhD Chicago) in 1978. Margrabe's paper has been cited by over 2000 subsequent articles.

Formula
Suppose S1(t) and S2(t) are the prices of two risky assets at time t, and that each has a constant continuous dividend yield qi. The option, C, that we wish to price gives the buyer the right, but not the obligation, to exchange the second asset for the first at the time of maturity T. In other words, its payoff, C(T), is max(0, S1(T) - S2(T)). 

If the volatilities of Si are σi, then , where ρ is the Pearson's correlation coefficient of the Brownian motions of the Si 's.

Margrabe's formula states that the fair price for the option at time 0 is:

where:
 are the expected dividend rates of the prices  under the appropriate risk-neutral measure,
 denotes the cumulative distribution function for a standard normal, 
, 
.

Derivation
Margrabe's model of the market assumes only the existence of the two risky assets, whose prices, as usual, are assumed to follow a geometric Brownian motion. The volatilities of these Brownian motions do not need to be constant, but it is important that the volatility of S1/S2, σ, is constant. In particular, the model does not assume the existence of a riskless asset (such as a zero-coupon bond) or any kind of interest rate. The model does not require an equivalent risk-neutral probability measure, but an equivalent measure under S2.

The formula is quickly proven by reducing the situation to one where we can apply the Black-Scholes formula.  
First, consider both assets as priced in units of S2 (this is called 'using S2 as numeraire'); this means that a unit of the first asset now is worth S1/S2 units of the second asset, and a unit of the second asset is worth 1.  
Under this change of numeraire pricing, the second asset is now a riskless asset and its dividend rate q2 is the interest rate. The payoff of the option, repriced under this change of numeraire, is max(0, S1(T)/S2(T) - 1).  
So the original option has become a call option on the first asset (with its numeraire pricing) with a strike of 1 unit of the riskless asset. Note the dividend rate q1 of the first asset remains the same even with change of pricing.
Applying the Black-Scholes formula with these values as the appropriate inputs, e.g. initial asset value S1(0)/S2(0), interest rate q2, volatility σ, etc., gives us the price of the option under numeraire pricing. 
Since the resulting option price is in units of S2, multiplying through by S2(0) will undo our change of numeraire, and give us the price in our original currency, which is the formula above. Alternatively, one can show it by the Girsanov theorem.

External links and references
Notes

Primary reference
William Margrabe, "The Value of an Option to Exchange One Asset for Another", Journal of Finance, Vol. 33, No. 1, (March 1978), pp. 177-186.
Discussion
Mark Davis, Imperial College London, Multi-Asset Options
Rolf Poulsen, University of Gothenburg, The Margrabe Formula

 
Mathematical finance
Options (finance)
Financial models