From: Rodrigo on
I'm newbie in Matlab. I was trying to do a portfolio optimization, and so I did using the function "frontcon" and "portopt", but now, I'm trying to put some Monte Carlo simulation on it.
In" portReturn" there are 1000 results generated by Monte Carlo simulation. I have to do the portfolio optimization for each one of them, and find the mean of those results. It has been my problem.
--//---------------------------//-------------------------

n=1000;
for i= 1.:n
for i=true
[PRisk,PRoR,PWts] = mean(portopt(portReturn(:,:,i),CovMatrix,10));
[PWts,PRoR,PRisk]
end
end

--//------------------------//----------------------------
If you take out the - mean - of the code, it will generate the individual result for each portfolio in the simulation. I have no idea to solve this problem and find the mean portfolio.

Thank you.

rodrigosm
From: Steven Lord on

"Rodrigo" <rodrigosmunhoz(a)yahoo.com.br> wrote in message
news:1046640892.500857.1270415431034.JavaMail.root(a)gallium.mathforum.org...
> I'm newbie in Matlab. I was trying to do a portfolio optimization, and so
> I did using the function "frontcon" and "portopt", but now, I'm trying to
> put some Monte Carlo simulation on it.
> In" portReturn" there are 1000 results generated by Monte Carlo
> simulation. I have to do the portfolio optimization for each one of them,
> and find the mean of those results. It has been my problem.
> --//---------------------------//-------------------------
>
> n=1000;
> for i= 1.:n
> for i=true

You don't need to do a second loop here; even if you did, you shouldn't
reuse the loop variable from the outer loop because it could get confusing.

> [PRisk,PRoR,PWts] = mean(portopt(portReturn(:,:,i),CovMatrix,10));

Preallocate your PRisk, PRoR, and PWts variables to be the appropriate size
prior to the loop, fill them in inside the loop, and then take the MEAN
after the loop is complete.

*snip*

A simpler example you can use as a template for your real problem is:

n = 10;
z = zeros(1, n);
for k = 1:n
z(k) = k.^2;
end
mean(z)

--
Steve Lord
slord(a)mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ


From: Rodrigo on
I don't know if I understood correctly, but I´m doing some big mistake here. I will explain again what I trying to do, because I don't know if I was clear in the last time.
This is what I would like to reach:

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

[PRisk(1),PRoR(1),Pwts(1)]=frontcon(portReturn(:,:,1),CovMatrix,20);
[Pwts(1), PRoR(1), PRisk(1)];
[PRisk(2),PRoR(2),Pwts(2)]=frontcon(portReturn(:,:,2),CovMatrix,20);
[Pwts(2), PRoR(2), PRisk(2)]; ....
([Pwts(1), PRoR(1), PRisk(1)] + [Pwts(2), PRoR(2), PRisk(2)]+...+ [Pwts(n),
[ PRoR(n), PRisk(n)] /n

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

I tested it with only ( [Pwts(1), PRoR(1), PRisk(1)] + [Pwts(2), PRoR(2), PRisk(2)]) / 2, and it was working well.
I tried to insert what Steven Lord said, but the result is totally wrong, I'm certainly doing something wrong.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

n=1000;
PRisk=zeros(1,n);
PRoR=zeros(1,n);
Pwts=zeros(1,n);
for i=1:1:n;
[PRisk,PRoR,Pwts]=frontcon(portReturn(:,:,i),CovMatrix,20);
sum([PRisk,PRoR,Pwts])/i
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%