Portfolio Optimizer

Does anyone have experience with portfolio optimization in Matlab? I’m currently using excel but curious if others have found Matlab better.

Cheers

I did Matlab’s optimizer a long time ago. Basically, Matlab is better if you are running lots and lots of optimizations, because setting up the cell selections in Excel is a PITA. So if you want to run optimizations with lots of different assumptions or lots of different asset combinations, or plot out an efficient frontier with more than two assets, it’s nicer to use Matlab’s.

Matlab is much faster than Excel. Also, Excel’s “Solver” tool is kind of opaque. I never know if it is stuck in at an inflection point or something…

how do you use excel? If you don’t mind…can i use your spreadsheet? I’m using my own excel sheet, but it’s a pain and hella slow.

Palantir, send me a mail and I’ll send you an excel optimizer

Hey, not sure how I can contact you

Drop me the spreadsheet too homie.

And, I need to call out my man bchad again. I used to be all into looking for minimum portfolio variance, covariance, and correlations close to zero. I spent a lot of time looking to build the bulletproof asset allocation without success.

So, I humbly come before the great Oracle of AF and ask how to do a portfolio asset allocation? What is the methodology to use outside of a Mean Variance Optimizer? So often these programs turn into GIGO.

You should just throw that file into a public dropbox link… pretty sure its something a few people would be interested (such as myself)

Personally, I just do volatility weighting, with an approximation for covariance. I’ll typically assume zero covariance if they are different asset classes, and I’ll assume a covariance of 1 if they are the same asset class. I figure that all the noise in a proper MVO probably doesn’t improve things all that much over that.

If you stress test stuff, then you probably want to assume that the correlation of everything turns to 1, except possibly US Treasuries, which might be close to -1.

I’ve always been curious about that optimization method that was mentioned in L3 where you add some noise to each of the parameters, and then optimize 10000 portfolios with your parameters plus some noise and take the average. I suspect that it works pretty well for long-only portfolios, but maybe not so well for long-short ones.

Do you just put together a correlation (or covariance) matrix, and a row and/or column of expected returns and weights, and then use solver to solve for the highest sharpe ratio (or return with a constant risk, or lowest risk with a constant return) by manipulating the weights (perhaps with some constraints)?

If it’s more complex than that, I’d be curious to see what you’re doing.

^ I had a spreadsheet that was doing just that. I’d be able to input up to 7 Tickers, populate their returns, and then run solver to min varience while maxing return to see what allocations should be. Problem is, you’d need to run it over and over and over and over for differnt time spans to get a good idea of % allocation.

And I always worried about GIGO.

What I’ve been trying to do is put together a list of correlations and returns for about 9 assets, which I have. So Then I take randomly generated portfolios and run a Data Table function to spit out a range of expected returns and standard deviation for the portfolios to create an efficient frontier. The trouble is,I created a few hundred thousand randomly generated portfolios, so I can “paint a field” on the graph.However, as you can imagine, it’s really really slow, and I can’t save the file.

If you just have a stock portfolio, you might compare the Sharpe ratios of the optimized portfolio with the sharpe ratio fo the market portfolio. If they aren’t that different, then you might just use a mix of the two portfolios. This is kind of the Treynor process that they covered in L2 when I took the exam. Of course, it’s boring to just invest in the market portfolio, but it is often hard to beat.

If all of your assets are the same asset class, it’s not always so bad to use an equal weighted portfolio (same dollar amounts to each asset). Personally, I don’t like to do that. I prefer to weight assets by their normal risk (i.e. SD, or possibly Beta) because I don’t think that I’m better at analyzing low volatility assets than high volatility ones, and so I want each one to be contributing about the same amount of risk to the portfolio and hope that whatever skill I have averages out positive over all the assets. If I have a high conviction on an asset, I may increase the weight beyond what the risk says I should, but seldom by very much.

Options are the way to deal with non-normal risk (i.e. tail risks). They are also a way to try to access risk as an asset class (also the vix). I don’t feel all that confident that I can trade options effectively, although I probably could with a little more practice. That’s a personal goal for 2013.

@Bchad Were you talking about Michaud resampling? The basic idea (assuming away uncertainty in the covariance matrix for the moment) is that you only estimate the expected returns with an uncertainty. So you actually estimate returns that are N(mu,sigma_mu), where sigma_mu might be like the standard error of mu. So then you simulate a new mu and construct your efficient frontier, including constraints. You do this many times and then average the frontiers for your resampled frontier.

Also, if you’re going to begin portfolio optimization with options. While there are some (approximate) CVaR optimizers that can handle large portfolios options, it is easier to take a two-stage approach: 1) calculate mean-variance frontier (ie. ignoring non-normality in options), 2) calculate the mean and CVaR of the efficient frontier portfolios and decide on the optimal portfolio within this set. I think the optimization is the easy part. It’s getting the inputs (distribution of option returns at the horizon) that’s difficult.

Yeah, that’s it. It’s Michaud resampling. Since I tend to do vol weighting and don’t tend to have options, I’d forgotten the details, but it always seemed a sensible approach in a long-only non-options context.

Michaud is likely superior to classical estimates with MVO, especially when the portfolio size increases. Not sure whether you would get better returns than a Bayesian approach, but you would avoid a lot of headaches that come with Bayesian techniques (ever try to impose stationarity in a Bayesian VAR?).

My head hurts just thinking about that.

BChad, my excel version is simply that, mean variance, a row of weighted return, the MMulti function to get portfolio variance and then use solver to get max sharpe/min vol etc portfolio. Some interesting things mentioned above that I’ll look into. I can try share the spreadsheet when I get back into work.

I’m trying to do an optimiser for managed funds accoss asset classes and currencies, has anyone looked at that? I might end up using mean variance optimization of the fund ‘alphas’ within each asset class and then optimize accross the asset classes.

I like all these geeky talk…

No experneice with stock-only portfolio. In a multi-asset portfolio, I use contribution to risk as a mean of both identifying SAA and reblancing. MVO is good but it relies too heavily on the asset class return assumptions.

Bchad - why would you use 0 for covariance matirx? Wouldn’t that under-estimate your portfolio vol especially when you use vol-weighting?

To respond to OP - am also trying matlab, it’s faster than excel and there are few built-in tool that handles things nicely that excel can not. For example, PCA, cluster analysis etc. In terms of the optimisation, I think matlab is quicker but not necessarily more sophisticate.