Path: news.mathworks.com!not-for-mail
From: "Anish Goorah" <anish.goorah@gmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: Vectorization, For loop
Date: Fri, 15 Feb 2008 13:13:02 +0000 (UTC)
Organization: Oxford Properties Group
Lines: 25
Message-ID: <fp434u$n1m$1@fred.mathworks.com>
Reply-To: "Anish Goorah" <anish.goorah@gmail.com>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1203081182 23606 172.30.248.38 (15 Feb 2008 13:13:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 15 Feb 2008 13:13:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 978321
Xref: news.mathworks.com comp.soft-sys.matlab:451629


Any brillant ideas as to how I avoid this double loop:


%%Initialization
iter = 50000;
simlen = 81;


dPt(:,(1:iter)) = 0.0142;%Initial Price Growth
price(:,(1:iter)) = 100000;%Initial Price
stdev = 0.25;
rho = 0.5;
c = 0.05;

%Simluation

dist = stdev*randn(simlen+1,iter);


for i=1:iter
    for j=1:simlen
        dPt(j+1,i) = c+rho*dPt(j,i)+dist(j,i);
        price(j+1,:) = price(j,:).*(1+dPt(j+1,:));
    end
end