0

I am trying to do portfolio optimization in R based on asset returns, covariances and variance I have calculated elewhere for all periods. I would then do backtesting using the calculated weights and actual past returns of the assets.

I'm ultimately attempting to try multiple optimization methids, but decided t ostart off simple, with Markowtiz Variance Optimization.

Optimization packages/functions I've been able to find so far are able to do exactly what I'm trying t achieve, but just using returns data. On the other hand, I'm trying to utilize expected returns I have calculated wth a separate model which give me the expected returns & variance for all the assets instead of simplu utilizing past performance.

Is there a simple optimization formula to achieve this? I am abe to pull off the simple optimization in Excel, but this is way too heavy to perform for a large number of periods. Should I just do the optimizatin semi-manually, by using the underlying optimization formulas and some sort of "solver" for R?

I have tried to see how the most common optimization functions in R work, but they all seem to only utilize past returns data directly.

Theo
  • 13
  • 3
  • 1
    If you are looking for data modeling recommendations, this is not the right site to ask. Stack Overflow is for specific programming questions. It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. – MrFlick Jul 27 '23 at 13:13

1 Answers1

0

If I understand correctly, you are looking for functions that take as inputs expected means and covariance matrices, and return mean-variance efficient portfolios (i.e. weight vectors). You might want to have a look at functions minvar, mvPortfolio, or maxSharpe in package NMOF, which compute minimum-variance, mean-variance efficient and maximum Sharpe-ratio portfolios. Examples are in a package vignette Functions for portfolio selection . (Disclosure: I am the package maintainer.)

Enrico Schumann
  • 1,278
  • 7
  • 8
  • Thank you! This seems very useful. Is there a way to also include transactio costs in the optimization process somehow? – Theo Jul 28 '23 at 14:14
  • Not with these functions I am afraid. But you if you are interested in backtests, you could easily wrap these functions in a backtest routine and subtract transaction costs. See https://quant.stackexchange.com/questions/39759/backtest-with-rolling-volatility-in-r for an example of doing a backtest, and, for the case of proportional transaction costs, see the parameter `tc` in `PMwR::btest` https://search.r-project.org/CRAN/refmans/PMwR/html/btest.html . – Enrico Schumann Jul 29 '23 at 16:24