Differences
This shows you the differences between two versions of the page.
personal:portfolio:portopt [2014/05/28 13:56] antonello |
personal:portfolio:portopt [2018/06/18 15:11] |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | PortOpt [Portfolio Optimizer] is an open-source (GPLed) C++ program (with Python binding) implementing the Markowitz(1952) [[http:// | ||
- | |||
- | You have to provide PortOpt (in text files or - if you use the api- using your own code) the variance/ | ||
- | |||
- | It returns the vector of assets' | ||
- | |||
- | In order to minimise the variance it internally uses [[http:// | ||
- | |||
- | {{ : | ||
- | |||
- | ===== Download it ===== | ||
- | |||
- | Windows executable (command line tool!), linux (x64) executable and source code (for C++/Python) are available from [[https:// | ||
- | |||
- | ===== Theorical Background ===== | ||
- | |||
- | In portfolio theory agents attempts to maximise portfolio expected return for a given amount of portfolio risk, or equivalently to minimise risk for a given level of expected return. | ||
- | |||
- | {{ : | ||
- | |||
- | The portfolio management can be portrayed graphically as in the above Figure, where the feasible set of variance-profitability combinations in enclosed by the blue curve and the B-D segment represents the efficient frontier, where no variance can be lowered at productivity' | ||
- | |||
- | In order to simplify computations, | ||
- | In such case the indifference curves can be drawn like a bundle of straight lines having equation $prod = \alpha * var + \beta$, where $\alpha$ is the linear risk aversion coefficient and both $prod$ and $var$ refer to the overall portfolio' | ||
- | |||
- | Point $B$ represents the point having the lowest possible portfolio variance. | ||
- | |||
- | \begin{equation} | ||
- | \begin{array}{rrrll} | ||
- | \max_{x_i, \beta} & Y & = & \beta & \\ | ||
- | s.t. & & & | ||
- | & x_i & \geqslant & 0 & \forall i\\ | ||
- | & \sum_i x_i & = & 1 & \\ | ||
- | & \sum_i {x_i p_i} & = & \alpha \sum_i { \sum_j { x_i x_j \sigma_{i, | ||
- | \end{array} | ||
- | \label{eq: | ||
- | \end{equation} | ||
- | |||
- | |||
- | that by substitution become: | ||
- | |||
- | \begin{equation} | ||
- | \begin{array}{rrrll} | ||
- | \min_{x_i} & Y & = & | ||
- | s.t. & | ||
- | & x_i & \geqslant & 0 & \forall i\\ | ||
- | & \sum_i x_i & = & 1 & \\ | ||
- | \end{array} | ||
- | \label{eq: | ||
- | \end{equation} | ||
- | |||
- | where $x_i$ is the share of the asset $i$, $p_i$ is its productivity and hence $\sum_i {x_i p_i}$ is the overall portfolio productivity and $\sum_i { \sum_j { x_i x_j \sigma_{i, | ||
- | |||
- | As the only quadratic term arises when $i=j$ and $\sigma_{i, | ||
- | |||
- | |||
- | ===== Compilation (not needed if using a pre-compiled version) ===== | ||
- | |||
- | === | ||
- | |||
- | g++ -std=c++0x -O -o portopt_executable QuadProg++.cpp Array.cpp anyoption.cpp portopt.cpp | ||
- | |||
- | === Option 2 - as a library to be used in your C/C++ program === | ||
- | |||
- | g++ -fPIC -std=c++0x -O -c QuadProg++.cpp Array.cpp anyoption.cpp portopt.cpp main.cpp | ||
- | g++ -std=c++0x -O -shared -Wl, | ||
- | |||
- | Then link your program e.g. with: | ||
- | g++ -std=c++0x -O -o portopt_executable main.o -Wl, | ||
- | ./ | ||
- | |||
- | | ||
- | === Option 3 - as a lib to be used in python, using swig === | ||
- | |||
- | swig -c++ -python portopt.i | ||
- | g++ -fPIC -std=c++0x -O -c QuadProg++.cpp Array.cpp anyoption.cpp portopt.cpp portopt_wrap.cxx main.cpp -I/ | ||
- | g++ -std=c++0x -O -shared -Wl, | ||
- | (then please refer to the python example for usage) | ||
- | |||
- | ===== Usage ===== | ||
- | == Linux == | ||
- | ./portopt [options] | ||
- | | ||
- | == Windows == | ||
- | portopt.exe [options] | ||
- | (from a DOS prompt: (a) START-> | ||
- | |||
- | == As a lib from C++: == | ||
- | |||
- | Call: | ||
- | double solveport (const vector< vector < | ||
- | | ||
- | == As a lib ising Python: == | ||
- | import portopt | ||
- | results = portopt.solveport(var, | ||
- | |||
- | === Options === | ||
- | < | ||
- | -h --help | ||
- | -v --var-file [input_var_file_name] | ||
- | -m --means-file [input_means_file_name] | ||
- | -a --alpha [alpha_coefficient] | ||
- | -f --field-delimiter [field_delimiter] | ||
- | -s --decimal-separator [decimal-separator] | ||
- | </ | ||
- | |||
- | === Notes === | ||
- | |||
- | * Higher the alpha, lower the agent risk aversion; | ||
- | * Set a negative alpha to retrieve the portfolio with the lowest possible variance; | ||
- | * Set alpha to zero to retrieve the portfolio with the highest mean, indipendently from variance (solution not guaranteed to be unique); | ||
- | * Assets shares are returned in the x_h vector, eventual error code (0: all fine, 1: input data error, 2: no solutions) in the errorcode parameter. | ||
- | | ||
- | | ||
- | ===== Copyright and licence ===== | ||
- | |||
- | Copyright (C) 2014 Antonello Lobianco. | ||
- | |||
- | PortOpt is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. | ||
- | |||
- | PortOpt is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. | ||
- | |||
- | You should have received a copy of the GNU Lesser General Public License along with PortOpt. | ||
- | |||
- | |||
- | ===== Acknowledgements ===== | ||
- | |||
- | This work was supported by the French National Research Agency through the Laboratory of Excellence ARBRE, a part of the " | ||
- | |||
- | |||