Class MarkowitzByQP

  • Direct Known Subclasses:
    MarkowitzByCLM

    public class MarkowitzByQP
    extends Object
    Modern portfolio theory (MPT) is a theory of investment which attempts to maximize portfolio expected return for a given amount of portfolio risk, or equivalently minimize risk for a given level of expected return, by carefully choosing the proportions of various assets.

    For a given "risk aversion", q, the mathematical formulation is the following Markowitz’s mean-variance formulation: \[ w_{eff} = \arg\max \left \{ E(w'r) - q * Var(w'r) \right \} \\ =\arg\min \left \{ q * Var(w'r) - E(w'r) \right \} \\ =\arg\min \left \{ q * (w' \Sigma w) - w'r \right \} \] s.t., w' 1 = 1, other constraints on w. q is the slope of a portfolio on the efficient frontier.
    See Also:
    • Wikipedia: Modern portfolio theory
    • "Tze Leung Lai, Haipeng Xing, Zehao Chen. "Eq. 1.2, Mean-variance portfolio optimization when means and covariances are unknown," Annals of Applied Statistics 2011, Vol. 5, No. 2A, 798-823"
    • Constructor Detail

      • MarkowitzByQP

        public MarkowitzByQP​(Vector mu,
                             Matrix sigma,
                             QPConstraint constraints)
        Constructs a Markowitz portfolio from expected future returns and future covariance, assuming zero benchmark rate for Sharpe ratio calculation.
        Parameters:
        mu - expected future returns of assets
        sigma - future covariance of assets
        constraints - the additional constraints on w_eff
      • MarkowitzByQP

        public MarkowitzByQP​(Vector mu,
                             Matrix sigma,
                             QPConstraint constraints,
                             double benchmarkRate)
        Constructs a Markowitz portfolio from expected future returns and future covariance.
        Parameters:
        mu - expected future returns of assets
        sigma - future covariance of assets
        constraints - the additional constraints on w_eff
        benchmarkRate - the benchmark rate used to compute Sharpe ratio
      • MarkowitzByQP

        public MarkowitzByQP​(Vector mu,
                             Matrix sigma)
        Constructs a Markowitz portfolio from expected future returns and future covariance, assuming no short selling constraint and zero benchmark rate.
        Parameters:
        mu - expected future returns of assets
        sigma - future covariance of assets
      • MarkowitzByQP

        public MarkowitzByQP​(Vector mu,
                             Matrix sigma,
                             Vector lower,
                             Vector upper)
        Constructs a Markowitz portfolio from expected future returns and future covariance, with lower and upper limits on asset weights, assuming zero benchmark rate.
        Parameters:
        mu - expected future returns of assets
        sigma - future covariance of assets
        lower - the lower limits of asset weights
        upper - the upper limits of asset weights
      • MarkowitzByQP

        public MarkowitzByQP​(Vector mu,
                             Matrix sigma,
                             Vector lower,
                             Vector upper,
                             double benchmarkRate)
        Constructs a Markowitz portfolio from expected future returns and future covariance for a given benchmark rate, with lower and upper limits on asset weights.
        Parameters:
        mu - expected future returns of assets
        sigma - future covariance of assets
        lower - the lower limits of asset weights
        upper - the upper limits of asset weights
        benchmarkRate - the benchmark rate used to compute Sharpe ratio
    • Method Detail

      • setRiskAversionCoefficient

        public void setRiskAversionCoefficient​(double q)
                                        throws QPInfeasible,
                                               Exception
        Sets the risk aversion coefficient, effectively moving along the efficient frontier. Recompute the optimal weights.
        Parameters:
        q - the risk aversion coefficient
        Throws:
        QPInfeasible
        Exception
      • getOptimalW

        protected Vector getOptimalW​(double q)
                              throws Exception
        Solves w_eff = argmin {q * (w' Σ w) - w'r}.
        Parameters:
        q - the risk-aversion coefficient
        Returns:
        the optimal weights w_eff
        Throws:
        QPInfeasible - when the underlying quadratic programming problem is infeasible
        Exception
      • getOptimalWeights

        public Vector getOptimalWeights()
        Gets the Markowitz optimal portfolio weights, for a given risk aversion coefficient.
        Returns:
        the Markowitz optimal portfolio weights
      • fw

        public double fw()
        Evaluates \(E(w'r) - q * Var(w'r)\) at w_eff.
        Returns:
        \(E(w'r) - q * Var(w'r)\) at w_eff
      • getOptimalRiskAversionCoefficient

        public double getOptimalRiskAversionCoefficient​(double lower,
                                                        double initial,
                                                        double upper)
                                                 throws Exception
        Gets the optimal risk aversion coefficient w.r.t. Sharpe ratio.
        Parameters:
        lower - lower bound for the search, e.g., 0
        initial - an initial guess of where the optimal risk aversion coefficient may be
        upper - upper bound for the search
        Returns:
        the optimal risk aversion coefficient
        Throws:
        Exception
      • getOptimalRiskAversionCoefficient

        public double getOptimalRiskAversionCoefficient()
        Gets the optimal risk aversion coefficient w.r.t. Sharpe ratio.
        Returns:
        the optimal risk aversion coefficient
      • getRiskAversionCoefficientForTargetReturn

        public double getRiskAversionCoefficientForTargetReturn​(double r,
                                                                double lower,
                                                                double upper,
                                                                int maxIterations)
                                                         throws NoRootFoundException
        Throws:
        NoRootFoundException
      • getRiskAversionCoefficientForTargetVariance

        public double getRiskAversionCoefficientForTargetVariance​(double var,
                                                                  double lower,
                                                                  double upper,
                                                                  int maxIterations)
                                                           throws NoRootFoundException
        Throws:
        NoRootFoundException