Login

Generate an MPS file (free MPS format) for Mean-CVaR problem

Here are some examples for illustrating how the script meancvar.py can be used under *nix environment (requires Python 2.4 or 2.5, gzip). Problem formulation can be found here.

You may download a set of scenarios here: returns.dat.gz (~3.9Mb)

The data contains 100,000 scenarios with 4 assets.

The following commands assume that both the script and data are in the current directory.

To generate an MPS file for problem with requried return equal to 0.005:

$ gzip -cd returns.dat.gz|python meancvar.py -r 0.005 > meancvar.mps

To solve the problem with the first 10000 scenarios only:

$ gzip -cd returns.dat.gz|head -n 10000|python meancvar.py -r 0.005 > meancvar.mps

or

$ gzip -cd returns.dat.gz|python meancvar.py -r 0.005 -N 10000 > meancvar.mps

To solve the problem considering only the first 2 assets and last 10000 scenarios:

$ gzip -cd returns.dat.gz|tail -n 10000|gawk '{print $1, $2}'|python meancvar.py -r 0.005 > meancvar.mps

Now that we have generated meancvar.mps. We can solve the optimization problem with various solvers.

MOSEK

MOSEK is a commercial solver. It has a simple command line tool for solving LP problem in free MPS format:

$ mosek -min -d MSK_IPAR_READ_MPS_FORMAT MSK_MPS_FORMAT_FREE meancvar.mps

A file meancvar.sol is then written.

CPLEX

CPLEX is another commercial solver. It provides an interactive command line tool:

$ cplex

Then we are in CPLEX Interactive Optimizer:

CPLEX> read meancvar.mps

then

CPLEX> optimize

GLPK

GLPK is a free solver. To solve the problem with GLPK:

$ glpsol --freemps --min -o out.txt meancvar.mps

The output is then saved in out.txt.

CLP

CLP is an open source solver developed under Computational Infrastructure for Operations Research (COIN-OR). To solve the problem with CLP:

$ clp meancvar.mps -dualsimplex -solution out.txt

The output is then saved in out.txt.

Comparison

This comparison is by no means a rigorous one. I did not tweak the solvers and basically use their default settings. We generate the MPS file as follows:

$ gzip -cd returns.dat.gz|python meancvar.py -r 0.005 > meancvar.mps

MOSEK CPLEX GLPK CLP
Objective 2.1686035989e-02 2.1686035989e-02 2.168603599e-02 2.168603599e-02
W0 -1.73637962998158 -1.736380 -1.73638 -1.7363796
W1 3.30776840568039 3.307768 3.30777 3.3077684
W2 -0.703969489851783 -0.703969 -0.703969 -0.70396949
W3 0.132580714152964 0.132581 0.132581 0.13258071
TAU 0.0147259589357271 0.014726 0.014726 0.014725959
Iterations 25 15169 160262 22990
CPU time reported (s) 4.48 162.15 29501.0 270.952