FAQs

Quadratic Programming FAQ: QP Optimization in Practice

Quadratic programming (QP) models costs and risk with squared terms. Learn when to use convex QP and MIQP.

FAQs

Quadratic Programming FAQ: QP Optimization in Practice

Quadratic programming (QP) models costs and risk with squared terms. Learn when to use convex QP and MIQP.

FAQs

Quadratic Programming FAQ: QP Optimization in Practice

Quadratic programming (QP) models costs and risk with squared terms. Learn when to use convex QP and MIQP.

Quadratic programming is a type of mathematical optimization problem where the objective or constraints include quadratic terms, often representing risk, smoothness, or squared error.  

In practical QP optimization work, those squared terms can capture realities that linear models approximate poorly, like variance in a portfolio, power losses, or deviation from targets. 

What is quadratic programming, in plain terms?

Quadratic programming (QP) chooses decision variables to optimize an objective that includes squared or cross-product terms. When quadratic terms appear in constraints as well, the problem is called quadratically constrained programming (QCP). Those quadratic terms let you model tradeoffs like risk vs. return, tracking error vs. service level, or smooth changes vs. aggressive moves. Many real systems have costs that grow faster than linearly, and QP captures that naturally.



When should I use QP instead of linear programming?

Use QP when the economics of the decision are not well represented by straight lines. Common triggers include:

  • Risk penalties (variance, tracking error) in finance and supply planning

  • Squared deviation from a target (quality, demand matching, setpoints)

  • Smoothness penalties (avoid sudden changes in production rates or controls)

  • Physical relationships that are inherently quadratic (power losses, flow dynamics)

 

If your costs and tradeoffs are truly linear or can be approximated acceptably with piecewise-linear terms, LP may remain simpler. Note that LP (linear programming) and MILP (mixed-integer linear programming) differ in whether integer variables are present; similarly, QP has continuous variants and mixed-integer variants (MIQP), so choose the formulation that matches your decision structure.



What is convex quadratic programming, and why does it matter?

Convex quadratic programming means the quadratic objective curves upward (for minimization problems), so any local optimum is also a global optimum. This property extends to convex quadratic constraints, where the feasible region forms a convex set. Convexity matters because it enables stronger algorithmic guarantees: in convex QP, when the solver finishes, you can trust that the result is globally optimal for the given data and model.

Importantly, Gurobi can solve both convex and non-convex quadratic programming problems to global optimality. Non-convex problems—where quadratic terms may create multiple local optima—are significantly more challenging and can require longer solution times, but Gurobi uses global optimization techniques such as spatial branch-and-bound to find provably optimal solutions, rather than settling for local optima.



What changes when integers are involved (MIQP)?

Mixed-integer quadratic programming (MIQP) combines quadratic objectives with yes/no or integer decisions, like selecting which facilities to open, which assets to include, or which machines to turn on. The integers introduce combinatorial complexity, so runtime depends heavily on model structure and data. For convex MIQP, the continuous relaxation provides strong bounds, while non-convex MIQP presents the combined challenge of both non-convexity and discrete decisions. 

Where does quadratic programming show up in portfolio optimization?

A classic use in portfolio optimization is balancing expected return against risk, where risk is represented by a quadratic form derived from asset covariances. The decision variables are asset weights, often with constraints like budget, leverage limits, sector bounds, and turnover limits. If you add discrete choices (for example, minimum lot sizes or cardinality limits), the model becomes MIQP.



What about energy and industrial systems?

In power and process operations, QP and QCP can model quadratic generation costs, transmission losses, or tracking objectives. Decisions might include dispatch levels across generators, storage charge/discharge, and ramping limits. The quadratic objective can encourage efficient, stable operation while linear and quadratic constraints enforce physics-based bounds and operational rules.



How do I know if my QP is well-posed and solvable?

Start by validating units, bounds, and data ranges. Poor scaling or missing bounds can produce numerically fragile models. Also check that constraints reflect physical limits, and that the quadratic terms represent the intended penalty (for example, whether cross terms imply interactions you truly want). For convex models, verify that your quadratic matrix is positive semi-definite (PSD); for non-convex models, understand that solution times may be significantly longer. Performance depends on model structure, data quality, and solver settings, so prototype with realistic data and measure solution time and quality.