Optimal Portfolio Liquidation

Mixed Integer Programming model to hit a cash or fiscal target while respecting FIFO and Spanish tax rules.

Problem Definition

In Spain, when an investor wishes to withdraw a specific amount from their investment portfolio they must evaluate the fiscal impact of the operation. The fiscal impact refers to the tax consequences of the transaction. If the fiscal impact is positive, meaning that gains are realized, the investor is required to pay taxes on these gains. Conversely, if the fiscal impact is negative, the realized losses can be offset against other capital gains.

In this work we cover two distinct needs that investors generally have. First, they may seek to define specific criteria for the fiscal impact they wish to generate when executing a withdrawal of a known amount. Second, an investor may wish to generate a predetermined fiscal impact, such as realizing specific gains or losses for tax purposes, while immediately reinvesting the funds back into their portfolio. This financial operations are further complicated by the regulatory requirement, which mandates the use of the First In, First Out (FIFO) rule. Assets within an instrument must be sold in the order they were acquired, limiting the flexibility to choose which specific transactions to sell first.

I decided to tackle this problem using a Mixed Integer Programming approach for portfolio liquidation.


Methodology

The Mixed Integer Programming (MIP) models provide solutions by determining the optimal set of transactions to liquidate. The most important decision variable in this model is \(X_{i,j}\), which represents the number of shares sold from transaction i of instrument j.

This means that for any \(X_{i,j}>0\), we must interpret the solution as implying that \(X_{i-1,j}=N_{i-1,j}\), where \(N_{i-1,j}\) represents the total number of available shares for transaction i-1. Similarly, \(X_{i-2,j},X_{i-3,j},\ldots\) would also equal their corresponding \(N_{i-2,j},N_{i-3,j},\ldots\), respectively.

Each instrument is segmented by transaction (FIFO). Decision variables choose a single active segment per instrument; precomputed accumulators carry net, fiscal impact, and sells to the boundary.

Two models main backbones:

  • 1) Withdraw D (optimize fiscal impact)
    Maximize/minimize fiscal impact \(\sum_{i,j} X_{ij}(P_{ij}-C_{ij}) + Y_{ij}F_{ij}\) s.t. \(\sum X_{ij}P_{ij} + A_{ij}Y_{ij} - Z_{ij} I_j = D\)
  • 2) Generate fiscal target F (minimize liquidation value)
    Minimize \(\sum X_{ij}P_{ij} + A_{ij}Y_{ij}\) s.t. \(\sum X_{ij}(P_{ij}-C_{ij}) + Y_{ij}F_{ij} = F\)

Variables

  • \(X_{ij}\) Continuous variable indicating the number of shares sold from the i-th transaction of the j-th instrument.
  • \(Y_{ij}\) Binary variable, equal to 1 if any share is sold from the i-th transaction of the j-th instrument, 0 otherwise.
  • \(T_{ij}\) Binary variable, equal to 1 if there is a taxable gain associated with the i-th transaction of the j-th instrument.
  • \(Z_{ij}\) Continuous variable representing the taxable profit from the i-th transaction of the j-th instrument (zero if no tax is triggered).

Parameters

  • \(K\) Total number of instruments.
  • \(M_j\) Number of transactions for the j-th instrument.
  • \(I_j\) Tax rate applied to the j-th instrument.
  • \(N_{ij}\) Available number of shares for the i-th transaction of the j-th instrument.
  • \(P_{ij}\) Selling price per share for the i-th transaction of the j-th instrument.
  • \(C_{ij}\) Cost basis (purchase price) per share for the i-th transaction of the j-th instrument.
  • \(F_{ij}\) Cumulative fiscal impact up to and including the i-th transaction for the j-th instrument.
  • \(A_{ij}\) Accumulated liquidation value up to and including the i-th transaction of the j-th instrument (sum of sold shares times price).

Subscripts

  • \(i=1,2,\ldots,M_j\) Index of transactions per instrument.
  • \(j=1,2,\ldots,K\) Index of instruments.