AlgoQuant, an integrated trading strategy research and backtesting system
com.numericalmethod.algoquant.model.portfoliooptimization.markowitz

## Class MarkowitzPortfolio

• java.lang.Object
• com.numericalmethod.algoquant.model.portfoliooptimization.markowitz.MarkowitzPortfolio

• public class MarkowitzPortfolio
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\max \left \{ q * Var(w'r) - E(w'r) \right \} \\ =\arg\max \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.
• 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 Summary

Constructors
Constructor and Description
MarkowitzPortfolio(com.numericalmethod.suanshu.algebra.linear.vector.doubles.Vector mu, com.numericalmethod.suanshu.algebra.linear.matrix.doubles.Matrix sigma)
Constructs a Markowitz portfolio from expected future returns and future covariance, assuming no short selling constraint and zero benchmark rate.
MarkowitzPortfolio(com.numericalmethod.suanshu.algebra.linear.vector.doubles.Vector mu, com.numericalmethod.suanshu.algebra.linear.matrix.doubles.Matrix sigma, QPConstraint constraints)
Constructs a Markowitz portfolio from expected future returns and future covariance, assuming zero benchmark rate for Sharpe ratio calculation.
MarkowitzPortfolio(com.numericalmethod.suanshu.algebra.linear.vector.doubles.Vector mu, com.numericalmethod.suanshu.algebra.linear.matrix.doubles.Matrix sigma, QPConstraint constraints, double benchmarkRate)
Constructs a Markowitz portfolio from expected future returns and future covariance.
• ### Method Summary

All Methods
Modifier and Type Method and Description
double fw()
Evaluates $$E(w'r) - q * Var(w'r)$$ at w_eff.
double getOptimalRiskAversionCoefficient()
Gets the optimal risk aversion coefficient w.r.t.
double getOptimalRiskAversionCoefficient(double lower, double initial, double upper)
Gets the optimal risk aversion coefficient w.r.t.
com.numericalmethod.suanshu.algebra.linear.vector.doubles.Vector getOptimalWeights()
Gets the Markowitz optimal portfolio weights, for a given risk aversion coefficient.
double getRiskAversionCoefficientForTargetReturn(double r, double lower, double upper, int maxIterations)
double getRiskAversionCoefficientForTargetVariance(double var, double lower, double upper, int maxIterations)
void setRiskAversionCoefficient(double q)
Sets the risk aversion coefficient, effectively moving along the efficient frontier.
• ### Methods inherited from class java.lang.Object

clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
• ### Constructor Detail

• #### MarkowitzPortfolio

public MarkowitzPortfolio(com.numericalmethod.suanshu.algebra.linear.vector.doubles.Vector mu,
com.numericalmethod.suanshu.algebra.linear.matrix.doubles.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
• #### MarkowitzPortfolio

public MarkowitzPortfolio(com.numericalmethod.suanshu.algebra.linear.vector.doubles.Vector mu,
com.numericalmethod.suanshu.algebra.linear.matrix.doubles.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
• #### MarkowitzPortfolio

public MarkowitzPortfolio(com.numericalmethod.suanshu.algebra.linear.vector.doubles.Vector mu,
com.numericalmethod.suanshu.algebra.linear.matrix.doubles.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
• ### Method Detail

• #### setRiskAversionCoefficient

public void setRiskAversionCoefficient(double q)
throws com.numericalmethod.suanshu.optimization.multivariate.constrained.convex.sdp.socp.qp.QPInfeasible,
Exception
Sets the risk aversion coefficient, effectively moving along the efficient frontier. Recompute the optimal weights.
Parameters:
q - the risk aversion coefficient
Throws:
com.numericalmethod.suanshu.optimization.multivariate.constrained.convex.sdp.socp.qp.QPInfeasible
Exception
• #### getOptimalWeights

public com.numericalmethod.suanshu.algebra.linear.vector.doubles.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 com.numericalmethod.suanshu.analysis.root.univariate.NoRootFoundException
Throws:
com.numericalmethod.suanshu.analysis.root.univariate.NoRootFoundException
• #### getRiskAversionCoefficientForTargetVariance

public double getRiskAversionCoefficientForTargetVariance(double var,
double lower,
double upper,
int maxIterations)
throws com.numericalmethod.suanshu.analysis.root.univariate.NoRootFoundException
Throws:
com.numericalmethod.suanshu.analysis.root.univariate.NoRootFoundException