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.
- 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
- Clone the repository:
git clone https://github.com/reetmitra/options_simulator.git
cd options_simulator- Install the required packages:
pip install -r requirements.txtRun the test script to see the library in action:
python test_options.pyThis will:
- Calculate call and put option prices
- Compute all Greeks for both options
- Generate payoff diagrams (saved as PNG files)
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}")black_scholes.py: Core Black-Scholes pricing functionsgreeks.py: Functions for calculating option Greekspayoff_visualizer.py: Tools for visualizing option payoffstest_options.py: Comprehensive test script with examples
- NumPy
- SciPy
- Matplotlib
This project is licensed under the MIT License - see the LICENSE file for details.
The project includes a bash script (run_tests.sh) that automates the process of running the options simulation. The script:
- Creates and activates a virtual environment
- Installs required dependencies
- Runs the test suite
- Generates the Jupyter notebook tutorial
- Cleans up temporary files
To use the bash script:
# Make the script executable
chmod +x run_simulation.sh
# Run the script
./run_simulation.shThe 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.