Initializing help system before first use

# MIQP

Topics covered in this section:

- Implementation with Mosel
- Analyzing the solution

We now wish to express the fact that at most a given number MAXNUM of different assets may be selected into the portfolio, subject to all other constraints of the previous QP model. In Chapter Mixed Integer Programming we have already seen how this can be done, namely by introducing an additional set of binary decision variables buys that are linked logically to the continuous variables:

∀ s ∈ SHARES: fracs ≤ buys

Through this relation, a variable buys will be at 1 if a fraction fracs greater than 0 is selected into the portfolio. If, however, buys equals 0, then fracs must also be 0.

To limit the number of different shares in the portfolio, we then define the following constraint:

∑s ∈ SHARES buys ≤ MAXNUM

## Implementation with Mosel

We may modify the previous QP model or simply add the following lines to the end of the QP model in the previous section: the problem is then solved once as a QP and once as a MIQP in a single model run.

     declarations
      buy: array(SHARES) of mpvar       ! 1 if asset is in portfolio, 0 otherwise
     end-declarations

    ! Limit the total number of assets
     sum(s in SHARES) buy(s) <= MAXNUM

     forall(s in SHARES) do
      buy(s) is_binary
      frac(s) <= buy(s)
     end-do

    ! Solve the problem
     minimize(Variance)

     writeln("With a target of ", TARGET," and at most ", MAXNUM,
             " assets, minimum variance is ", getobjval)
     forall(s in SHARES) writeln(s, ": ", getsol(frac(s))*100, "%")

When executing the MIQP model, we obtain the following solution output:

    With a target of 9 and at most 4 assets,
     minimum variance is 1.248761905
    1: 30%
    2: 20%
    3: 0%
    4: 0%
    5: 23.80952381%
    6: 26.19047619%
    7: 0%
    8: 0%
    9: 0%
    10: 0%

With the additional constraint on the number of different assets the minimum variance is more than twice as large as in the QP problem.

## Analyzing the solution

If we enable the Optimizer logging output display by setting XPRS_VERBOSE to 'true' we see the following information:

Figure 8.2: Detailed MIQP solution information

This is quite similar to the MIP statistics.

Just as with linear problems, the root solving as continuous problem is followed by a root cutting and heuristics phase (several integer feasible solutions are found by the heuristics):

Figure 8.3: MIQP root cutting and heuristics

One more integer feasible solution is found during the Branch-and-Bound search. The search has been completed, this means that optimality of this solution has been proven (we may have chosen to stop the search, for example, after a given number of nodes, in which case it may not be possible to prove optimality or even to find the best solution).

Figure 8.4: MIQP Branch-and-Bound search

Parent Topic Quadratic Programming

© 2001-2026 Fair Isaac Corporation. All rights reserved. This documentation is the property of Fair Isaac Corporation (“FICO”). Receipt or possession of this documentation does not convey rights to disclose, reproduce, make derivative works, use, or allow others to use it except solely for internal evaluation purposes to determine whether to purchase a license to the software described in this documentation, or as otherwise set forth in a written software license agreement between you and FICO (or a FICO affiliate). Use of this documentation and the software described in it must conform strictly to the foregoing permitted uses, and no other use is permitted.