The management of a liquid asset portfolio that can be used to generate counterbalancing capacity in liquidity distress is quickly emerging as a core function in banks. The new Basel III liquidity risk regulation underscores the importance in banks managing a liquidity contingency buffer. The focus is on maintaining a high quality liquidity portfolio that can efficiently hedge liquidity outflows under stress scenarios. That is, to generate sufficient counterbalancing capacity. Since holding standby counterbalancing capacity has an opportunity cost, the firm would like to hold the minimum-cost portfolio that suffices for hedging out the negative flows. While the simplest way to build a liquidity portfolio is to hold sufficient cash at hand, this is not optimal for a profit-seeking institution. In general, high liquidity assets, such as cash, are the most costly to hold but have a lower execution cost when needed to create liquidity. In this paper we propose two typically complementary methods of finding the optimal liquidity hedging portfolio that can generate enough counterbalancing capacity with a high probability. The first method is to acquire more assets, which can generate future cashflows that can complement the potential net cash outflows. This method can be referred to as hedging with contractual cashflows that naturally complement the term structure of liquidity. The method can also be used when the strategy for executing the liquidity hedging portfolio is predetermined. The second method for liquidity hedging is to leverage dynamic counterbalancing capacity through use of credit facilities, asset sales and repo in order to generate liquidity at the exact time when net contractual cashflow cannot balance by itself. The main contribution of this paper is to establish a sound quantitative liquidity hedging framework that unifies and makes possible the application of the two liquidity hedging approaches consistently in practice.