Skip to main content

GBMSimulator

GBMSimulator is a Python class designed to simulate Geometric Brownian Motion (GBM), a stochastic process widely used in mathematical finance for modeling stock prices and other financial instruments.

Features

  • Simulates GBM paths given user-defined parameters.
  • Supports customizable drift, volatility, initial value, number of paths, and time steps.
  • Returns an array of simulated paths, which can be easily visualized or analyzed.

Installation

Ensure you have Python 3.12 or higher. You can install the package and its dependencies from source with:

pip install -e .

or from PyPi with:

pip install GBMSimulator==0.0.2

Usage

Please also refer to Examples/GBMnotebook.ipynb

  1. Import the GBMSimulator class and matplotlib for plotting
from GBMSimulator.GBMSimulator import  GBMSimulator
import matplotlib.pyplot as plt
  1. Set the parameters for the GBMsimulator
'''
Args:
    mu (int): drift coefficient
    n (int): number of steps
    T (int): time in years
    M (int): number of sims
    y0 (int): initial value
    sigma (int): volatility
'''
mu = 0.1
n = 100
T =  1
M = 1000
y0 = 0.01
sigma = 0.5
  1. Create an instance of GMBSimulator
simulator = GBMSimulator()
  1. Create an array of simulated paths
simulated_paths = simulator.simulate(mu, n, T, M, y0, sigma)
  1. Plot the data
# template
plt.style.use('ggplot') 
# changing size of chart
plt.figure(figsize=(12, 5))

# Loop to do a line plot for each simulation
for num, sim in enumerate(simulated_paths.T):
    # length of each simulation
    t_values = list(range(len(sim)))
    # simulated values
    y_values = sim

    # line plot for each sim
    plt.plot(t_values, y_values, label=f"GBM path {num+1}")


# labelling chart
plt.xlabel("Time")
plt.ylabel("Y(t)")
plt.title("Simulated Geometric Brownian Motion Path")
if M <= 10:
    plt.legend()
else:
    plt.show()

Documentation

Visit our documentation page.

Contributing

Contributions are welcome! Fork our repository and submit a pull request.

Metadata

Release files for GBMSimulator 0.0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for GBMSimulator 0.0.4
File Size Uploaded
gbmsimulator-0.0.4.tar.gz 3.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for GBMSimulator 0.0.4
File Interpreter ABI Platform
gbmsimulator-0.0.4-py3-none-any.whl Python 3 none any Details

Total release size: 7.3 kB

Release files / gbmsimulator-0.0.4.tar.gz

Download URL gbmsimulator-0.0.4.tar.gz
Size 3.0 kB
Tags Source
SHA-256 checksum
How to use checksums
d9abd6335f7671fc9522af5ffc2b9c710d34feff40d8d358e297c560211fd490
BLAKE2b-256 checksum
How to use checksums
92fb7cbc94c5167a886eb2e29c6b3aad25574abde5ef04becf6cd8ea0061a65f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.3

Release files / gbmsimulator-0.0.4-py3-none-any.whl

Download URL gbmsimulator-0.0.4-py3-none-any.whl
Size 4.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
99394f56124f87cdef8ca673e5aa098bb54fdc868c119d86d2025cdb151ba07d
BLAKE2b-256 checksum
How to use checksums
f16fa84db4711c4116e6304998af05302f84a173af8bf906067df5421a03d18b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.3

Release history Release notifications | RSS feed

This release

0.0.4 This release

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page