Skip to content
All library documents

Encoding Linear Turnover Costs in Mean–Variance Optimization

Article Quant Q&A · Author: qfd

Summary

The document discusses adding a penalty proportional to absolute portfolio changes to a mean–variance objective, while retaining constraints such as long-only holdings and fully invested weights. Its central modeling idea is to represent each position change with nonnegative variables for increases and decreases. This converts the absolute-value turnover penalty into linear terms, allowing the objective to be expressed as a quadratic program.

The answer describes expanding the optimization variables and covariance matrix, then incorporating the return and cost terms into the linear objective vector. It also notes that portfolio constraints must be rewritten in terms of the new variables. The response is conceptual rather than a complete MATLAB implementation, and it explicitly cautions readers to verify the signs and formulation. Some stated constraints and transformations are not fully consistent with the original long-only, fully invested setup, so the formulation should be checked before use.

Key ideas

  • A linear cost on absolute weight changes introduces absolute values into a mean–variance objective.
  • Representing increases and decreases separately can remove the absolute values and preserve a quadratic-program structure.
  • The expanded model must adjust the objective and covariance matrix to match the new variables.
  • Budget and long-only constraints need careful translation into the transformed formulation.
  • The proposed signs and constraints require independent verification before implementation.

Tags

Full text
# formulating MVO with costs


# formulating MVO with costs












I am trying to formulate this simple MVO utility function with a linear transaction cost penalty added using Quadprog in MATLAB

tcost = 0.001; lambda = 4; mu = vector of expected returns (say 4x1) S = covariance matrix (4x4)

max w'*mu - lambda *w'Sw - lambda_TC * tcost *sum(abs(w(i) - w0(i))

I understand in order to be linear we can replace w(i) - w0(i) with a variable y(i) replacing the above equation to be

max w'*mu - lambda *w'Sw - lambda_TC * tcost *sum(y(i))

and we add the constraints y(i)>= w(i) - w0(i) and y(i)>= - (w(i) - w0(i))

I additionally have a long only constraint and the sum of the weights should sum to 1

I am unsure how to formulate this in quadprog in MATLAB. Any help will be appreciate.

Thanks very much!

## Answer by rhaskett (score 2, accepted)

https://quant.stackexchange.com/a/15407

I'm not that familiar with MATLAB. However, in quadratic programming the main issue I've found is setting up the problem correctly and then the coding becomes much easier.

As you noted this problem can be expressed as a quadratic cone problem and solved by quadprog but a good amount of more work needs to be done to get this in the correct form.

- You should convince yourself that under the change of variables y = w - w0 you suggested that the problem actually becomes the below with sum(y) = 0 (assuming sum(x0) = 1) and we no longer have to worry about w. max y'*mu - lambda * y'Sy - lambda_tc * tcost * sum(abs(y)) + constant

You can calculate that constant if you want but because we are maximizing it doesn't matter. The problem is this problem is still not in a quadradic programming form because it still has a absolute value function.

- The next step is to get rid of the abs(). The trick here is to double the number of optimization variables as you allude to in the question. We call y = (y_plus - y_minus)/2 where now we have two new constraints y_plus >= w - w0 and y_minus >= -(w - w0).

- This appears to make the problem more complicated, but note if we define z to be the vector of (y_plus, y_minus) for 8 variables we can rewrite the problem again as the below with sum(z) = 0. max z'*mu - lambda * z'Sz - lambda_tc * tcost * sum(z)

where mu and S have extended to double their original size. mu is just repeated twice with a sign flip (now has 2*4 members) and H now has two block diagonal S matrices and block zeros on the off diagonals (8 by 8 matrix in total). However, now we have removed the absolute value from the problem!

- To put this in standard form we just need to combine the linear terms in z. So the equations for 'f' in quadprod would look like (Please double check my signs here) (mu_i - lambda_tc * tcost) * yplus_i and (mu_i + lambda_tc * tcost) * yminus_i

- Now this problem can be put in the quadprog with the above 'f' and extended (doubled-size) 'S' as 'H'. Aeq,beq can constrain sum(z) = 0 and A,b constrain each yplus_i>0 and yminus_i<0 as y_plus are changes to w that are positive and y_minus are changes that are negative.

Shown in full with attribution under the source's licence. Licence: CC BY-SA 4.0 (Stack Exchange)

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.