This paper studies optimal investment and the dynamic cost of income uncertainty, applying a stochastic programming approach. The motivation is given by a case study in Finnish agriculture. The investment decision of a representative farm is modelled as a Markov decision process, extended to account for risk. A numerical framework for studying the dynamic uncertainty cost is presented, modifying the classical expected value of perfect information to a dynamic setting. The uncertainty cost depends on the volatility of income: e.g. with stationary income, the dynamic uncertainty cost corresponds to a dynamic option value of postponing investment. The model can be applied to agricultural policy planning. In the case study, the investment decision is sensitive to risk.