Class PortfolioOptimizer

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

public final class PortfolioOptimizer extends Object
Portfolio Optimization Engine (long-only, fully invested).

Supports maximum-Sharpe and minimum-volatility portfolios plus efficient frontier construction. The optimizer uses stochastic search over the simplex (Dirichlet sampling) followed by deterministic pairwise-transfer refinement, which is robust for non-smooth objectives and needs no external solver. Results are deterministic for a given seed.

Expected returns and covariance must share the same periodicity (e.g. both annualized, or both daily).

  • Constructor Details

    • PortfolioOptimizer

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

      public PortfolioOptimizer(double[] expectedReturns, double[][] covariance, long seed)
  • 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)
      Efficient frontier: minimum-volatility portfolios across a grid of target returns between the min and max asset expected returns.
    • rebalance

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