org.ojalgo.finance.portfolio
Class MarkowitzModel

java.lang.Object
  extended by org.ojalgo.finance.portfolio.FinancePortfolio
      extended by org.ojalgo.finance.portfolio.MarkowitzModel

public final class MarkowitzModel
extends FinancePortfolio

The Markowitz model, in this class, is defined as:

min (RAF/2) [w]T[C][w] - [w]T[r]
subject to |[w]| = 1

RAF stands for Risk Aversion Factor. Instead of specifying a desired risk or return level you specify a level of risk aversion that is used to balance the risk and return.

The expected returns for each of the instruments/assets must be excess returns. Otherwise this formulation is wrong.

The total weights of all instruments will always be 100%, but shorting can be allowed or not according to your preference. ( setShortingAllowed(boolean) ) In addition you may set lower and upper limits on any individual instrument. ( setLowerLimit(int, BigDecimal) and setUpperLimit(int, BigDecimal) )

Risk-free asset: That means there is no excess return and zero variance. Don't (try to) include a risk-free asset here.

Do not worry about the minus sign in front of the return part of the objective function - it is handled/negated for you. When you're asked to supply the expected excess returns you should supply precisely that.

Author:
apete

Constructor Summary
MarkowitzModel(org.ojalgo.finance.portfolio.EquilibriumModel anEquilibriumModel)
           
MarkowitzModel(MarketEquilibrium aMarketEquilibrium, BasicMatrix anExpectedExcessReturns)
           
 
Method Summary
 org.ojalgo.finance.portfolio.MarkowitzModel.LowerUpper addConstraint(BigDecimal aLower, BigDecimal anUpper, int... someInstrumentIndeces)
           
 void clearAllConstraints()
           
 BasicMatrix getAssetReturns()
           
 List<SimpleAsset> getAssets()
           
 BasicMatrix getAssetWeights()
           
 BasicMatrix getCovariances()
           
 BigDecimal getImpliedRiskAversion(BasicMatrix aWeightsVctr, BasicMatrix aReturnsVctr)
           
 double getMeanReturn()
          The mean/expected return of this instrument.
 State getOptimisationState()
           
 double getReturnVariance()
          The instrument's return variance.
 BigDecimal getRiskAversion()
           
 String[] getSymbols()
           
 List<BigDecimal> getWeights()
          This method returns a list of the weights of the Portfolio's contained assets.
 void setLowerLimit(int anInstrumentIndex, BigDecimal aLimit)
           
 void setRiskAversion(Number aFactor)
           
 void setShortingAllowed(boolean aFlag)
           
 void setTargetReturn(BigDecimal aTargetReturn)
           Will set the target return to whatever you input and the target variance to null.
 void setTargetVariance(BigDecimal aTargetVariance)
           Will set the target variance to whatever you input and the target return to null.
 void setUpperLimit(int anInstrumentIndex, BigDecimal aLimit)
           
 String toString()
           
 
Methods inherited from class org.ojalgo.finance.portfolio.FinancePortfolio
forecast, getSharpeRatio, getValueAtRisk, getVolatility, normalise, shift
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MarkowitzModel

public MarkowitzModel(org.ojalgo.finance.portfolio.EquilibriumModel anEquilibriumModel)

MarkowitzModel

public MarkowitzModel(MarketEquilibrium aMarketEquilibrium,
                      BasicMatrix anExpectedExcessReturns)
Method Detail

addConstraint

public org.ojalgo.finance.portfolio.MarkowitzModel.LowerUpper addConstraint(BigDecimal aLower,
                                                                            BigDecimal anUpper,
                                                                            int... someInstrumentIndeces)

clearAllConstraints

public final void clearAllConstraints()

getOptimisationState

public final State getOptimisationState()

setLowerLimit

public final void setLowerLimit(int anInstrumentIndex,
                                BigDecimal aLimit)

setShortingAllowed

public final void setShortingAllowed(boolean aFlag)

setTargetReturn

public final void setTargetReturn(BigDecimal aTargetReturn)

Will set the target return to whatever you input and the target variance to null.

Setting the target return implies that you disregard the risk aversion factor and want the minimum risk portfolio with return that is equal to or greater than the target.

By setting the target return too high it is possible to define an infeasible optimisation problem. It is in fact (in combination with setting lower and upper bounds on the instrument weights) very easy to do so without realising it.

Setting a target return is not recommnded. It's much better to modify the risk aversion factor.

See Also:
setTargetVariance(BigDecimal)

setTargetVariance

public final void setTargetVariance(BigDecimal aTargetVariance)

Will set the target variance to whatever you input and the target return to null.

Setting the target variance implies that you disregard the risk aversion factor and want the maximum return portfolio with risk that is equal to or as close to the target as possible.

A target variance isn't an infeasibility risk the way a return target is. The algorithm will return a solution, but there is no guaranty the portfolio variance is equal to or less than the target (as one may expect).

There is a performance penalty for setting a target variance as the underlying optimisation model has to be solved several (many) times with different pararmeters (different risk aversion factors).

Setting a target variance is not recommnded. It's much better to modify the risk aversion factor.

See Also:
setTargetReturn(BigDecimal)

setUpperLimit

public final void setUpperLimit(int anInstrumentIndex,
                                BigDecimal aLimit)

toString

public String toString()
Overrides:
toString in class Object

getAssetReturns

public final BasicMatrix getAssetReturns()

getAssets

public List<SimpleAsset> getAssets()

getAssetWeights

public final BasicMatrix getAssetWeights()

getCovariances

public final BasicMatrix getCovariances()

getImpliedRiskAversion

public final BigDecimal getImpliedRiskAversion(BasicMatrix aWeightsVctr,
                                               BasicMatrix aReturnsVctr)

getMeanReturn

public final double getMeanReturn()
Description copied from class: FinancePortfolio
The mean/expected return of this instrument. May return either the absolute or excess return of the instrument. The context in which an instance is used should make it clear which. Calling FinancePortfolio.shift(Number) with an appropriate argument will transform between absolute and excess return.

Specified by:
getMeanReturn in class FinancePortfolio

getReturnVariance

public final double getReturnVariance()
Description copied from class: FinancePortfolio
The instrument's return variance. Subclasses must override either FinancePortfolio.getReturnVariance() or FinancePortfolio.getVolatility().

Overrides:
getReturnVariance in class FinancePortfolio

getRiskAversion

public final BigDecimal getRiskAversion()

getSymbols

public final String[] getSymbols()

getWeights

public final List<BigDecimal> getWeights()
Description copied from class: FinancePortfolio
This method returns a list of the weights of the Portfolio's contained assets. An asset weight is NOT restricted to being a share/percentage - it can be anything. Most subclasses do however assume that the list of asset weights are shares/percentages that sum up to 100%. Calling FinancePortfolio.normalise() will transform any set of weights to that form.

Specified by:
getWeights in class FinancePortfolio

setRiskAversion

public final void setRiskAversion(Number aFactor)