In this chapter we determine the optimal allocation for a generic investor in a generic market of securities. In Section 6.1 we introduce allocation optimization by means of a fully worked-out, non-trivial leading example. In Section 6.2 we present an overview of results on convex optimization, with particular focus on cone programming. First order, second-order, and semidefinite cone programming encompass a broad class of constrained optimization problems that appear in the context of asset allocation. In Section 6.3 we discuss a two-step approach that approximates the solution to the formal general allocation optimization by means of a tractable, quadratic problem. The first step in this approach is the mean-variance optimization pioneered by Markowitz, which selects a one-parameter family of efficient allocations among all the possible combinations of assets; the second step is a simple one-dimensional search for the best among the efficient allocations, which can be performed numerically. We introduce the mean-variance framework by means of geometrical arguments and discuss how to compute the necessary inputs that feed the mean-variance optimization. We also present the mean-variance problem in the less general, yet more common, formulation in terms of returns. In Section 6.4 we discuss analytical solutions to the mean-variance problem. Among other results, we prove wrong the common belief that a market with low correlations provides better investment opportunities than a highly correlated market. In Section 6.5 we analyze a few common pitfalls of the mean-variance approach. In Section 6.6 we discuss at lenght benchmark-driven allocation and the wedge-like geometry of its efficient frontier. In Section 6.7 we conclude with a case study.