In this paper we develop a concrete and fully implementable approach to the optimization of functionally generated portfolios in stochastic portfolio theory. The main idea is to optimize over a family of rank-based portfolios parameterized by an exponentially concave function on the unit interval. This choice can be motivated by the long term stability of the capital distribution observed in large equity markets, and allows us to circumvent the curse of dimensionality. The resulting optimization problem, which is convex, is flexible as various regularizations and constraints can be imposed on the generating function. We prove that the optimization problem is well-posed and provide a stability estimate in terms of a Wasserstein metric of the input measure. We then give a careful treatment of its discretization and the optimization algorithm. Finally, we present empirical examples using CRSP data from the US stock market.