Let’s Diffuse Some Particles
You have now seen how to make a Monte Carlo simulation of three different stochastic differential equations. The first is Brownian motion. The second and third are Geometric Brownian motion. These will simulate stock prices, first without jumps, then with jumps. You can use the same code for the stock prices, making the jump size zero if you don’t want any jumps. Let’s code it.
Brownian Motion
You need particles to move, so code a Particle class with a position (x, y) and a way to Move. To avoid busting through the sides of the bag, specify the bag’s edges and its size. When a particle is high enough to escape from the bag, it’s done and stops moving:
| class Particle |
| { |
| public: |
| Particle( ... |
Get Genetic Algorithms and Machine Learning for Programmers now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.