# robust portfolio optimization re-balancing with transaction costs

The optimal re-balancing strategy takes account of factors including i) objective function, ii) current portfolio weights, iii) expected return vector containing updated views/alpha forecasts, iv) uncertainty in the alpha forecasts, v) transaction costs, vi) risk aversion, and vii) constraints (long-only, turnover, etc.).

Question - Are there any libraries in R that return the optimal weight vector as a function of these inputs and related reporting? Or should I select one of the many optimizers in R and build out all the wonderful optimization reporting (risk budgeting, contribution to risk, etc.) that the rmetrics team has already done?

Below I describe why the rmetrics package does not solve the problem:

The challenge is that the rmetrics optimization procedure identifies the optimal portfolio without reference to current vector of portfolio weights, updated alpha forecasts, and transactions costs. The correct procedure performed periodically would be to specify the path of the portfolio along a line where the marginal transaction cost is just offset by the marginal expected return (or marginal risk reduction) in the utility function. The marginal return would be the output of a forecasting model as opposed to using the mean return. The fPortfolioBacktest anticipates this issue and attempts to smooth the change in weights from period to period. But we can do better by having the optimizer confront the trade-off directly.

## 2 Answers

The PortfolioAnalytics package will create weights without reference to current weights, if that's what you want. It should also have much of the reporting that you like from Rmetrics fPortfolio.

There is a longer seminar presentation on Portfolioanalytics from 2010's R/Finance conference here: Complex Portfolio Optimization with Generalized Business Objectives

• The links and example in powerful is great - thanks! Your choice of optimizer seems general enough to solve the optimization problem while also referencing current weights. I believe I can pass an additional penalty to the objective function that measures the distance from the current weight vector to the weight vector the optimizer is solving for time a constant (e.g. transactions costs). Since your optimizer can take expected return as an input I expect it could take a current weight vector as well. This would enable me to optimize in the presence of transaction costs. – Ram Ahluwalia Jul 27 '11 at 17:37
• Brian, 1) Can the PortfolioAnalytics function handle custom constraints (example: sector-neutral weights)? The constraint class looks pre-specified. 2) Also, I see that the optimize.portfolio function can accept a matrix of returns. I have a posterior distribution of expected market returns (i.e. K possible realizations of market returns for N assets resulting from MCMC). Can this function identify the optimal weight vector with respect to the sampling from the posterior? Of course, I would continue to use covariance of historical returns (de-noised) for calculation of ES. Thanks! – Ram Ahluwalia Aug 3 '11 at 0:11
• All the components of the objective are arbitrary R functions. The package takes care of the 'wrapper' around all of that, basic box constraints and full investment constraint, dealing with the optimization engines, etc. The objective is layered (and separately multiplied/penalized) by each arbitrary function you define. There was a discussion on R-SIG-Finance this week here showing a custom objective that isn't in the 'standard' model of using returns the way a modified Markowitz approach does. – Brian G. Peterson Aug 5 '11 at 14:29

This is the website to the R/Finance conference this year. Tons of great links.

http://www.rinfinance.com/agenda/

Brian Peterson's slide (Building and Testing Quantitative Strategy Models in R) mentions Portfolio-Analytics (which I think is based on R/Metrics).

And here is a paper based on Portfolio-Analytics.

http://cran.r-project.org/web/packages/portfolio/vignettes/portfolio.pdf

I am a Python guy (not R) so I can't say if my response exactly answers your question but it may be a good starting place.

• Good suggestions... but I'll help out since you're not an R guy. :) The Portfolio-Analytics Brian mentions isn't related to R-metrics; he's referring to the PortfolioAnalytics package on R-forge. – Joshua Ulrich Jul 25 '11 at 11:09
• Thanks all. I looked at the vignette attached. This package takes as input a portfolio with a set of weights. I am looking for an optimizer to discover the optimal set of weights given the objective funcion and constraints above. So this module would be used downstream after the optimizer. The R-Finance content is a goldmine - thank you for sharing that - but doesn't seem to have anything on portfolio construction and optimization – Ram Ahluwalia Jul 25 '11 at 13:32