You are on page 1of 4

ASSIGNMENT – 4

OBJECTIVE:

1. A walker can perform step towards right with probability 0.5 and left with probability 0.5. Let
the walker performs N steps (here 10). Record the final position of the walker. Repeat the
experiment 10,000 times, and record the final position of walker in each experiment. Also
record the average final position of the walker.
2. In the above problem, let the walker performs step towards right with probability 1/4 and left
with probability 3/4. In each case walker moves 20 steps. Perform this up to 10,000 times. Take
initial position of walker to be 20.

THEORY:

Random walk, in probability theory, is a process for determining the probable location of a point subject
to random motions, given the probabilities (the same at each step) of moving some distance in some
direction. Random walks are an example of Markov processes, in which future behaviour is independent
of past history. A typical example is the drunkard’s walk, in which a point beginning at the origin of the
Euclidean plane moves a distance of one unit for each unit of time, the direction of motion, however,
being random at each step. The problem is to find, after some fixed time, the probability distribution
function of the distance of the point from the origin. Many economists believe that stock market
fluctuations, at least over the short run, are random walks. And the problem of random walk is very
important in the stock market today. The stock price rising or declining is a completely random event
just like a drunk man taking his next step is completely random and doesn’t depend on the previous
steps taken. But if the drunk man is not walking on a plane street but on some kind of inclined street
then the walk is more likely to be towards the slope compared to the hill, this situation, we call biased
random walk.

CODE:

(i)
clc
data = []
for i = 1:10000
step = 11
for j = 1:10
randstep = rand(1)
if randstep>0.5
step = step + 1
else
step = step - 1
end
end
data = cat(1, data, step)
end

histplot(21, data)
disp('Frequency table', tabul(data))
[MaxFreq Ind] = max(tabul(data)(:,2))
Mean = tabul(data)(Ind, 1)
mprintf("\n Mean = %d", Mean)
stdv = sqrt(sum(data^2)/10e3 - (sum(data)/10e3)^2)
mprintf("\n Standard deviation = %f", stdv)
xlabel("Range")
ylabel("Frequncy")
title("Random walk distribution")

(ii)
clc
clf
clear
data = []
for i = 1:10e4
step = 20
for j = 1:20
randstep = rand(1)
if randstep > 3/4
step = step + 1
else
step = step - 1
end
end
data = cat(1, data, step)
end

histplot(41, data)
disp("Frequency table", tabul(data))
[MaxFreq Ind] = max(tabul(data)(:,2))
Mean = tabul(data)(Ind, 1)
mprintf("\n Mean = %d", Mean)
stdv = sqrt(sum(data^2)/10e4 - (sum(data)/10e4)^2)
mprintf("\n Standard deviation = %f", stdv)
ThMean = 20 - step*(3/4 - 1/4)
mprintf("\n Final position = %d", ThMean)
xlabel("Range")
ylabel("Frequency")
title("Biased random walk distribution")

OUTPUT:
(i)
(ii)

You might also like