1
$\begingroup$

I am trying to perform a standard portfolio optimization, but with a constraint to how much the final weights of the portfolio are allowed to deviate from a set of initial weights. I do this with the PortfolioAnalytics package and the following code is a MWE without any errors.

# load packages and data
library(quadprog)
library(PortfolioAnalytics)
data(edhec)
dat <- edhec[,1:4]

# add initial weights to initial portfolio
funds <- c("Convertible Arbitrage" = 0.4, "CTA Global" = 0.3, "Distressed Securities" = 0.2, "Emerging Markets" = 0.1)
init.portf <- portfolio.spec(assets=funds)

# standard constraints & objectives
init.portf <- add.constraint(portfolio=init.portf, type="box", min_w=0, min_sum=0.99, max_sum=1.01)
init.portf <- add.objective(portfolio=init.portf, type="return", name="mean") 
init.portf <- add.objective(portfolio=init.portf, type="risk", name="StdDev")

# TURNOVER CONSTRAINT (MATTER OF THIS THREAD)
init.portf <- add.constraint(portfolio=init.portf, type="turnover", turnover_target=0)

# optimize portfolio
opt.portf <- optimize.portfolio(R=dat, portfolio=init.portf, trace=TRUE, optimize_method="random")

# check the weights of optimized portfolio
print.default(opt.portf$weights)

turnover_target is 0, so the output weights should be the same as the input weights (0.4, 0.3, 0.2, 0.1) but instead they are equal weighted (0.25, 0.25, 0.25, 0.25). Equal weighted are the default initial weights, so somehow it seems like the initial weights I set up aren't recognized. However looking at the documentation of add.constraint or turnover_constraint doesn't help much. It kinda look's like everything should be working. They way I define the initial weights matches with the documentation of portfolio.spec

Does anyone have an idea why my initial weights are ignored by turnover_constraint?

$\endgroup$
4
  • 1
    $\begingroup$ If you remove that turnover constraint, what do you get? $\endgroup$
    – shabbychef
    Commented Nov 3, 2021 at 18:34
  • $\begingroup$ Once I remove it I get a optimized Portfolio without constraints, f.e. with weights like (0.22, 0.27, 0.51, 0). So the turnover constraint itsself has definitely an affect and works as its supposed to work, it's just the initial weights it ignores. $\endgroup$
    – Quastiat
    Commented Nov 4, 2021 at 8:27
  • 1
    $\begingroup$ Maybe the documentation can help: "Note that with the ROI solvers, turnover constraint is currently only supported for the global minimum variance and quadratic utility problems with ROI quadprog plugin." Is that the case ? cran.r-project.org/web/packages/PortfolioAnalytics/… $\endgroup$ Commented Nov 4, 2021 at 11:17
  • $\begingroup$ I am aware of that, which is why I am using the the random solver, with optimize_method="random". Like I said the turnover method itself is working, but somehow I am setting up the initial weights wrong. $\endgroup$
    – Quastiat
    Commented Nov 4, 2021 at 11:19

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.