MATLAB: Mean of columns across simulations

matrix manipulationmeansimulation

I have a 30x126x500 matrix (PortRetComb) containing 500 simulations of returns of 126 portfolios for a 30-year duration. What I am trying to calculate is the average return of each portfolio across simulation. So time series mean for years 1-30 for portfolio 1 will give the average portfolio 1 return over 30 years. I further want an average based on 500 simulations of this 30 year return. After doing this for 126 portfolios, I want a 1×126 matrix.
I'm currently trying:
for a = 1:500 for b = 1:126 for c = 1:30 Portmeans = mean(PortRetComb(c,b,a)); end end end
This isn't working out. Any help would be great.

Best Answer

Try this:
meanOverAllSimulations = mean(PortRetComb, 3);
portfolioMeans = mean(meanOverAllSimulations, 1);