Markowitz suggests in his Nobel Prize-winning paper Markowitz(1952) that when one selects a portfolio, he/she should consider both the return and the risk of the portfolio. Most of us, if not all, are risk-averse. Risk-averse means that if there are two  portfolios with the same return, but different risks (in this article by risk we mean the standard deviation of the portfolio), we would choose the one with the smaller risk without any hesitation. Therefore given a set of risky assets and an expected return, we are interested in finding their best combination, i.e. the weights which will minimize the risk of the portfolio. And if we find the minimum risk of the portfolio for any return, we can draw a curve on risk-return plane. This curve is the famous efficient frontier.

Assuming there are \(n\) risky assets, and their return vector and covariance matrix are \(R\) and \(\Sigma\) respectively, then the points on the efficient frontier are computed by solving the following problem:

\(\min_{w\in\mathbb{R}^{n}} w^{\top}\Sigma w \)

\(\text{s.t.} \sum_{i=1}^{n}w_{i}=1\)


where \(\mu\) is the pre-defined expected return, and \(w\) is the weight vector. The above problem can be solved using Lagrange multipliers. And we denote this problem as “Problem 1”.

In AlgoQuant, we use another approach to compute the efficient frontier. The problem we solve is based on the utility function:

\(\min_{w\in\mathbb{R}^{n}} q\times w^{\top}\Sigma w-R^{\top}w \)

\(\text{s.t.} \sum_{i=1}^{n}w_{i}=1\)


\(R\), \(\Sigma\), \(w\) and \(\mu\) are the same parameters in Problem 1. The newly added parameter \(q\), is risk-averse coefficient. And this problem is denoted as “Problem 2”.

The larger the \(q\), the less risk the investor is willing to take. Although most of us are risk-averse, the degrees of risk-averse are different among individuals. As a result, a coefficient that describes the risk-averse degree is introduced. Note that in some papers, risk tolerance coefficient is used, for example Steinbach (2001). Risk tolerance is the reciprocal of risk-averse and it is applied on the return term in the objective function rather than the risk term. For usages of risk-averse coefficient in portfolio optimization, please see page 75 of Lee and Lee (2010), and page 159 of Bodie et al. (2008).

It can be seen that Problem 2 and Problem 1 are equivalent. Because with the constraint \(R^{\top}w=\mu\), the second term in Problem 2’s objective function is a constant, and it does not affect the optimization result. If problem 2 and problem 1 are equivalent, why even bother including the risk-averse coefficient?

When computing the efficient frontier, the two problems are equivalent. However the solutions of the two problems will be different when the constraint \(R^{\top}w=\mu\) is removed.


Problem 1′:

\(\min_{w\in\mathbb{R}^{n}} w^{\top}\Sigma w \)

\(\text{s.t.} \sum_{i=1}^{n}w_{i}=1\)

Problem 2′:

\(\min_{w\in\mathbb{R}^{n}} q\times w^{\top}\Sigma w-R^{\top}w \)

\(\text{s.t.} \sum_{i=1}^{n}w_{i}=1\)

The solution of Problem 1′ is the minimum variance portfolio. And minimum variance portfolio is the portfolio on the efficient frontier which has the minimum variance (i.e., the leftmost point on the curve). On the other hand, the solution of Problem 2′ is the optimal portfolio given utility function \(R^{\top}w-q\times w^{\top}\Sigma w\). This optimal portfolio is also on the efficient frontier.  Thus different \(q\) can lead to different optimal portfolios on the efficient frontier.  When \(q\) is infinity, the return term in the objective function would be 0 comparing to the risk. It means that the only consideration in portfolio optimization is the risk. Thus the portfolio corresponding to \(q=\infty\) is the minimum variance portfolio. When \(q\) is decreasing to 0, the significance of the risk term in the objective function is also decreasing.  And the corresponding portfolio is moving in the upper right direction along the efficient frontier. Finally when \(q\) is 0, we are just maximizing expected return, without any constraints on the risk.

From the above discussion, it can be seen that changing \(q\) in Problem 2′ can also find the efficient frontier. However this is not the approach used in AlgoQuant. Because the point movements on the curve are very slow when \(q\) increases. For example, portfolios corresponding to \(q = 0.1\) and \(q = 10\) are very close on the efficient frontier. As a result, changing expected return in Problem 2 is more convenient to draw the efficient frontier.

When \(q\) is unknown, AlgoQuant provides a method to find the optimal \(q\). In AlgoQuant, MarkowitzPortfolio class, there is a method called getOptimalRiskAversionCoefficient. This method will try different risk-averse coefficients and select the one whose corresponding optimal portfolio has the largest Sharpe ratio, given a risk free rate. And the corresponding portfolio is the tangency portfolio on the efficient frontier.

So far three different portfolios have been discussed: the minimum variance portfolio, the tangency portfolio and the optimal portfolio. And they have the following connections. The optimal portfolio is found by solving Problem 2′, given a risk-averse coefficient \(q\). And every portfolio on the efficient frontier is an optimal portfolio. The optimal portfolio with the largest Sharpe ratio (given a risk free rate) is the tangency portfolio.  And finally the optimal portfolio with the smallest risk is the minimum variance portfolio.  Moreover the weight corresponding to any one of the optimal portfolios is a linear combination of weights corresponding to the minimum variance portfolio and the tangency portfolio.

By providing an extra input parameter \(q\), AlgoQuant is more flexible to give a client a specific optimal portfolio. Because if a client knows his risk-averse coefficient \(q\), the optimal portfolio corresponding to \(q\) can be computed by AlgoQuant. And if he doesn’t, AlgoQuant can always recommend a portfolio on the efficient frontier according to his expected return.



The following code is an example on computing the efficient frontier in AlgoQuant. In this example, Problem 2 is solved with different expected returns and fixed \(q\).

public void generateFrontierUsingAlgoQuant() throws Exception {
    System.out.println("generating efficient frontier");
    Matrix sigma = new DenseMatrix(new double[][]{
        {0.1, 0.03, -0.08, 0.05},
        {0.03, 0.2, 0.02, 0.03},
        {-0.08, 0.02, 0.3, 0.2},
        {0.05, 0.03, 0.2, 0.9}
    final Vector mu 
            = new DenseVector(new double[]{0.08, 0.09, 0.1, 0.11});

    double q = 1;
    double[] expRs = DoubleUtils.seq(0.07, 0.14, 0.005);
    double[] returns = new double[expRs.length];
    double[] stdevs = new double[expRs.length];
    int i = 0;
    final int n = mu.size();
    for (final double expR : expRs) {
        // we constraint the expected return to compute the point
        // on the frontier
        WeightConstraints expectedReturnConstraint 
                = getExpReturnConstraint(mu, expR);

        MarkowitzPortfolio mp = new MarkowitzPortfolio(mu,
                sigma, expectedReturnConstraint);
        double ret = mp.getPortfolioReturn();
        double stdev = Math.sqrt(mp.getPortfolioVariance());
        Vector w = mp.getWeights();

        System.out.println("exp return = " + expR);
        System.out.println("q = " + q);
        System.out.println("w = " + w);
        System.out.println("return = " + ret + " = "
                + w.innerProduct(mu));
        System.out.println("stdev = " + stdev + " = "
                + Math.sqrt(w.innerProduct(sigma.multiply(w))));

        returns[i] = ret;
        stdevs[i] = stdev;

    // print out for plotting in Excel
    System.out.println("  returns = ");
    for (double ret : returns) {
    System.out.println("  stdevs = ");
    for (double std : stdevs) {

private WeightConstraints getExpReturnConstraint(
        final Vector mu, 
        final double expR) {
    return new WeightConstraints() {
        public LinearGreaterThanConstraints getLinearGreaterThanConstraints() {
            return null;

        public LinearLessThanConstraints getLinearLessThanConstraints() {
            return null;

        public LinearEqualityConstraints getLinearEqualityConstraints() {
            return new LinearEqualityConstraints(
                    new DenseMatrix(
                    mu.minus(expR).toArray(), 1, mu.size()),
                    new DenseVector(0.));

Recommended Posts

No comment yet, add your voice below!

Add a Comment