We present a simulation-and-regression method for solving dynamic portfolio allocation problems in the presence of general transaction costs, liquidity costs and market impacts. This method extends the classical least squares Monte Carlo algorithm to incorporate switching costs, corresponding to transaction costs and transient liquidity costs, as well as multiple endogenous state variables, namely the portfolio value and the asset prices subject to permanent market impacts. To do so, we improve the accuracy of the control randomization approach in the case of discrete controls, and propose a global iteration procedure to further improve the allocation estimates. We validate our numerical method by solving a realistic cash-and-stock portfolio with a power-law liquidity model.We quantify the certainty equivalent losses associated with ignoring liquidity effects, and illustrate how our dynamic allocation protects the investor's capital under illiquid market conditions. Lastly, we analyze, under different liquidity conditions, the sensitivities of certainty equivalent returns and optimal allocations with respect to trading volume, stock price volatility, initial investment amount, risk-aversion level and investment horizon.The effect of liquidity on the design of dynamic multi-period portfolio selection methods (a.k.a. asset allocation, portfolio optimization or portfolio management) has drawn great attention from academics and practitioners alike. Liquidity affects portfolio allocation in two main ways: temporary liquidity cost and permanent market impact. Liquidity cost, also known as implementation shortfall, temporary market impact or transitory market impact, is the difference between the realized transaction price and the pre-transaction price. Market impact is the permanent shift in the asset price after a transaction, due to the post-transaction "resilience" of the limit order book. These liquidity effects depend on several factors, such as the nature of the exchange platform, the duration of the trade execution, the transaction volume, the asset volatility and so on. Up to now, liquidity modeling for dynamic portfolio selection has been impeded by the intractability of analytical solutions and by the limited capability of numerical methods to handle endogenous stochastic prices. The purpose of the present paper is to introduce a new simulation-and-regression method capable of handling multivariate portfolio allocation problems under general transaction costs, liquidity costs and market impacts. The original literature on dynamic portfolio selection started with simple problems without transaction costs. The seminal papers, Mossin (1968), Samuelson (1969), Merton (1969) and Merton (1971) provide closed-form solutions of optimal asset allocation strategies for long-term investors. In reality though, every transaction incurs commission fee (or brokerage cost), and several improvements have therefore been proposed to account for transaction cost. Examples of closed-form solutions are Davis and Norman (1990), Shr...