This paper presents a procedure for computing the theoretically optimal portfolio under the assumption that housing is an indivisible, illiquid asset that restricts the portfolio choice decision. The analysis also includes the financial constraints households may face when they apply for external funding. The set of financial assets that constitute the household's portfolios are bank time deposits, stocks, mortgage, and housing. We compare the theoretically optimal portfolio against Spanish household's actual choices using a unique data set, the Spanish Survey of Household Finance. In comparison with the optimal portfolio, households significantly underinvest in stocks and deposits. In the case of mortgages, the optimal and actual portfolios weights are not unequal. At a more disaggregated level, some additional differences emerge that are explained by demographic, educational, and income characteristics