Skip to main content

A Python library for stochastic modeling and simulations.

Project description

stochPathSim

stochPathSim is a Python library designed for stochastic modeling, simulations, and statistical analysis. This library implements widely used stochastic models for financial and quantitative research, such as Geometric Brownian Motion (GBM), Heston Model, Vasicek Model, and more. It also includes utilities for statistical evaluation and visualization of simulations, making it ideal for researchers, quants, and data scientists.


Features

  • Simulation of Stochastic Models:
    • Geometric Brownian Motion (GBM)
    • Heston Model
    • Vasicek Model
    • Hull-White Model
    • Cox-Ingersoll-Ross (CIR) Model
    • Black-Derman-Toy (BDT) Model
    • Ho-Lee Model
  • Statistical Analysis:
    • Probability levels (P_LEVEL)
    • Quantile-based analysis (99th, 90th, 10th, 1st percentiles)
    • Mean value calculation
    • Exceedance metrics (upper and lower exceedance counts)
  • Visualization:
    • Interactive visualizations using Plotly
    • Static visualizations using Matplotlib

Installation

To install the library from PyPI:

pip install stochPathSim

Usage

1. Simulate Geometric Brownian Motion (GBM)

from stochPathSim.gbm import GeometricBrownianMotion
from stochPathSim.statistics_utils import calculate_statistics, display_statistics
from stochPathSim.visualization_utils import plot_simulation

# Initialize GBM
gbm = GeometricBrownianMotion(mu=0.1, sigma=0.2, s0=100, T=1, n=1000, paths=1000)

# Simulate
time, simulations = gbm.simulate()

# Calculate statistics
initial_value = 100  # Initial value of the simulation
stats_df = calculate_statistics(simulations, initial_value)

# Display statistics
display_statistics(stats_df, time)

# Plot simulation
plot_simulation(time, simulations)

2. Statistical Analysis with P_LEVEL and Exceedance Metrics

from stochPathSim.statistics_utils import calculate_statistics, display_statistics

# Assuming `simulations` is a 2D array of paths and `time` is the time vector
initial_value = 100

# Calculate statistics
stats_df = calculate_statistics(simulations, initial_value)

# Display statistics
display_statistics(stats_df, time)

3. Visualize Simulation Paths

from stochPathSim.visualization_utils import plot_simulation

# Plot simulation with 15 paths
plot_simulation(time, simulations, num_paths=15)

Supported Models

Geometric Brownian Motion (GBM)

  • Simulates the evolution of stock prices under constant drift and volatility.
  • Applications: Equity modeling, option pricing.

Heston Model

  • Stochastic volatility model with mean-reverting variance.
  • Applications: Volatility modeling, derivative pricing.

Vasicek Model

  • Mean-reverting interest rate model.
  • Applications: Fixed income modeling.

Hull-White Model

  • Generalized mean-reverting interest rate model with time-dependent drift.
  • Applications: Bond pricing.

Cox-Ingersoll-Ross (CIR) Model

  • Mean-reverting interest rate model with non-negative constraints.
  • Applications: Credit risk modeling.

Black-Derman-Toy (BDT) Model

  • Lognormal interest rate model.
  • Applications: Term structure modeling.

Ho-Lee Model

  • Arbitrage-free interest rate model with Gaussian increments.
  • Applications: Pricing interest rate derivatives.

Contributing

We welcome contributions! If you'd like to contribute, please:

  1. Fork the repository.
  2. Create a feature branch (git checkout -b feature-name).
  3. Commit your changes (git commit -m 'Add feature-name').
  4. Push to the branch (git push origin feature-name).
  5. Open a pull request.

License

MIT License

Copyright (c) 2024 Amit Kumar Jha

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


Contact

For questions or feedback, contact:

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

stochPathSim-1.0.0.tar.gz (6.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

stochPathSim-1.0.0-py3-none-any.whl (12.4 kB view details)

Uploaded Python 3

File details

Details for the file stochPathSim-1.0.0.tar.gz.

File metadata

  • Download URL: stochPathSim-1.0.0.tar.gz
  • Upload date:
  • Size: 6.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.11.9

File hashes

Hashes for stochPathSim-1.0.0.tar.gz
Algorithm Hash digest
SHA256 5e852df03c9e22eabe59cad2fb19e2293b8617dfa4545591bef5c8c1ad32592f
MD5 4319fd661f2428dd945c024466431895
BLAKE2b-256 6c9b8fe890c056a6284ae14610659f988589fb1237c3e80ff8113d807340256e

See more details on using hashes here.

File details

Details for the file stochPathSim-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: stochPathSim-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 12.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.11.9

File hashes

Hashes for stochPathSim-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1749521ab8570671bfa7d052ef5245eda87d2ba253e56343c9aa7f9d8193a1d1
MD5 6631bbf72b976ffbdff402a5fc3b6952
BLAKE2b-256 490c3946772e959b832ff4322cd0e8ac0c57504e67b7f41f4737535e2f649fd4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page