Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Next revision Both sides next revision
personal:portfolio:portopt [2014/06/06 10:22]
antonello [Usage]
personal:portfolio:portopt [2016/02/15 11:02]
antonello [Usage]
Line 54: 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,j}}}$ its variance.+where $x_i$ is the share of the asset $i$, $p_i$ is its productivity, $\sigma_{i,j}$ is the covariance between assets $i$ and $j$ and hence $\sum_i {x_i p_i}$ is the overall portfolio productivity and $\sum_i { \sum_j { x_i x_j \sigma_{i,j}}}$ is its variance.
  
 As the only quadratic term arises when $i=j$ and $\sigma_{i,j}$ being the variance is always positive, the problem is convex and hence easily numerically solved. As the only quadratic term arises when $i=j$ and $\sigma_{i,j}$ being the variance is always positive, the problem is convex and hence easily numerically solved.
Line 81: Line 81:
   g++ -std=c++0x -O -shared -Wl,-soname,_portopt.so -o _portopt.so QuadProg++.o Array.o anyoption.o portopt.o portopt_wrap.o   g++ -std=c++0x -O -shared -Wl,-soname,_portopt.so -o _portopt.so QuadProg++.o Array.o anyoption.o portopt.o portopt_wrap.o
 (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 =====
Line 93: Line 101:
  
 Call: Call:
-  double solveport (const vector< vector <double> > &VAR, const vector<double> &MEANS, const double &alpha, vector<double> &x_h, int &errorcode, string &errormessage, const double tollerance = 0.000001)+  double solveport (const vector< vector <double> > &VAR, const vector<double> &MEANS, const double &alpha, vector<double> &x_h, int &errorcode, string &errormessage, double &port_opt_mean, double &port_opt_var, const double tollerance = 0.000001)
      
 == As a lib using Python: == == As a lib using Python: ==
   import portopt   import portopt
-  results = portopt.solveport(var,means,alpha,tollerance) # tollerance is optional, default to 0.000001+  results = portopt.solveport(var,means,alpha,tolerance) # tolerance is optional, default to 0.000001
   functioncost = results[0]   functioncost = results[0]
   shares       = results[1]   shares       = results[1]
   errorcode    = results[2]   errorcode    = results[2]
   errormessage = results[3]   errormessage = results[3]
 +  opt_mean     = results[4]
 +  opt_var      = results[5]
  
 === Options === === Options ===
 <code> <code>
-  -h  --help                                    Prints this help +  -h  --help                                   Prints this help 
   -v  --var-file [input_var_file_name]         Input file containing the variance/covariance matrix (relative path)      -v  --var-file [input_var_file_name]         Input file containing the variance/covariance matrix (relative path)   
   -m  --means-file [input_means_file_name]     Input file containing the means vector (relative path)     -m  --means-file [input_means_file_name]     Input file containing the means vector (relative path)  
personal/portfolio/portopt.txt · Last modified: 2018/06/18 15:11 (external edit)
CC Attribution-Noncommercial-Share Alike 4.0 International
Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0