kul-optec / superscs

Fast conic optimization in C
https://kul-forbes.github.io/scs/
Other
26 stars 11 forks source link

YAML file of portfolio selection example #31

Open heshriti opened 5 years ago

heshriti commented 5 years ago

Hi,

do you have a YAML file of the portfolio selection problem in the cvx page? (https://kul-forbes.github.io/scs/page_cvx_examples.html)

Thank you.

alphaville commented 5 years ago

Hi @heshriti. You can download the YAML file you requested from this link.

If you would like to generate it yourself, you need to follow these steps:

  1. Run the portfolio selection example using the option dumpfile; this will create a MAT file with the problem data
  2. Run problem_to_yaml to export the problem in YAML format

Here is the code:

%% Run the portfolio selection problem
density = 0.1;
rc = 0.5; % estimated reciprocal condition number
n = 100000;
m = 100;
mu = exp(0.01 * randn(n, 1)) - 1; % returns
D = rand(n,1) / 10; % idiosyncratic risk
F = sprandn(n, m, density, rc) / 10; % factor model
gamma = 1;
B = 1;
cvx_begin
    cvx_solver scs
    cvx_solver_settings('eps', 1e-4,...
        'do_super_scs', 1,...
        'direction', 100,...
        'memory', 100, ...
        'dumpfile', 'portfolio.mat')
    variable x(n)
    maximize(mu'*x - gamma*(sum_square(F'*x) + sum_square(D.*x)))
    sum(x) == B
    x >= 0
cvx_end

%% Serialize the problem 
load('portfolio.mat');
problem_to_yaml('portfolio.yml', 'MyPortfolio', data, K);
heshriti commented 5 years ago

@alphaville Thanks Pantellis.

Is it possible to share python or c example to generate this yaml? I don't have matlab unfortunately.