Second-order cone programming (SOCP) offers a robust and efficient way of solving several types of convex problems, including convex quadratically constrained quadratic programming (QCQP) problems. That is the reason why it can be highly utilized in a broad range of fields, like  finance. At Mark 29.3 of the NAG Library, NAG introduces a performance update to the SOCP solver (nag_opt_handle_solve_socp_ipm) which has been shown to be particularly effective for portfolio optimization.

### 1. SOCP in the NAG Library Introduction

Second-order cone programming is one of the main methods for solving QCQP problems, which arises in applications such as portfolio construction. The standard form convex QCQP problem is:

$\begin{array}{cc}\underset{x\in {ℝ}^{n}}{\text{minimize}}\hfill & \frac{1}{2}{x}^{T}{Q}_{0}x+{r}_{0}^{T}x\hfill \\ \\ \text{subject to}\hfill & \frac{1}{2}{x}^{T}{Q}_{i}x+{r}_{i}^{T}x+{s}_{i}\le 0\phantom{\rule{1em}{0ex}}\mathrm{for}\phantom{\rule{0.33em}{0ex}}i=1,\dots ,m,\hfill \\ \\ \hfill & \mathit{Ax}=b,\hfill \end{array}$

where $$Q_{o},…, Q_{m}$$ are positive semidefinite $$n$$ x $$n$$ matrices.

Figure 1: Feasible region of an SOCP problem with three variables.

The feasible region of an SOCP problem (which may, for instance, be a transformed QCQP problem) can be seen in Figure 1. The feasible region here is the intersection of the green polyhedron and a cone. The curve represents the added quadratic information which makes SOCP more complicated, but at the same time more powerful than LP.

In terms of the implementation of NAG’s SOCP solver, a path-following homogeneous self-dual algorithm is used. This is both robust and efficient and can detect infeasibility and unboundedness of the model. Also, NAG exploits the sparsity pattern of the problem thoroughly which makes the solver efficient, especially on large and sparse problems. For more details on implementation, see the NAG Library routine documentation for NAG SOCP solver nag_opt_handle_solve_socp_ipm [1].

### 2. Usage of SOCP in Portfolio Optimization

It is rare that a second-order cone (SOC) would appear naturally in the model, yet through a model reformulation, many portfolio optimization problems and constraints can be handled by SOCP. We discuss several of these below, for more examples see [2].

#### 2.1 Optimization with norms

The leverage constraint:

$\parallel x{\text{∥}}_{1}=\sum _{i=1}^{n}|{x}_{i}|\le L\phantom{\rule{1em}{0ex}}⟺\phantom{\rule{1em}{0ex}}\sum _{i=1}^{n}{s}_{i}\le L,\left({s}_{i},{x}_{i}\right)\in {K}_{q}^{2},\mathit{i}=1,\dots ,n.$

The above norm constraint can be viewed as a special case of general p-norm constraint on a vector $x\in {ℝ}^{n}$ defined as 

$\parallel x{\text{∥}}_{p}:={\left(\sum _{i=1}^{n}|{x}_{i}{\text{|}}^{p}\right)}^{\phantom{\rule{-0.17em}{0ex}}1∕p}\le t,$

(1)

Where $$p = l / m$$ is a positive rational number with $$l ≥ m$$. Inequality constraints (1) have SOC representation since they are equivalent to inequalities involving rational powers.

The tracking error constraint

$\frac{1}{2}{x}^{T}\mathit{Px}+{q}^{T}x+r\le 0$

(2)

where $$P$$ ∈ $$S^n$$ is a positive semidefinite matrix is common in portfolio optimization. Using routines handle_set_qconstr (e04rs) and handle_set_qconstr_fac (e04rt) introduced at Mark 27.1 of the NAG Library, users can easily define quadratic objective functions and/or constraints and seamlessly integrate them with other constraints. Then what will happen under the hood is as follows. Assume the matrix $$P$$ has factorization $$P = F^TF$$, (2) has an equivalent SOC representation as

$t+{q}^{T}x+r=0,\left(t,1,\mathit{Fx}\right)\in {K}_{r}^{n+2}$

since $$(1 / 2)x^TPx ≤ t$$ is equivalent to $$|| Fx||^2_{2} ≤ 2t$$. Thus, adding auxiliary variables $$y = Fx$$ will transform the quadratic constraint into a standard cone constraint.

For more details, see our mini article on QCQP and the python examples on portfolio optimization involving quadratic functions.

#### 2.3 More second-order cone representable functions

We have mentioned important SOC-representable functions above yet many more problems and constraints from portfolio optimization are SOC-representable. We list some below.

• Maximize Sharpe ratio:
$\mathrm{max}\frac{{\mu }^{T}x}{\sqrt{{x}^{T}\mathrm{\Sigma }x}}.$
• Holding and budget constraints:

$0\le x\le u,\phantom{\rule{1em}{0ex}}{e}^{T}x=b,$

where $$e$$ is the vector of all ones.

• Maximum position constraint:
$\mathrm{max}|x|\le m.$
• Market impact cost:
${w}^{T}|x-{x}_{0}{\text{|}}^{\eta }\le {u}_{M}.$

We encourage users to exploit their models thoroughly to reach a SOC-equivalent problem, thereby making the most of the versatility and practical performance of the NAG SOCP solver nag_opt_handle_solve_socp_ipm.

### 3. Performance of NAG SOCP solver

In this section, we show the performance of the NAG SOCP solver from the NAG Library for Python together with the NAG SOCP solver called from CVXPY and the default solver in CVXPY. While we used Python, the same NAG SOCP solver is available in many other environments (C, Java, Fortran, etc.). All solvers were at default settings with accuracy at $1{0}^{-8}$ and in single-threaded mode.

The solvers were used on $10$ classic portfolio optimization problems ranging from 1100 to 2900 assets. Randomly generated data was used in a Markowitz model whose objective involved a large covariance matrix and was subject to a long-only constraint and a budget constraint.

The computational time comparison can be found in Figure 2. Here it can be seen that the NAG solver called from CVXPY is faster than the standard CVXPY solver. Further, for smaller problems, the NAG solver called from Python is at least twice as fast as standard CVXPY, becoming as much as five times faster for larger problems.

Figure 2: Comparison of time on $10$ portfolio optimization problems.

In conclusion, SOCP is widely used in finance due to its powerful nature. At Mark 29.3, NAG introduces an updated SOCP solver (nag_opt_handle_solve_socp_ipm) that is highly performant on portfolio optimization problems. In some cases, reformulation of your problem is required, yet it is worth the effort. For further examples and reading visit our GitHub Local optimization page.

The solver is available for multiple languages and environments including C and C++, Python, Java, .NET and Fortran, on Windows, Linux and MacOS. See the Getting Started page for how to download and install.

#### Please fill out all of the following questions

What solvers are you interested in trying? (multiple choice)