Class PortfolioOptimizer

java.lang.Object
com.quantfinlib.optimization.PortfolioOptimizer

public final class PortfolioOptimizer extends Object
Long-only, fully invested mean-variance optimisation (Markowitz 1952), solved exactly as convex quadratic programs by QuadraticProgram:
  • minimum variance: min w'Σw s.t. 1'w = 1, w ≥ 0;
  • frontier point: the same with μ'w = target added;
  • maximum Sharpe: by the homogenisation of the linear-fractional problem (Cornuéjols and Tütüncü, Optimization Methods in Finance, 2007, §8.2): min y'Σy s.t. (μ − r_f)'y = 1, y ≥ 0, then w = y / 1'y. It needs at least one asset with μ_i > r_f; otherwise no long-only portfolio has a positive excess return and the method throws.

Results are optimal to rounding (the active-set method terminates on the KKT conditions). Expected returns and covariance must share the same periodicity. The covariance is copied and must be symmetric and positive semi-definite.

  • Constructor Details

    • PortfolioOptimizer

      public PortfolioOptimizer(double[] expectedReturns, double[][] covariance)
  • Method Details

    • maxSharpe

      public PortfolioOptimizer.Allocation maxSharpe(double riskFreeRate)
      Maximum Sharpe ratio portfolio. riskFreeRate in the same periodicity as the inputs.
    • minVolatility

      public PortfolioOptimizer.Allocation minVolatility()
      Minimum volatility portfolio.
    • efficientFrontier

      public List<PortfolioOptimizer.Allocation> efficientFrontier(int points)
      Minimum-variance frontier: for each of points target returns evenly spaced from the lowest to the highest asset expected return, the long-only portfolio of least variance that earns exactly that return. Points below the minimum-variance portfolio's return are on the inefficient lower branch; filter by return if only the efficient part is wanted.
    • rebalance

      public static double[] rebalance(double[] currentWeights, double[] targetWeights)
      Rebalancing deltas: target minus current weights, per asset.