Simulated Random Walk in MATLAB

Put in simple terms, a Random Walk basically involves taking successive random steps and tracing the trajectory. I adapted the example from part one of Wilmott on Quantitative Finance and wrote a quick MATLAB script to simulate a simple random walk. Basically flip a coin if it is heads multiply the equity seed by 1.01 and if its tails multiply by 0.99.

Results

The graphs below show successive runs of the script. I simulated 10,000 coin tosses in each test.

Simulated Random Walk Matlab .m fileSimulated Random Walk – Sim One: You flipped 5000 heads & 5000 tails

Simulated Random Walk 2 Matlab .m File

Simulated Random Walk – Sim Two: You flipped 5077 heads & 4923 tails

Simulated Random Walk 3 Matlab .m File

Simulated Random Walk – Sim Three: You flipped 4890 heads & 5110 tails

MATLAB Code

Writing the code in MATLAB is very straightforward I wrote the code in less then five minutes so it is a bit rough around the edges. I probably could refactor it but it does the job.

 

Leave a Reply

Your email address will not be published. Required fields are marked *