Stock Price Simulation
Simulate the Stock Price based on the Binomial Model, a mathematical model used to estimate the price of European and American style options. It does so by creating a binomial tree of price paths for the underlying asset based on the stock price, volatility, risk free rate, dividend yield and time to expiration. The stock price is then simulated based on the up and down movements.
By default the most recent risk free rate and stock price is used, you can alter this by changing the start date. The volatility is calculated based on the daily returns of the stock price and the selected period (this can be altered by defining this accordingly when defining the Toolkit class, start_date and end_date).
The formulas are as follows:
\[\text{up movement} (u) = e ^{\sigma \cdot \sqrt{t}}\] \[\text{down movement} (d) = 1 / u\] \[\text{stock price at each node} = S \cdot u ^{j} \cdot d ^{n - j}\]Where S is the stock price, r is the risk free rate, σ is the volatility, t is the time to expiration, j is the number of up movements, n is the number of time steps.
The resulting output is a DataFrame containing the tickers and movements as the index and the time to expiration as the columns. The movements index contains the number of up movements and the number of down movements. The output is the binomial tree displayed in a table. E.g. when using 10 time steps, the table from each company will contain the actual binomial tree’s stock prices as also depicted in the image found here: https://en.wikipedia.org/wiki/Binomial_options_pricing_model#Method
Hint: consider plotting the resulting DataFrame for each company to visualize the binomial tree. For example for below’s example use stock_price_simulation.loc['AMZN'].T.plot(legend=False)
Also known as: Monte Carlo simulation, GBM, stock price path.
No programming experience? With the Finance Toolkit MCP server, AI assistants such as Claude and ChatGPT can calculate the Stock Price Simulation for you. Just ask in plain English.
Calculate the Stock Price Simulation in Python
The Stock Price Simulation is available in the Options module of the open-source Finance Toolkit. Install it with:
pip install financetoolkit -U
Then call get_stock_price_simulation as shown below.
from financetoolkit import Toolkit
toolkit = Toolkit(["AMZN", "ASML"], api_key=API_KEY)
stock_price_simulation = toolkit.options.get_stock_price_simulation(
start_date='2020-06-22', timesteps=4
)
stock_price_simulation.loc['AMZN']
Which returns:
| Movement | 2020-06-22 | 2020-09-21 | 2020-12-21 | 2021-03-22 | 2021-06-22 |
|---|---|---|---|---|---|
| UUUU | 135.69 | 160.047 | 188.776 | 222.663 | 262.632 |
| UUUD | 135.69 | 160.047 | 188.776 | 222.663 | 188.776 |
| UUDU | 135.69 | 160.047 | 188.776 | 160.047 | 188.776 |
| UUDD | 135.69 | 160.047 | 188.776 | 160.047 | 135.69 |
| UDUU | 135.69 | 160.047 | 135.69 | 160.047 | 188.776 |
| UDUD | 135.69 | 160.047 | 135.69 | 160.047 | 135.69 |
| UDDU | 135.69 | 160.047 | 135.69 | 115.04 | 135.69 |
| UDDD | 135.69 | 160.047 | 135.69 | 115.04 | 97.5323 |
| DUUU | 135.69 | 115.04 | 135.69 | 160.047 | 188.776 |
| DUUD | 135.69 | 115.04 | 135.69 | 160.047 | 135.69 |
| DUDU | 135.69 | 115.04 | 135.69 | 115.04 | 135.69 |
| DUDD | 135.69 | 115.04 | 135.69 | 115.04 | 97.5323 |
| DDUU | 135.69 | 115.04 | 97.5323 | 115.04 | 135.69 |
| DDUD | 135.69 | 115.04 | 97.5323 | 115.04 | 97.5323 |
| DDDU | 135.69 | 115.04 | 97.5323 | 82.6891 | 97.5323 |
| DDDD | 135.69 | 115.04 | 97.5323 | 82.6891 | 70.1049 |
Parameters
get_stock_price_simulation accepts the following parameters:
- start_date (str | None, optional): The start date which determines the stock price. Defaults to None which means it will use the most recent date.
- time_to_expiration (int): The number of year to use for the time to expiration. Defaults to 1 which equals one year.
- timesteps (int): The number of time steps to use for the binomial tree. Defaults to 10 which equals 10 time steps. This will be evenly distributed over the time to expiration.
- risk_free_rate (float, optional): The risk free rate to use for the calculation. Defaults to None which means it will use the current risk free rate.
- show_unique_combinations (bool, optional): Whether to show the unique combinations of the stock prices. Defaults to False.
- show_input_info (bool, optional): Whether to show the input information. Defaults to False.
- rounding (int | None, optional): The number of decimals to round the results to. Defaults to 4.
- standardize (bool, optional): Whether to standardize (Z-Score) the result across the time to expiration columns for each ticker and strike price. Defaults to False.
Related Option Pricing
The Options module page introduces the module, and the sidebar lists all of its functions.