We derive generalizations of Dupire formula to the cases of general
stochastic drift and/or stochastic local volatility. First, we handle a case in
which the drift is given as difference of two stochastic short rates. Such a
setting is natural in foreign exchange context where the short rates correspond
to the short rates of the two currencies, equity single-currency context with
stochastic dividend yield, or commodity context with stochastic convenience
yield. We present the formula both in a call surface formulation as well as
total implied variance formulation where the latter avoids calendar spread
arbitrage by construction. We provide derivations for the case where both short
rates are given as single factor processes and present the limits for a single
stochastic rate or all deterministic short rates. The limits agree with
published results. Then we derive a formulation that allows a more general
stochastic drift and diffusion including one or more stochastic local
volatility terms. In the general setting, our derivation allows the computation
and calibration of the leverage function for stochastic local volatility
models