MATLAB Language Financial Applications Random Walk

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Example

The following is an example that displays 5 one-dimensional random walks of 200 steps:

y = cumsum(rand(200,5) - 0.5);

plot(y)
legend('1', '2', '3', '4', '5')
title('random walks')

In the above code, y is a matrix of 5 columns, each of length 200. Since x is omitted, it defaults to the row numbers of y (equivalent to using x=1:200 as the x-axis). This way the plot function plots multiple y-vectors against the same x-vector, each using a different color automatically.

random walks plot



Got any MATLAB Language Question?