In this paper we solve the general discrete time mean-variance hedging problem by dynamic programming. Thanks to its simple recursive structure our solution is well suited for computer implementation. On the theoretical side, we show how the variance-optimal measure arises in our dynamic...