Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
personal:portfolio:portopt [2014/05/28 09:11] antonello [Theorical Background] |
personal:portfolio:portopt [2016/02/15 11:19] antonello |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | PortOpt is a C++ program (with Python binding) implementing the Markowitz(1952) [[http:// | + | PortOpt |
You have to provide PortOpt (in text files or - if you use the api- using your own code) the variance/ | 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' | + | It returns the vector of assets' |
In order to minimise the variance it internally uses [[http:// | In order to minimise the variance it internally uses [[http:// | ||
Line 11: | Line 11: | ||
===== Download it ===== | ===== Download it ===== | ||
- | * windows | + | Windows |
- | * linux (x64) executable | + | |
- | * source (for C++/Python) | + | ===== Bugs and support ===== |
+ | |||
+ | If you find a bug, request a feature or need support open a ticket or discuss it in the [[https:// | ||
===== Theorical Background ===== | ===== Theorical Background ===== | ||
Line 19: | Line 21: | ||
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. | 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' | 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' | ||
Line 26: | Line 28: | ||
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' | 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. | + | Point $B$ represents the point having the lowest possible portfolio variance. |
\begin{equation} | \begin{equation} | ||
Line 52: | Line 54: | ||
\end{equation} | \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, | + | where $x_i$ is the share of the asset $i$, $p_i$ is its productivity, $\sigma_{i, |
As the only quadratic term arises when $i=j$ and $\sigma_{i, | As the only quadratic term arises when $i=j$ and $\sigma_{i, | ||
Line 79: | Line 81: | ||
g++ -std=c++0x -O -shared -Wl, | g++ -std=c++0x -O -shared -Wl, | ||
(then please refer to the python example for usage) | (then please refer to the python example for usage) | ||
+ | |||
+ | If you want to change the output library name (e.g. you want to create _portopt_p3.so for python3 alongside _portopt.so for python2), do it in the %module variable of portopt.i and in the -soname and -o options of the linking command (and don't forget to use the right python included directory in the compilation command).\\ | ||
+ | You can then load the correct module in your script with something like: | ||
+ | import sys | ||
+ | if sys.version_info < (3, 0): | ||
+ | import portopt | ||
+ | else: | ||
+ | import portopt_p3 as portopt | ||
===== Usage ===== | ===== Usage ===== | ||
+ | |||
+ | :!: Please notice that the API changed from version 1.1, with the introduction of the '' | ||
+ | |||
+ | |||
== Linux == | == Linux == | ||
./portopt [options] | ./portopt [options] | ||
Line 91: | Line 105: | ||
Call: | Call: | ||
- | double solveport (const vector< vector < | + | double solveport (const vector< vector < |
| | ||
- | == As a lib ising Python: == | + | == As a lib using Python: == |
import portopt | import portopt | ||
- | results = portopt.solveport(var, | + | results = portopt.solveport(var, |
+ | functioncost = results[0] | ||
+ | shares | ||
+ | errorcode | ||
+ | errormessage = results[3] | ||
+ | opt_mean | ||
+ | opt_var | ||
=== Options === | === Options === | ||
< | < | ||
- | -h --help | + | -h --help |
-v --var-file [input_var_file_name] | -v --var-file [input_var_file_name] | ||
-m --means-file [input_means_file_name] | -m --means-file [input_means_file_name] | ||
-a --alpha [alpha_coefficient] | -a --alpha [alpha_coefficient] | ||
-f --field-delimiter [field_delimiter] | -f --field-delimiter [field_delimiter] | ||
- | -s --decimal-separator [decimal-separator] | + | -s --decimal-separator [decimal-separator] |
+ | -t --tollerance [tolerance] | ||
</ | </ | ||
Line 111: | Line 132: | ||
* Higher the alpha, lower the agent risk aversion; | * Higher the alpha, lower the agent risk aversion; | ||
* Set a negative alpha to retrieve the portfolio with the lowest possible variance; | * 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 | + | * Set alpha to zero to retrieve the portfolio with the highest mean, independently |
- | * 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. | + | * Assets shares are returned in the x_h vector, eventual error code (0: all fine, 1: input data error, 2: no solutions, 3: didn't solve, 4: solver internal error) in the errorcode parameter. |
+ | * Use option " | ||
| | ||
| | ||
Line 124: | Line 146: | ||
You should have received a copy of the GNU Lesser General Public License along with PortOpt. | You should have received a copy of the GNU Lesser General Public License along with PortOpt. | ||
+ | |||
+ | |||
+ | ===== Citations ===== | ||
+ | If you use this program or a derivative of it in an academic framework, please cite it!\\ | ||
+ | Please cite as: | ||
+ | * A. Dragicevic, A. Lobianco, | ||
+ | |||
+ | ===== Acknowledgements ===== | ||
+ | |||
+ | This work was supported by: | ||
+ | |||
+ | * a grant overseen by Office National des Forêts through the [[http:// | ||
+ | * the French National Research Agency through the [[http:// | ||
+ | |||