Class MCLNiedermayer
- java.lang.Object
-
- tech.nmfin.portfoliooptimization.clm.MCLNiedermayer
-
- All Implemented Interfaces:
MarkowitzCriticalLine
public class MCLNiedermayer extends Object implements MarkowitzCriticalLine
Implements Markowitz's critical line algorithm. The portfolio minimization problem is formulated as: \[ minimize_w \frac{1}{2} w^t \Sigma w - \lambda \mu^t w \text{subject to} 1^t w = 1, w \ge 0 \]By default, this implementation computes the turning points along a critical line and returns the optimal weights once a given lambda or target return is reached. This ensures the best performance for one-off usage. However, if the critical line is known to be reused for many thousands of times, it might be more time-saving to compute and cache the whole critical line by calling setCachingCriticalLine(boolean) before computing weights.
-
-
Constructor Summary
Constructors Constructor Description MCLNiedermayer(Vector gain, Matrix covariance)Creates the critical line for given gain vector and covariance matrix, with non-negativity constraint.MCLNiedermayer(Vector gain, Matrix covariance, Vector lower, Vector upper)Creates the critical line for given gain vector and covariance matrix, with given lower and upper bounds for weights.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description VectorgetOptimalWeightForSetLambda(double lambda)VectorgetOptimalWeightForTargetReturn(double target)List<TurningPoint>getTurningPoints()voidsetCachingCriticalLine(boolean toCache)Sets the algorithm to compute and cache the whole critical line, so that optimal weights can be computed as quick as a linear search for turning points on the line.
-
-
-
Constructor Detail
-
MCLNiedermayer
public MCLNiedermayer(Vector gain, Matrix covariance)
Creates the critical line for given gain vector and covariance matrix, with non-negativity constraint.- Parameters:
gain- the gain vectorcovariance- the covariance matrix
-
MCLNiedermayer
public MCLNiedermayer(Vector gain, Matrix covariance, Vector lower, Vector upper)
Creates the critical line for given gain vector and covariance matrix, with given lower and upper bounds for weights.- Parameters:
gain- the gain vectorcovariance- the covariance matrixlower- the lower bounds for asset weightsupper- the upper bounds for asset weights
-
-
Method Detail
-
setCachingCriticalLine
public void setCachingCriticalLine(boolean toCache)
Sets the algorithm to compute and cache the whole critical line, so that optimal weights can be computed as quick as a linear search for turning points on the line.Caution: computation of the whole critical line may be thousand times time-consuming than finding the optimal weights for a single lambda or return.
- Parameters:
toCache-trueif the whole critical line needs to be computed and cached
-
getTurningPoints
public List<TurningPoint> getTurningPoints() throws Exception
- Specified by:
getTurningPointsin interfaceMarkowitzCriticalLine- Throws:
Exception
-
getOptimalWeightForSetLambda
public Vector getOptimalWeightForSetLambda(double lambda) throws Exception
- Specified by:
getOptimalWeightForSetLambdain interfaceMarkowitzCriticalLine- Throws:
Exception
-
getOptimalWeightForTargetReturn
public Vector getOptimalWeightForTargetReturn(double target) throws Exception
- Specified by:
getOptimalWeightForTargetReturnin interfaceMarkowitzCriticalLine- Throws:
Exception
-
-