cvxgrp / strat_models

A distributed method for fitting Laplacian regularized stratified models.
Apache License 2.0
25 stars 8 forks source link

Replacing Mosek with OSQP #3

Closed andrewcztrack closed 3 years ago

andrewcztrack commented 3 years ago

Hi @jonathantuck @sbarratt !!

Would it be possible to replace mosek solver with OSQP for the finance sector example?

Also, i would like to add a constraint that every weight is above 5%, would this be possible?

Kind regards and thanks, Andrew

sbarratt commented 3 years ago

We don’t use MOSEK or OSQP in this project

On Wed, Nov 25, 2020 at 6:01 PM andrewcztrack notifications@github.com wrote:

Hi @jonathantuck https://github.com/jonathantuck @sbarratt https://github.com/sbarratt !!

Would it be possible to replace mosek solver with OSQP?

Kind regards and thanks, Andrew

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/cvxgrp/strat_models/issues/3, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB7LUGL5XLJPFRTRYKIR7CTSRWZGRANCNFSM4UDDXW4A .

andrewcztrack commented 3 years ago

Hi @sbarratt !!

Thank you for your help :)!

When i run the sector example i get the below -

In the training set: Market conditions average of 1.2664 data points. The most populated market condition has 38 data points. 1395 market conditions have no data. Traceback (most recent call last): File "sectors.py", line 91, in prob.solve(verbose=False) File "/home/andrewcz/miniconda3/envs/mlfinll/lib/python3.7/site-packages/cvxpy/problems/problem.py", line 396, in solve return solve_func(self, *args, **kwargs) File "/home/andrewcz/miniconda3/envs/mlfinll/lib/python3.7/site-packages/cvxpy/problems/problem.py", line 753, in _solve self, data, warm_start, verbose, kwargs) File "/home/andrewcz/miniconda3/envs/mlfinll/lib/python3.7/site-packages/cvxpy/reductions/solvers/solving_chain.py", line 326, in solve_via_data solver_opts, problem._solver_cache) File "/home/andrewcz/miniconda3/envs/mlfinll/lib/python3.7/site-packages/cvxpy/reductions/solvers/conic_solvers/mosek_conif.py", line 233, in solve_via_data task.optimize() File "/home/andrewcz/miniconda3/envs/mlfinll/lib/python3.7/site-packages/mosek/init.py", line 7627, in optimize raise Error(rescode(res),msg) mosek.Error: rescode.err_missing_license_file(1008): License cannot be located. The default search path is ':/home/andrewcz/mosek/mosek.lic:

I assume its because i don't have a licence for mosek.

jonathantuck commented 3 years ago

Hello! Unfortunately, this problem cannot be reduced to a QP, so you cannot use OSQP for this optimization problem.

Best, Jonathan

On Nov 25, 2020, at 8:00 PM, andrewcztrack notifications@github.com wrote:



Hi @sbarratthttps://github.com/sbarratt !!

When i run the sector example i get the below -

In the training set: Market conditions average of 1.2664 data points. The most populated market condition has 38 data points. 1395 market conditions have no data. Traceback (most recent call last): File "sectors.py", line 91, in prob.solve(verbose=False) File "/home/andrewcz/miniconda3/envs/mlfinll/lib/python3.7/site-packages/cvxpy/problems/problem.py", line 396, in solve return solve_func(self, *args, **kwargs) File "/home/andrewcz/miniconda3/envs/mlfinll/lib/python3.7/site-packages/cvxpy/problems/problem.py", line 753, in _solve self, data, warm_start, verbose, kwargs) File "/home/andrewcz/miniconda3/envs/mlfinll/lib/python3.7/site-packages/cvxpy/reductions/solvers/solving_chain.py", line 326, in solve_via_data solver_opts, problem._solver_cache) File "/home/andrewcz/miniconda3/envs/mlfinll/lib/python3.7/site-packages/cvxpy/reductions/solvers/conic_solvers/mosek_conif.py", line 233, in solve_via_data task.optimize() File "/home/andrewcz/miniconda3/envs/mlfinll/lib/python3.7/site-packages/mosek/init.py", line 7627, in optimize raise Error(rescode(res),msg) mosek.Error: rescode.err_missing_license_file(1008): License cannot be located. The default search path is ':/home/andrewcz/mosek/mosek.lic:

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/cvxgrp/strat_models/issues/3#issuecomment-734044757, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AA2KFDJ52Z44QK5PL72AA5TSRXAFTANCNFSM4UDDXW4A.

andrewcztrack commented 3 years ago

Hi @jonathantuck @sbarratt !!

Thank you! much appreciated! Is there an open source solver that can I can use for the optimisation?

@jonathantuck is there anyway to make the weights a minimum of 5% for example, so as to get non-zero weights in the optimisation?

Kind regards and thanks, Andrew

jonathantuck commented 3 years ago

You must use a solver that can handle SDPs. SCS is an open-source solver that you could use. For a full list compatible with CVXPY, see here.

I'm not entirely sure what you're asking about in your second question. Could you clarify?

andrewcztrack commented 3 years ago

Hi @jonathantuck !

Thank you! In terms of changing the solver, do i just have to change these two lines?

    prob = cp.Problem(cp.Minimize(obj), cons_sm)
    prob_common = cp.Problem(cp.Minimize(obj_common), cons_common)

    prob.solve(solver="SCS") 
    prob_common.solve(solver="SCS") 

So I was wondering if could set a constraint for the optimization, that every weight of the portfolio has to be at least 5% of the original capital ie no weight of the solved optimization is less than 5%.

Kind regards and sincere thanks, Andrew

andrewcztrack commented 3 years ago

Hi @jonathantuck !! I hope your well.

i tried replacing the above code and got the below output -

(mlfinll) [andrewcz@andrewcz examples]$ ls
__pycache__  cardio.py  crime.py  data  elections.py  figs  house.py  mesothelioma.py  sectors.py  utils.py  weather.py
(mlfinll) [andrewcz@andrewcz examples]$ python sectors.py 
In the training set:
        Market conditions average of 1.2664 data points.
        The most populated market condition has 38 data points.
        1395 market conditions have no data.
Traceback (most recent call last):
  File "sectors.py", line 91, in <module>
    prob.solve(verbose=False)
  File "/home/andrewcz/miniconda3/envs/mlfinll/lib/python3.7/site-packages/cvxpy/problems/problem.py", line 396, in solve
    return solve_func(self, *args, **kwargs)
  File "/home/andrewcz/miniconda3/envs/mlfinll/lib/python3.7/site-packages/cvxpy/problems/problem.py", line 753, in _solve
    self, data, warm_start, verbose, kwargs)
  File "/home/andrewcz/miniconda3/envs/mlfinll/lib/python3.7/site-packages/cvxpy/reductions/solvers/solving_chain.py", line 326, in solve_via_data
    solver_opts, problem._solver_cache)
  File "/home/andrewcz/miniconda3/envs/mlfinll/lib/python3.7/site-packages/cvxpy/reductions/solvers/conic_solvers/mosek_conif.py", line 233, in solve_via_data
    task.optimize()
  File "/home/andrewcz/miniconda3/envs/mlfinll/lib/python3.7/site-packages/mosek/__init__.py", line 7627, in optimize
    raise Error(rescode(res),msg)
mosek.Error: rescode.err_missing_license_file(1008): License cannot be located. The default search path is ':/home/andrewcz/mosek/mosek.lic:'.
(mlfinll) [andrewcz@andrewcz examples]$ 
jonathantuck commented 3 years ago

Based on your error message, you are still using MOSEK as your solver, it looks like you did not replace prob.solve(verbose=False) with prob.solve(verbose=False, solver="SCS") on line 91.

andrewcztrack commented 3 years ago

@jonathantuck It worked!! thank you :)!