We develop a unified framework for optimally managing public portfolios for a class of macro-finance models that include widely-used specifications for households’ risk and liquidity preferences, market structures for financial assets, and trading frictions. An optimal portfolio hedges fluctuations in interest rates, primary surpluses, liquidities and inequalities. It recognizes liquidity benefits that government debts provide and internalizes equilibrium effects of public policies on financial asset prices. We express an optimal portfolio in terms of statistics that are functions only of macro and financial market data. An application to the U.S. shows that hedging interest rate risk plays a dominant role in shaping an optimal maturity structure of government debt.