We develop an integrated simulation/optimization model for managing portfolios of mortgage-backed securities. The mortgage portfolio problem is viewed in the same spirit of models used for the management of portfolios of equities. That is, it trades off rates of return with a suitable measure of risk. In this respect we employ amean-absolute deviation model which is consistent with the asymmetric distribution of returns of mortgage securities and derivative products. We develop a simulation procedure to compute holding period returns of the mortgage securities under a range of interest rate scenarios. The simulation explicitly takes into account the stylized facts of mortgage securities: the propensity of homeowners to prepay their mortgages, and theoption adjusted premia associated with these securities. Details of both the simulation and optimization models are presented. The model is then applied to the funding of a typical insurance liability stream, and it is shown to generate superior results than the standardportfolio immunization approach.