This module provides comprehensive option pricing tools using various mathematical models and techniques.
The Black-Scholes formula calculates the theoretical price of European-style options:
For a Call Option:
C = S * N(d1) - K * e^(-r*T) * N(d2)
For a Put Option:
P = K * e^(-r*T) * N(-d2) - S * N(-d1)
Where:
C
: Call Option PriceP
: Put Option PriceS
: Current Stock PriceK
: Strike Pricer
: Risk-Free Interest RateT
: Time to ExpirationN()
: Cumulative Standard Normal Distribution Function
- d1 Calculation:
d1 = [ln(S/K) + (r + σ²/2) * T] / (σ * √T)
ln()
: Natural Logarithmσ
: Stock Price Volatility
- d2 Calculation:
d2 = d1 - σ * √T
-
Delta (Δ):
- Measures rate of change in option price relative to stock price
- Call Option:
N(d1)
- Put Option:
N(d1) - 1
-
Gamma (Γ):
- Measures rate of change in delta
Γ = φ(d1) / (S * σ * √T)
Where
φ()
is the standard normal probability density function -
Vega (ν):
- Measures sensitivity to volatility
ν = S * φ(d1) * √T
-
Theta (Θ):
- Measures time decay of option value
- Complex calculation involving stock price, volatility, and time
The Binomial Tree model discretizes time into multiple steps, creating a tree of possible stock price movements.
- Up and Down Factors:
u = e^(σ * √Δt) # Up factor
d = 1/u # Down factor
- Risk-Neutral Probability:
p = (e^(r*Δt) - d) / (u - d)
- Option Value Calculation:
- Backward induction from expiration to present
- At each node, compare intrinsic value with expected discounted value
- Handles American-style options
- More flexible than Black-Scholes
- Can incorporate early exercise
- Reverse-engineer volatility from market option prices
- Uses iterative numerical methods (e.g., Newton-Raphson)
- Log-normal distribution of stock prices
- No transaction costs
- No dividends
- Risk-free rate and volatility are constant
- European-style options only
- Discrete-time model
- Stock price can move up or down
- Risk-neutral pricing framework
This interactive Streamlit application provides comprehensive option pricing tools using various mathematical models and techniques, including:
- Black-Scholes Option Pricing Model
- Binomial Tree Option Pricing Model
- Advanced Option Pricing Techniques
- Python 3.8+
- pip (Python package manager)
- Clone the repository:
git clone https://github.com/Kohnnn/option-pricing-model.git
cd option-pricing-model
- Create a virtual environment (optional but recommended):
python -m venv venv
source venv/bin/activate # On Windows, use `venv\Scripts\activate`
- Install dependencies:
pip install -r requirements.txt
To launch the Streamlit application:
streamlit run streamlit_app.py
- Interactive option pricing calculation
- Multiple pricing model comparisons
- Visualization of pricing accuracy
- Greeks calculation
- Model performance analysis
Calculates theoretical prices for European-style options.
Provides a more flexible approach to option pricing by discretizing time.
Contributions are welcome! Please feel free to submit a Pull Request.
- Ensure you have Python 3.9-3.12 installed
- Create a virtual environment:
python -m venv venv source venv/bin/activate # On Windows use `venv\Scripts\activate`
- Upgrade pip and setuptools:
pip install --upgrade pip setuptools wheel
- Install dependencies:
pip install -r requirements.txt
- Run the Streamlit app:
streamlit run streamlit_app.py
- Ensure you have a
requirements.txt
file with all dependencies - Set the main file as
streamlit_app.py
- Use Python 3.9-3.12 for compatibility
- If you encounter
ModuleNotFoundError: No module named 'distutils'
:- Ensure you're using Python 3.9-3.12
- Upgrade pip, setuptools, and wheel
- Use the latest versions of dependencies
- Consider using
numpy>=1.26.0
and other flexible version constraints
# Create virtual environment
python -m venv venv
source venv/bin/activate # On Windows use `venv\Scripts\activate`
# Install dependencies
pip install -r requirements.txt
# On Windows
run.bat
# On macOS/Linux
python app.py
Navigate to http://localhost:5000
in your web browser.
from option_pricing import calculate_option_price
# Calculate option price
price = calculate_option_price(
spot_price=100,
strike_price=100,
risk_free_rate=0.05,
volatility=0.2,
time_to_expiry=1.0,
option_type='call'
)
- Choose Option Type (Call or Put)
- Enter Option Parameters
- Click "Calculate Option Price"
Added:
- Implied Volatility Calculation
- Scenario Analysis
- Models Comparison
- Tooltips for Clarity
- Greeks Calculation (Delta, Gamma, Vega, Theta)
MIT License
- Fomula Accuracy
- More Robust Calculation
- Pricing for other assets classes