A minimalist package to simulate geometric brownian motion
Project description
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
- Import the
GBMSimulator
class andmatplotlib
for plotting
from GBMSimulator.GBMSimulator import GBMSimulator
import matplotlib.pyplot as plt
- 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
- Create an instance of
GMBSimulator
simulator = GBMSimulator()
- Create an array of simulated paths
simulated_paths = simulator.simulate(mu, n, T, M, y0, sigma)
- 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.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file gbmsimulator-0.0.4.tar.gz
.
File metadata
- Download URL: gbmsimulator-0.0.4.tar.gz
- Upload date:
- Size: 3.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
d9abd6335f7671fc9522af5ffc2b9c710d34feff40d8d358e297c560211fd490
|
|
MD5 |
c997010ef42dd4be5bf987a5bb7b72be
|
|
BLAKE2b-256 |
92fb7cbc94c5167a886eb2e29c6b3aad25574abde5ef04becf6cd8ea0061a65f
|
File details
Details for the file gbmsimulator-0.0.4-py3-none-any.whl
.
File metadata
- Download URL: gbmsimulator-0.0.4-py3-none-any.whl
- Upload date:
- Size: 4.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
99394f56124f87cdef8ca673e5aa098bb54fdc868c119d86d2025cdb151ba07d
|
|
MD5 |
299b5e091ffac4c5b57f09e62fb988c3
|
|
BLAKE2b-256 |
f16fa84db4711c4116e6304998af05302f84a173af8bf906067df5421a03d18b
|