A package for simulating financial stochastic processes.
Project description
FinancialStochasticProcesses Documentation
Installation
You can install the package via pip:
pip install financial_stochastic_processes
StochasticAssetPriceSimulator
The StochasticAssetPriceSimulator is a Python class designed to simulate various financial stochastic processes, such as Geometric Brownian Motion (GBM), Jump Diffusion, Heston Stochastic Volatility model, and Regime-Switching models. This class can be used to model and simulate asset price dynamics with optional control over randomness using a seed for reproducibility.
Features
- Geometric Brownian Motion (GBM): Simulates asset price movements under the GBM assumption.
- Jump Diffusion Model: Simulates asset price movements with both continuous price changes and discrete jumps, where jumps can be either upward or downward.
- Heston Model: Simulates asset price dynamics with stochastic volatility using the Heston model.
- Regime-Switching Model: Simulates asset prices under different market regimes using a regime-switching model.
- Seed Control: Optionally set a random seed to generate reproducible simulations.
1. Initialize the Simulator
You can initialize the simulator by providing the required parameters, including the initial stock price, time horizon, and time step size.
from financial_stochastic_processes import StochasticAssetPriceSimulator
simulator = StochasticAssetPriceSimulator(S0=100, T=1, dt=0.01, seed=42)
2. Simulate Geometric Brownian Motion (GBM)
Use the simulate_GBM method to generate asset prices under a GBM process.
gbm_simulation = simulator.simulate_GBM()
3. Simulate Jump Diffusion
Use the simulate_jump_diffusion method to generate asset prices under a Jump Diffusion process.
jump_diffusion_simulation = simulator.simulate_jump_diffusion()
4. Simulate Heston Model
Use the simulate_heston method to generate asset prices under the Heston stochastic volatility model.
heston_simulation, heston_volatility = simulator.simulate_heston()
5. Simulate Regime-Switching Model
Use the simulate_regime_switching method to generate asset prices under the regime-switching model.
regime_switching_simulation = simulator.simulate_regime_switching()
Example Code:
import matplotlib.pyplot as plt
# Initialize the simulator
simulator = StochasticAssetPriceSimulator(S0=100, T=1, dt=0.01, sigma1=0.2, sigma2=0.2, V0=0.05, seed=42)
# Simulate GBM
gbm_prices = simulator.simulate_GBM()
# Simulate Jump Diffusion
jump_diffusion_prices = simulator.simulate_jump_diffusion()
# Simulate Heston Model
heston_prices, heston_volatility = simulator.simulate_heston()
# Plot the results
plt.plot(gbm_prices, label="GBM")
plt.plot(jump_diffusion_prices, label="Jump Diffusion")
plt.plot(heston_prices, label="Heston Model")
plt.xlabel("Time")
plt.ylabel("Asset Price")
plt.legend()
plt.title("Stochastic Asset Price Simulation")
plt.show()
Parameters
The following parameters are available when creating a StochasticAssetPriceSimulator instance:
| Parameter | Description | Default Value |
|---|---|---|
S0 |
Initial stock price (Every Model) | Required |
T |
Time horizon (Every Model) | Required |
dt |
Time step size(Every Model) | Required |
mu |
Drift (expected return)(GBM, Jump Diffusion) | 0.05 |
sigma |
Volatility (GBM, Jump Diffusion) | 0.2 |
lamb |
Jump intensity (average number of jumps)(Jump Diffusion) | 0.75 |
p |
Probability of upward jumps(Jump Diffusion) | 0.5 |
lambda1 |
Intensity of upward jumps(Jump Diffusion) | 1.0 |
lambda2 |
Intensity of downward jumps(Jump Diffusion) | 1.0 |
kappa |
Mean reversion rate (Heston model) | 0.15 |
theta |
Long-term variance mean (Heston model) | 0.05 |
V0 |
Initial variance for Heston model (Heston model) | 0.05 |
sigma1 |
Volatility coefficient for W1 (Heston) | 0.2 |
sigma2 |
Volatility coefficient for W2 (Heston) | 0.2 |
| P_tran | Transition matrix (regime-switching model) | np.array([[0.3,0.7], [0.4,0.6]]) |
| mu_rs | Drift for the second regime (regime-switching model) | 0.07 |
| sigma_rs | Volatility for the second regime (regime-switching model) | 0.4 |
seed |
Seed for reproducibility | None |
Requirements
- Python 3.6 or higher
numpy
Install dependencies with:
pip install numpy
License
This project is licensed under the MIT License - see the LICENSE file for details.
Contributing
Feel free to contribute to this project by submitting issues or pull requests. For major changes, please open an issue first to discuss what you would like to change.
Happy simulating!
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file financial_stochastic_processes-0.1.6.tar.gz.
File metadata
- Download URL: financial_stochastic_processes-0.1.6.tar.gz
- Upload date:
- Size: 5.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3478fee9c1be3bf353f05431bb31ebb339debc2f271abfea7c39ddf2e96dc62f
|
|
| MD5 |
0936761cc6ce6c635f5407b8ebc83e32
|
|
| BLAKE2b-256 |
caff4c2b34322db27e56372061fbc5e6162ad7c2f977d074e8f315d89b35fc77
|
File details
Details for the file financial_stochastic_processes-0.1.6-py3-none-any.whl.
File metadata
- Download URL: financial_stochastic_processes-0.1.6-py3-none-any.whl
- Upload date:
- Size: 6.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2eb3fcbf620e97889888428c1939a6b2fce5956868dc847a18aa8d906fb01456
|
|
| MD5 |
6effab2a5b29ffa37703d9d8d3d50ecb
|
|
| BLAKE2b-256 |
d1c4c16355347b43b3213c5c73cea4c2f910441a09fbab7d205e04556f9b8a3c
|