# Quadratic Program solver for Portfolio Optimization

**URL:** <https://discourse.julialang.org/t/quadratic-program-solver-for-portfolio-optimization/93264>\
**Category:** Finance and Economics\
**Created:** [January 20, 2023, 1:41pm UTC](https://discourse.julialang.org/t/quadratic-program-solver-for-portfolio-optimization/93264 "2023-01-20T13:41:38Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![maxchendt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/maxchendt/32/42976_2.png) [@maxchendt](https://discourse.julialang.org/u/maxchendt)\
**Post date:** [January 20, 2023, 1:41pm UTC](https://discourse.julialang.org/t/quadratic-program-solver-for-portfolio-optimization/93264/1 "2023-01-20T13:41:38Z")

</div>

Any recommendations? For portfolio selection problem with equality and inequality constraints, and lower and upper bounds for portfolio weights.

So far, what I have tested ( I do not test commercial solver like Gurobi or CPLEX)

- **Clarabel** : fast and robust, but a heavy weapon (this package eats 1G in `~/.julia` )
- **GeneralQP** : fast and light. but an initial feasible point should be provided by user (can be obtained e.g. by performing Phase-I Simplex on the polyhedron Ax ≤ b). With this additional cost, is not as fast as _Clarabel_.
- **QPDAS** : positive-definite quadratic programming problem. Most of time fail by _‘matrix is not positive definite; Cholesky factorization failed’_
- **HiGHS** : the QP functionality is added recently, but mostly fail on my data
- **OSQP** : not Julia native, do not support `BigFloat`. The default setting should be tuned for portfolio optimization.
- **COSMO** : _'Solver reached iteration limit ’_ for my data, have to set `max_iter=N*10000`. And we [can’t install COSMO & Clarabel.jl together](https://github.com/oxfordcontrol/COSMO.jl/issues/161)
- **RipQP** : never succeed, even its examples on [Tutorial · RipQP.jl](https://juliasmoothoptimizers.github.io/RipQP.jl/stable/tutorial/)

---

<div class="post-metadata">

**Author:** ![sylvaticus](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sylvaticus/32/203883_2.png) [@sylvaticus](https://discourse.julialang.org/u/sylvaticus)\
**Post date:** [January 20, 2023, 2:01pm UTC](https://discourse.julialang.org/t/quadratic-program-solver-for-portfolio-optimization/93264/2 "2023-01-20T14:01:03Z")

</div>

Weakly related: in C++, provides the optimal portfolio conditional to a given risk aversion:

[https://lobianco.org/antonello/personal/portfolio/portopt](https://lobianco.org/antonello/personal/portfolio/portopt)

---

<div class="post-metadata">

**Author:** ![baggepinnen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/baggepinnen/32/693_2.png) [@baggepinnen](https://discourse.julialang.org/u/baggepinnen)\
**Post date:** [January 20, 2023, 2:29pm UTC](https://discourse.julialang.org/t/quadratic-program-solver-for-portfolio-optimization/93264/3 "2023-01-20T14:29:37Z")

</div>

Registered yesterday

> **[GitHub - PharosAbad/LightenQP.jl: A pure Julia implementation of OOQP](https://github.com/PharosAbad/LightenQP.jl)**
>
> A pure Julia implementation of OOQP . Contribute to PharosAbad/LightenQP.jl development by creating an account on GitHub.

The Readme states

> Fast: beat Clarabel for efficient portfolio seeking

---

<div class="post-metadata">

**Author:** ![Paul\_Soderlind](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/paul_soderlind/32/1753_2.png) [@Paul\_Soderlind](https://discourse.julialang.org/u/Paul_Soderlind)\
**Post date:** [January 20, 2023, 2:42pm UTC](https://discourse.julialang.org/t/quadratic-program-solver-for-portfolio-optimization/93264/4 "2023-01-20T14:42:39Z")

</div>

I use OSQP for such problems. Seems quick and versatile. Also took Clarabel for a spin, and it also did a very good job. “First time to solution” was a bit of an issue with Clarabel, but maybe that’s different on 1.9.

---

<div class="post-metadata">

**Author:** ![maxchendt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/maxchendt/32/42976_2.png) [@maxchendt](https://discourse.julialang.org/u/maxchendt)\
**Post date:** [January 20, 2023, 2:46pm UTC](https://discourse.julialang.org/t/quadratic-program-solver-for-portfolio-optimization/93264/5 "2023-01-20T14:46:14Z")

</div>

“First time to solution”: do you mean that a first time run takes 19 seconds, and a second time run takes just 0.03 seconds?

---

<div class="post-metadata">

**Author:** ![Paul\_Soderlind](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/paul_soderlind/32/1753_2.png) [@Paul\_Soderlind](https://discourse.julialang.org/u/Paul_Soderlind)\
**Post date:** [January 20, 2023, 3:16pm UTC](https://discourse.julialang.org/t/quadratic-program-solver-for-portfolio-optimization/93264/6 "2023-01-20T15:16:21Z")

</div>

yes. OSQP is clearly quicker.

---

<div class="post-metadata">

**Author:** ![maxchendt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/maxchendt/32/42976_2.png) [@maxchendt](https://discourse.julialang.org/u/maxchendt)\
**Post date:** [January 29, 2023, 11:05am UTC](https://discourse.julialang.org/t/quadratic-program-solver-for-portfolio-optimization/93264/7 "2023-01-29T11:05:31Z")

</div>

The best, undoubtedly, _EfficientFrontier_ is the best

> **[GitHub - PharosAbad/EfficientFrontier.jl: Entire Efficient Frontier by...](https://github.com/PharosAbad/EfficientFrontier.jl)**
>
> Entire Efficient Frontier by Status-Segment Method - GitHub - PharosAbad/EfficientFrontier.jl: Entire Efficient Frontier by Status-Segment Method

_EfficientFrontier_ is an analytical solver, the numerical solvers, such as [OSQP](https://osqp.org/), [Clarabel](https://github.com/oxfordcontrol/Clarabel.jl), and [LightenQP](https://github.com/PharosAbad/LightenQP.jl) are in the second tier.

see [Speed and Accuracy · PharosAbad/LightenQP.jl Wiki · GitHub](https://github.com/PharosAbad/LightenQP.jl/wiki/Speed-and-Accuracy) for more information.

---

<div class="post-metadata">

**Author:** ![klwlevy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/klwlevy/32/25272_2.png) [@klwlevy](https://discourse.julialang.org/u/klwlevy)\
**Post date:** [January 30, 2023, 7:02am UTC](https://discourse.julialang.org/t/quadratic-program-solver-for-portfolio-optimization/93264/8 "2023-01-30T07:02:34Z")

</div>

Is there anything available if we also add integer constraints?

---

<div class="post-metadata">

**Author:** ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)\
**Post date:** [January 30, 2023, 8:56am UTC](https://discourse.julialang.org/t/quadratic-program-solver-for-portfolio-optimization/93264/9 "2023-01-30T08:56:53Z")

</div>

> Is there anything available if we also add integer constraints?

There’s quite a few options.

Commercial:

- [GitHub - jump-dev/CPLEX.jl: Julia interface for the CPLEX optimization software](https://github.com/jump-dev/CPLEX.jl)
- [GitHub - jump-dev/Gurobi.jl: Julia interface for Gurobi Optimizer](https://github.com/jump-dev/Gurobi.jl)

Open source

- Bonmin via AmplNLWriter.jl: [GitHub - jump-dev/AmplNLWriter.jl: Julia interface to AMPL-enabled solvers](https://github.com/jump-dev/AmplNLWriter.jl#jll-packages)
- [GitHub - jump-dev/Pavito.jl: A gradient-based outer approximation solver for convex mixed-integer nonlinear programming (MINLP)](https://github.com/jump-dev/Pavito.jl)
- [GitHub - jump-dev/Pajarito.jl: A solver for mixed-integer convex optimization](https://github.com/jump-dev/Pajarito.jl)
- [GitHub - lanl-ansi/Juniper.jl: A JuMP-based Nonlinear Integer Program Solver](https://github.com/lanl-ansi/Juniper.jl)
- [GitHub - lanl-ansi/Alpine.jl: A Julia/JuMP-based Global Optimization Solver for Non-convex Programs](https://github.com/lanl-ansi/Alpine.jl)

If you have a license, Gurobi is probably the best.
