org.akutan.optimization
Class InteriorPointsSolver

java.lang.Object
  extended by org.akutan.optimization.InteriorPointsSolver
Direct Known Subclasses:
InteriorPointsReturn, InteriorPointsUtility

public class InteriorPointsSolver
extends java.lang.Object


Field Summary
protected  cern.colt.matrix.DoubleMatrix1D _er
          Expected returns of the assets
protected  java.util.List<double[]> _path
           
protected  boolean _savePath
          Manages the path of the solution across iterations
protected  cern.colt.matrix.DoubleMatrix2D _V
          Covariance matrix for the assets
protected  java.text.DecimalFormat df
          Format for formatting output
 
Constructor Summary
InteriorPointsSolver(cern.colt.matrix.DoubleMatrix1D er, cern.colt.matrix.DoubleMatrix2D V)
          Constructs
 
Method Summary
protected  void addPoint(java.util.List<SolvedPoint> l, double ra, cern.colt.matrix.DoubleMatrix1D x)
          Helper function called to build the finished point object and add it to the mean variance frontier.
protected  double algorithm(int maxMin, IPVector w_p, IPMatrix Q, IPMatrix QC, IPConsVector cons, double mu, cern.colt.matrix.DoubleMatrix2D AV, cern.colt.matrix.DoubleMatrix1D d, double threshold)
          Performs the actual algorithmic calculations of a single iteration.
protected  double computeAlpha(IPVector w_p, cern.colt.matrix.DoubleMatrix2D C, cern.colt.matrix.DoubleMatrix1D d, IPVector X)
           
protected  java.lang.String formatOutput(int n, double ra, IPVector x, int ct)
          Called to write out a line into the standard output for this iteration of the solver
protected  cern.colt.matrix.DoubleMatrix1D generate_b(java.util.List<Constraint> constraints)
          Given the list of constraints, builds the vector b (Ax = b) for the equality constraints.
protected  cern.colt.matrix.DoubleMatrix1D generate_d(java.util.List<Constraint> constraints)
          Given the list of constraints, builds the matrix of inequality constraints constants d (Cx >= d).
protected  cern.colt.matrix.DoubleMatrix2D getEqualityConstraints(java.util.List<Constraint> constraints)
          Given the list of constraints, builds the matrix of equality constraints A given the form Ax = b
protected  cern.colt.matrix.DoubleMatrix2D getInequalityConstraints(java.util.List<Constraint> constraints)
          Given the list of constraints, builds the matrix of inequality constraints C (Cx >= d)
protected  IPVector initialGuess(int maxMin, double mu, int n, int m1, cern.colt.matrix.DoubleMatrix2D AV, cern.colt.matrix.DoubleMatrix1D d)
          Called to compute the initial guess for a solution of the portfolio optimization problem
 cern.colt.matrix.DoubleMatrix2D make2D(cern.colt.matrix.DoubleMatrix1D input)
          Helper function to convert a vector into a single column 2d matrix for Colt.
protected  double maxReturn(cern.colt.matrix.DoubleMatrix1D er, java.util.List<Constraint> constraints)
          Called to solve the linear problem of max return portfolio in the presence of equality constraints.
protected  java.lang.String prettyPrint(int n, cern.colt.matrix.DoubleMatrix1D x, int ct, double eRet, double eSigma, double utility)
          Can be called to generate a pretty formatted string/line for output
 void savePath(boolean savePath)
          Enables "save path" mode which saves each solution along the path into a list so it could be plotted or reviewed.
 IPVector solvePoint(int maxMin, cern.colt.matrix.DoubleMatrix1D E_rx, java.util.List<Constraint> constraints, double ra, cern.colt.matrix.DoubleMatrix2D Vx, double threshold)
          Called to solve for a single point using the Interior Points method with logarithmic barriers.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_er

protected cern.colt.matrix.DoubleMatrix1D _er
Expected returns of the assets


_V

protected cern.colt.matrix.DoubleMatrix2D _V
Covariance matrix for the assets


_savePath

protected boolean _savePath
Manages the path of the solution across iterations


_path

protected java.util.List<double[]> _path

df

protected java.text.DecimalFormat df
Format for formatting output

Constructor Detail

InteriorPointsSolver

public InteriorPointsSolver(cern.colt.matrix.DoubleMatrix1D er,
                            cern.colt.matrix.DoubleMatrix2D V)
Constructs

Parameters:
er - Vector of asset expected returns
V - Matrix of covariance between assets
Method Detail

savePath

public void savePath(boolean savePath)
Enables "save path" mode which saves each solution along the path into a list so it could be plotted or reviewed.

Parameters:
savePath -

make2D

public cern.colt.matrix.DoubleMatrix2D make2D(cern.colt.matrix.DoubleMatrix1D input)
Helper function to convert a vector into a single column 2d matrix for Colt.

Parameters:
input - Input vector
Returns:
Single column matrix containing data from input

getEqualityConstraints

protected cern.colt.matrix.DoubleMatrix2D getEqualityConstraints(java.util.List<Constraint> constraints)
Given the list of constraints, builds the matrix of equality constraints A given the form Ax = b

Parameters:
constraints - List of constraints
Returns:
Returns the A matrix of coefficients for the constraints

generate_b

protected cern.colt.matrix.DoubleMatrix1D generate_b(java.util.List<Constraint> constraints)
Given the list of constraints, builds the vector b (Ax = b) for the equality constraints.

Parameters:
constraints - List of constraints
Returns:
b vector of constants for the constraints

getInequalityConstraints

protected cern.colt.matrix.DoubleMatrix2D getInequalityConstraints(java.util.List<Constraint> constraints)
Given the list of constraints, builds the matrix of inequality constraints C (Cx >= d)

Parameters:
constraints - List of constraints
Returns:
Matrix of coefficients for inequality constraints.

generate_d

protected cern.colt.matrix.DoubleMatrix1D generate_d(java.util.List<Constraint> constraints)
Given the list of constraints, builds the matrix of inequality constraints constants d (Cx >= d).

Parameters:
constraints - List of constraints
Returns:
Vector of constants for the constraints

solvePoint

public IPVector solvePoint(int maxMin,
                           cern.colt.matrix.DoubleMatrix1D E_rx,
                           java.util.List<Constraint> constraints,
                           double ra,
                           cern.colt.matrix.DoubleMatrix2D Vx,
                           double threshold)
Called to solve for a single point using the Interior Points method with logarithmic barriers. We are optimizing the objective of the form E_rx * X - 0.5 * ra * X' * Vx * X.

Parameters:
maxMin - Indicates whether the solution is maximizing the objective, or minimizing the objective.
E_rx - The vector of expected returns
constraints - List of constraints to be applied
ra - The risk aversion
Vx - The covariance matrix
threshold - Controls the number of iterations, terminates processing when the distance between two solutions (n, n-1) is less than this value as measured by the formula (x(n) - x(n-1))'((x(n) - x(n-1))
Returns:
The solution vector

algorithm

protected double algorithm(int maxMin,
                           IPVector w_p,
                           IPMatrix Q,
                           IPMatrix QC,
                           IPConsVector cons,
                           double mu,
                           cern.colt.matrix.DoubleMatrix2D AV,
                           cern.colt.matrix.DoubleMatrix1D d,
                           double threshold)
Performs the actual algorithmic calculations of a single iteration.

Parameters:
maxMin - Indicates whether we are maximizing or minimizing the objective function.
w_p - Solution vector to previous iteration.
Q - Matrix of coefficients for lhs (dX)
QC - Matrix of coefficients for rhs (X)
cons - Constant vector
mu - Coefficient of ?? Measures distance between ??
AV - Matrix of inequality constraint coefficients used in determining the step size along the direction computed.
d - Constant vector from inequality constraints used in determining the step size.
threshold - Distance between two successive solutions before the iterations will stop.
Returns:
Updated value of mu, mu = 0 when done.

addPoint

protected void addPoint(java.util.List<SolvedPoint> l,
                        double ra,
                        cern.colt.matrix.DoubleMatrix1D x)
Helper function called to build the finished point object and add it to the mean variance frontier.

Parameters:
l - List of solutions (points on the efficient frontier)
ra - Risk aversion used in evaluating the objective function
x - Solution vector

initialGuess

protected IPVector initialGuess(int maxMin,
                                double mu,
                                int n,
                                int m1,
                                cern.colt.matrix.DoubleMatrix2D AV,
                                cern.colt.matrix.DoubleMatrix1D d)
Called to compute the initial guess for a solution of the portfolio optimization problem

Parameters:
maxMin - Indicates whether we are maximizing or minimizing the objective function.
mu - Coefficient of ?? Used to measure distance between ??
n - Number of assets
m1 - Number of equality constraints
AV - Coefficients of inequality constraints
d - Constant values for inequality constraints.
Returns:
Solution vector for initial guess

computeAlpha

protected double computeAlpha(IPVector w_p,
                              cern.colt.matrix.DoubleMatrix2D C,
                              cern.colt.matrix.DoubleMatrix1D d,
                              IPVector X)

maxReturn

protected double maxReturn(cern.colt.matrix.DoubleMatrix1D er,
                           java.util.List<Constraint> constraints)
Called to solve the linear problem of max return portfolio in the presence of equality constraints. Uses the simplex solver.

Parameters:
er - Vector of expected returns
constraints - List of constraints
Returns:
Returns the maximum return given the covariance matrix embedded in this object and independent of the risk aversion.

prettyPrint

protected java.lang.String prettyPrint(int n,
                                       cern.colt.matrix.DoubleMatrix1D x,
                                       int ct,
                                       double eRet,
                                       double eSigma,
                                       double utility)
Can be called to generate a pretty formatted string/line for output

Parameters:
n - Number of assets
x - Solution vector
ct - Number of iterations to reach solution
eRet - Expected return for this solution
eSigma - Expected standard deviation for this solution
Returns:
String containing formatted version of solution

formatOutput

protected java.lang.String formatOutput(int n,
                                        double ra,
                                        IPVector x,
                                        int ct)
Called to write out a line into the standard output for this iteration of the solver

Parameters:
n - Number of assets
ra - Risk aversion
x - Solution vector
ct - Number of iterations so far
Returns:
Solution formatted as a pretty string