I am trying to build a Biased Random Walk can someone tell me what my mistake is?

3 views (last 30 days)
I'm trying to build a model for a biased RW, that the probability of the walk, changes depending on the current value, with a lower limit of -0.35. For some reason the probability of the RW does not change when it hits -0.35 and as a result the RW acts like a regular biased Walk with a probability of 0.6. Any help would be appreciated.
%Biased model for Ibm
N=502;
M=1000;
D=zeros(M,N);
D_sq=zeros(M,N);
AvgD_sq=zeros(1,N);
AvgD=zeros(1,N);
for j=1:M
p=rand(1,M);
for i=2:N
if D(j,i)>=0
prob=0.6;
elseif (D(j,i)>=(-0.2)) && (D(j,i)<0)
prob=0.7;
elseif (D(j,i)<(-0.2)) && (D(j,i)>=(-0.35))
prob=0.5;
else prob=0.2;
end
if p(j)>prob
D(j,i)=D(j,i-1)+.01;
else D(j,i)=D(j,i-1)-.01;
end
D_sq(j,i)=D_sq(j,i-1)+D(j,i)^2;
end
end
AvgD_sq=mean(D_sq);
AvgD=mean(D);
%Graph showing the X^2
figure
plot (AvgD_sq);
set(gca,'FontSize',20);
title ('X^2 prices, Vs. t','FontSize',20);
xlabel ('Time(sec)','FontSize',20);
ylabel ('X^2','FontSize',20);
figure
plot (AvgD);
set(gca,'FontSize',20);
title ('D, Vs. t','FontSize',20);
xlabel ('Time(sec)','FontSize',20);
ylabel ('D','FontSize',20);

Answers (1)

the cyclist
the cyclist on 30 Aug 2015
I did not dig deeply into your code, but I know that every time you get to the line
if D(j,i)>=0
D(j,i) is always equal to zero, so prob(j,i) will always be equal to 0.6.

Categories

Find more on Financial Toolbox in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!