O'Reilly logo

Genetic Algorithms and Machine Learning for Programmers by Frances Buontempo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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(​ ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required