# Geometric Brownian Motion Simulations for Stock Price

Published: 20 December 2023| Version 1 | DOI: 10.17632/wf36dmbcgz.1
Contributor:
Sunil Maria Benedict

## Description

Geometric Brownian Motion (GBM) is a mathematical model used to describe the stochastic movements of continuous-time processes. It's a fundamental concept in finance, particularly in modelling stock prices and other assets' movements in financial markets

## Steps to reproduce

import pandas as pd import numpy as np import matplotlib.pyplot as plt # Read the CSV file into a DataFrame df = pd.read_csv('/Users/sunilbenedict/Documents/HINDUNILVR.NS.csv') # Extract the 'Close' prices for analysis closing_prices = df['Close'] # Calculate daily returns returns = np.log(closing_prices / closing_prices.shift(1)) # Calculate drift and volatility of returns drift = returns.mean() volatility = returns.std() # Define parameters for the simulation t_intervals = 252 # Number of trading days iterations = 10 # Number of simulations # Simulate GBM daily_returns = np.exp(drift + volatility * np.random.normal(0, 1, (t_intervals, iterations))) price_paths = np.zeros_like(daily_returns) # Set the initial price as the last available price in the dataset price_paths[0] = closing_prices.iloc[-1] # Generate price paths based on the GBM for t in range(1, t_intervals): price_paths[t] = price_paths[t - 1] * daily_returns[t] # Plot the simulations with legends plt.figure(figsize=(10, 6)) plt.title('Geometric Brownian Motion Simulations for Stock Price') plt.xlabel('Trading Days') plt.ylabel('Stock Price') for i in range(iterations): plt.plot(price_paths[:, i], label=f'Simulation {i+1}') plt.legend() plt.show()

## Institutions

CMR Group of institutions

## Categories

Mathematics, Financial Mathematics, Financial Modelling, Geometric Theorem