Numerical Solution
A method page states the problem a method solves. This page states how the answer is computed and checked: which numerical solver runs, what counts as a solution, how small numbers are treated, and when a method returns nothing rather than a portfolio it cannot stand behind.
Problem Classes
Most methods are convex programs solved by an interior-point or simplex-type solver. The class of the program decides which solvers can take it:
| Class | Shape | Examples |
|---|---|---|
| Linear program (LP) | Linear objective, linear constraints. | MinCVaR, MinCDaR and the constraint feasibility checks |
| Quadratic program (QP) | Quadratic objective, linear constraints. | MinVol, MaxQuadraticUtility and the other mean-variance forms |
| Second-order cone | A norm in the objective or a constraint. | A tracking-error limit, the worst-case mean term of RobustMVO |
| Exponential cone | A logarithm or an entropy term. | Kelly, MinEVaR and MinEDaR |
The exponential cone is strictly narrower than the second-order cone: a solver that takes one does not necessarily take the other. A program that needs it declares it, so it is never handed to a solver that cannot compile it. Some methods are not programs of this kind at all: HRP and HERC allocate by recursion over a cluster tree, inverse volatility and equal weight are closed forms, and the Critical Line Algorithm pivots through the turning points of the frontier.
The Solver Fallback Order
Each method declares an ordered list of preferred solvers. The run tries them in exactly that order. After them it tries every other installed open-source solver that can take the program's class. The appended solvers never move ahead of a declared one, so adding a solver cannot change which one wins on a method that already solves. A commercial solver is never added automatically.
A solver that raises an error, or that returns any status other than optimal or optimal_inaccurate, counts as a failure, and the next solver runs. An infeasible verdict from one solver is therefore not final until every eligible solver has said the same. When every solver fails, the error names each solver and the reason it gave, not only the last one.
optimal_inaccurate is accepted because the tolerance checks below decide whether the answer is usable. A solution that is inaccurate enough to matter fails those checks.
From Solver Output to Stored Weights
A solver returns a vector that satisfies its own tolerances, typically within about 1e-6 of each bound on a hard problem. The stored weights are cleaned and then checked. The two paths differ, because rounding that is harmless without constraints can push a weight across a hard limit.
Without constraints
- The mean-variance methods that solve through PyPortfolioOpt set every weight below 1e-4 (0.01%) to zero and round the rest to five decimals.
- A long-only method that returns a weight below -1e-8 is refused with a no-short-sale error. A weight between -1e-8 and 1e-8 becomes zero.
- The remaining weights are divided by their sum, so they sum to one.
With constraints
- No rounding: the raw solver vector is used.
- A weight below -1e-4 is refused as a short position. A weight below 1e-9 becomes zero, and an excluded security (an upper bound of zero) is set to exactly zero.
- The weights are divided by their sum.
- Every rule is checked against the result with a tolerance of 1e-5, a tenth of a basis point. A breach larger than that fails the method with the rule and the amount named. The weights are never repaired toward compliance.
The same check runs a second time on the weights the run stores, after any security without price coverage is dropped and the rest are rescaled. Dropping a security raises every other weight, so a ceiling that held at the solve can fail here, and the run refuses rather than stores a breach. See Constraints for the feasibility program that runs before any solve.
What the tolerances mean for a reader
A weight of zero in a result can be a true zero or a weight below 0.01% that was set to zero. A sector total reported at exactly its limit can differ from the limit by up to 1e-5. Neither difference is large enough to matter for an allocation, and both are smaller than any limit a rule can express.
When the Risk-Free Rate Leaves Nothing to Optimize
A tangency (maximum Sharpe) objective is undefined when no asset's expected return exceeds the risk-free rate. For MVO, BlackLitterman, HMMRegimeMVO, EWMAMVO, ResampledMVO, MaximumDiversification, StackingOptimization and the maximum-Sharpe arm of the Critical Line Algorithm, the run then optimizes against a lowered rate:
The result is marked as degraded and records the requested rate, the applied rate, the highest expected return and . The reported Sharpe ratios still use the requested rate. Under constraints the run also asks whether any portfolio that satisfies them has an expected return above the rate. When none does, the method does not run, and the run states the reason instead of a bare solver verdict of infeasible.
A Failed Method Does Not Fail the Run
Each method runs in isolation. A method that cannot solve, that breaches a rule, or whose inputs are undefined is recorded in method_errors with its reason, and the other methods still return their portfolios. A run fails only when every requested method fails.
A method also refuses rather than substitutes. A hierarchical method does not change its cluster configuration to fit a portfolio it cannot handle, and a method that cannot enforce a family of rule the request uses does not run at all, rather than returning weights that ignore the rule.
References
- Boyd, S., & Vandenberghe, L. (2004). Convex Optimization. Cambridge University Press. doi:10.1017/CBO9780511804441.
- Diamond, S., & Boyd, S. (2016). "CVXPY: A Python-Embedded Modeling Language for Convex Optimization." Journal of Machine Learning Research, 17(83), 1-5. jmlr.org/papers/v17/15-408.html.
- Huangfu, Q., & Hall, J. A. J. (2018). "Parallelizing the Dual Revised Simplex Method." Mathematical Programming Computation, 10(1), 119-142. doi:10.1007/s12532-017-0130-5.
- Goulart, P. J., & Chen, Y. (2024). "Clarabel: An Interior-Point Solver for Conic Programs with Quadratic Objectives." arXiv:2405.12762. arxiv.org/abs/2405.12762.
Not investment advice. Past performance is not indicative of future results.