

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
Stock prices are one of the most random entities . Geometric Brownian Motion (GBM) is one of the most popular methods for simulating stock prices. It is based on the Brownian motion model, which describes the random motion of particles suspended in a fluid. Python code for actual simulation is also provided.
Typology: Summaries
1 / 2
This page cannot be seen from the preview
Don't miss anything!
Python Code for Simulating Stock Prices using GBM
1 import numpy as np 2 import matplotlib. pyplot as plt 3 4 def simulate_stock_prices ( S0 , mu , sigma , dt , T ) : 5 """ 6 Simulate stock prices using Geometric Brownian Motion. 7 8 Parameters : 9 - S0 : Initial stock price 10 - mu : Expected return ( drift ) 11 - sigma : Volatility 12 - dt : Time increment 13 - T : Total time horizon 14 15 Returns : 16 - A numpy array containing simulated stock prices. 17 """ 18 N = int ( T / dt ) 19 t = np. linspace (0 , T , N ) 20 W = np. random. standard_normal ( size = N ) 21 W = np. cumsum ( W ) * np. sqrt ( dt ) # Cumulative sum to generate Brownian motion 22 S = S0 * np. exp (( mu - 0.5 * sigma **2) * t + sigma * W ) 23 return S 24 25 # Parameters 26 S0 = 100 27 mu = 0. 28 sigma = 0. 29 dt = 0. 30 T = 1 31 32 # Simulate stock prices 33 stock_prices = simulate_stock_prices ( S0 , mu , sigma , dt , T ) 34 35 # Plot 36 plt. plot ( stock_prices ) 37 plt. title ( ’ Simulated Stock Prices using GBM ’) 38 plt. xlabel ( ’ Time Steps ’) 39 plt. ylabel ( ’ Stock Price ’) 40 plt. show ()