LessonThis is a lesson restated in new words. Any figure in it is an example from the source, not this desk's record.
A geometric Brownian motion path is a price series built from a drift, a volatility, and a fresh normal shock at every time step. In code you keep the latest price, apply one update, store the result, and repeat until a chosen horizon is finished. A chart of many such series is a set of what-if histories for one parameter set.
Why it matters
Risk work often starts with a price, a drift, and a volatility, and still needs a range of endings rather than one forecast. Sample paths turn those inputs into many possible routes. Later pricing work can read a contract payoff off each route and average them. The demonstration here uses round numbers so the mechanics stay visible. The same slots can hold a drift taken from historical returns, a volatility taken from the historical standard deviation of daily bars, and today's price.
The idea in plain words
Geometric Brownian motion splits the next price change into two pieces. One piece is the drift, multiplied by the length of the step and by the price you are at now. The other piece is the volatility, multiplied by that same price and by a Brownian increment. The increment is a draw from a normal distribution whose mean is zero and whose standard deviation is the square root of the step length. Both pieces scale with the current price, so a high price takes larger steps than a low price. The path is iterative. Each new level becomes the base for the step after it.
How to use it
Import NumPy for the random draw. Define a class that accepts the drift, the volatility, the step length, and the starting price. Give the object a list that begins with the starting price, and give it a field for the current price set to that same start. A step method draws the Brownian increment, computes the price change from the two-piece rule, adds the change to the current price, and appends that sum to the list. It then writes the new level back into the current-price field. That write is the whole memory of the path. Leave the field at the start and every later update is applied to the original price.
A fan of routes is a list of objects. The lesson builds 100 of them with a volatility of 0.3, a step of one day in a 365-day year, and a starting price of 300. Drift is the remaining input. The spoken demo treats the set as a stand-in you could replace with a historical mean and a historical daily standard deviation. For each object, put one year on a clock. While the time still left exceeds the step, call the step method and subtract one step from the clock. Start the clock over for every object so each path covers a full year.
The price list on the first object is the raw series. Import Matplotlib, build an x-axis by counting from zero up to the length of that list, and plot the prices against it. The lesson's chart has the jagged rise and fall associated with a traded price.
What usually goes wrong
The common bug is forgetting to store the new price as the current price, so the series never walks away from the start. Another is forgetting to restart the year clock, so later objects take fewer steps. The step length and the volatility have to share a clock. A daily standard deviation paired with a yearly step mixes two units. One fixed drift and one fixed volatility also cannot show a market whose pace changes through the year. A path that finishes high is one draw. A new seed finishes somewhere else. The generator is a scenario tool, and a single plotted line is one scenario.
Questions people ask
What does the normal draw represent?
It is the random piece of the price change over one step. Its center is zero and its spread is the square root of the step, which is the Brownian increment the update uses.
Why keep both a list and a current price?
The list is the history you may plot. The current price is the base for the next update. Both begin at the initial price, and the current price is overwritten after every step.
Do the paths alone give a contract price?
They are the scenarios. A contract price still needs the payoff on each ending, an average of those payoffs, and a discount back to today. The lesson stops once the paths exist.