# Portfolio optimization subject to transaction costs

Mean-Variance portfolio optimization attracted lots of attention in this forum so far. I am interested in the effect of incorporating transaction costs into the decision framework and I would like to obtain 'optimal' portfolios. In other words, approaches which are still capable of being solved using quadratic programing by constraining maximum turnover are not what I am looking for. Just recently, this question was solved with the help of the community in order to obtain optimal portfolios if we consider quadratic transaction costs. However, what happens if we come up with transaction costs in a V-shape, which means we pay a fee proportionally to the sum of absolute rebalancing: $$TC(\omega_\text{new}) \propto ||\omega_\text{new}-\omega_\text{old}||.$$ This (rather old) paper by Atsushi Yoshimoto handles exactly the optimization problem I want to solve: $$\omega_\text{new} = \arg\max {\omega'\mu - \sum_{i=1}^N c_i -\lambda \omega'\Sigma\omega} \\ \text{s.t.} c_i = k(d^+ _{i,t} + d^- _{i,t}), \forall i \\ \omega_{i}-\omega_{old} = d_{i} ^+ - d_{i} ^-, \forall i \\ d_i ^+ d_i ^- =0, \forall i \\ d_i ^+, d_i ^- \geq 0 \forall i \\\omega'\iota=1$$ Intuitively speaking the optimization is doing the following: Given estimates of future returns $\mu$ and volatility $\Sigma$, we search for $\omega$ which maximizes our Certainty equivalent. This value is decreased with total transaction costs $\sum c$. Transaction costs occur if we rebalance our portfolio: Given we increase the share of wealth in one asset $i$, this affects $d_i ^+$ and, vice versa, if we decrease the share of wealth in one asset, this increases $d_i ^-$. Total rebalancing in asset $i$ is therefore $d_i ^+ +d_i ^-$. The constraint $d_i ^+ d_i ^- = 0$ ensures, that one cannot buy and sell simultaneously one asset (which should be clear). The last constraint requires that our new portfolio weights $\omega$ sum up to 1, therefore we are investing all the money into the available assets (I did not incorporate an additional short sell constraint here, opposed to Yoshimoto).

I would love to implement this optimization in R, Matlab, Python, whatever, but I do not understand the structure explained in this paper: All which is explained is that a nonlinear optimizer called GAMS/MINOS was used. I think, 20 Years after publishing there should certainly be a publicly available approach to to this, therefore I ask (i) does an implementation already exist? (ii) If not, how to do this properly?

EDIT: To show my first approach I worked out this small example for R. Hereby I neglect the estimation of the mean but only consider volatility timing:

library(alabama)
library(quantmod)

symbols <- c("MSFT","AAPL","MMM")
getSymbols(symbols,src='yahoo',from = '1995-01-01')
N <- length(symbols)

MSFT <-  to.monthly(MSFT)
AAPL <-  to.monthly(AAPL)
MMM <-  to.monthly(MMM)
returns <- data.frame(MSFT=diff(log(MSFT$MSFT.Adjusted)), AAPL=diff(log(AAPL$AAPL.Adjusted)),
MMM=diff(log(MMM$MMM.Adjusted))) returns <- na.omit(returns) names(returns) <- symbols mu <- rep(1,N) sigma <- cov(returns) lambda <- 4 costpara <- 50/10000 wold <- rep(1/N,N) fn <- function(w) -w%*%mu + costpara*sum(abs(w- wold))+lambda*t(w)%*%sigma%*%w heq <- function(w) return(sum(w)-1) out <- constrOptim.nl(par=wold, fn=fn,heq=heq) rbind(out$par,wold)

wnew 0.3333233 0.08347908 0.5831977
wold 0.3333333 0.33333333 0.3333333


However, I am not too familiar with numerical optimization, so can anyone confirm this approach is correct, or point out ways to improve the optimization?

• I don't understand how you actually solved the transaction cost issue: in your code, you set costpara = 50/10000, but this should be dependent on your final optimal solution, so it looks like you solved your problem by making it constant. Jun 6, 2020 at 12:23
• Thanks @JejeBelfort. Indeed the description may be somewhat vague: What I assume implicitly is that transaction costs are proportional to the amount of rebalancing $||w_\text{new} - w_\text{old}||$ with a fixed constant of proportionality of 50 basis points. This parameter is fixed ad hoc and determines the costs conditional on the weights. Jun 8, 2020 at 9:06
• Thanks for the precision @muffin1974! I am actually trying to formulate this problem into a quadratic programming one in order to solve it using cvxopt in python, but I don't know how to handle the mute variables $d_{i}^+$ and $d_{i}^-$ into the optimization problem (I am not even sure if this is mathematically possible!). Do you know where I can find some python code to achieve what you did? Jun 8, 2020 at 10:03
• Thanks @JejeBelfort! I am not aware of a Python Package, but I can refer (in a shameless act of self-promotion) to this paper in which we show that L1 and L2 like turnover penalization can be incorporated via standard Lasso- or Ridge-like penalized optimization for which I believe standard methods in Python should exist (for L2 penalization, there is a closed form solution anyhow). Hope that helps! Jun 9, 2020 at 14:00

What you do looks ok. But in practice how would you set costpara? This coud have a huge impact on your optimization.
So I would do something different. Define the buys $b_i>0$ and the sells $s_i>0$ then you have $$w_i = wold_i + b_i - s_i$$ or in other terms: $$w_i-wold_i - b_i + s_i = 0.$$ This is a linear equality that you cas use in your heq. Then you add a constraint $$\sum_{i=1}^n b_i + s_i \le T$$ for some turnover limit $T$. Then you make sure that the problem is optimized under a turnover constraint. Multipliying this $T$ by your cost of one percent sold or bought gives you control over transaction costs.