Skip to content

reetmitra/options_simulator

Repository files navigation

Options Pricing Simulator

A Python library for options pricing and analysis using the Black-Scholes model. This library provides tools for calculating option prices, Greeks, and visualizing option payoffs.

Features

  • Black-Scholes option pricing for calls and puts
  • Greeks calculations (Delta, Gamma, Theta, Vega, Rho)
  • Payoff visualization for individual options and combined positions
  • Clear and documented code with type hints and docstrings

Installation

  1. Clone the repository:
git clone https://github.com/reetmitra/options_simulator.git
cd options_simulator
  1. Install the required packages:
pip install -r requirements.txt

Usage

Run the test script to see the library in action:

python test_options.py

This will:

  1. Calculate call and put option prices
  2. Compute all Greeks for both options
  3. Generate payoff diagrams (saved as PNG files)

Example Code

from black_scholes import black_scholes_call, black_scholes_put
from greeks import delta_call, gamma
from payoff_visualizer import plot_payoff

# Parameters
S = 100  # Stock price
K = 100  # Strike price
T = 1.0  # Time to expiration (years)
r = 0.05  # Risk-free rate
sigma = 0.2  # Volatility

# Calculate option price
call_price = black_scholes_call(S, K, T, r, sigma)
print(f"Call Option Price: ${call_price:.2f}")

# Calculate Greeks
delta = delta_call(S, K, T, r, sigma)
gamma = gamma(S, K, T, r, sigma)
print(f"Delta: {delta:.4f}")
print(f"Gamma: {gamma:.4f}")

Project Structure

  • black_scholes.py: Core Black-Scholes pricing functions
  • greeks.py: Functions for calculating option Greeks
  • payoff_visualizer.py: Tools for visualizing option payoffs
  • test_options.py: Comprehensive test script with examples

Dependencies

  • NumPy
  • SciPy
  • Matplotlib

License

This project is licensed under the MIT License - see the LICENSE file for details.

Bash Script

The project includes a bash script (run_tests.sh) that automates the process of running the options simulation. The script:

  1. Creates and activates a virtual environment
  2. Installs required dependencies
  3. Runs the test suite
  4. Generates the Jupyter notebook tutorial
  5. Cleans up temporary files

To use the bash script:

# Make the script executable
chmod +x run_simulation.sh

# Run the script
./run_simulation.sh

The script will:

  • Create a virtual environment named venv
  • Install all required packages from requirements.txt
  • Run the test suite to verify functionality
  • Generate the Jupyter notebook tutorial
  • Clean up any temporary files

Note: Make sure you have Python 3.8+ installed on your system before running the script.

About

A Python package implementing the Black-Scholes model for options pricing, Greeks calculation, and payoff visualization. Perfect for quantitative finance analysis and educational purposes.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors