How ddhruvin/black-scholes works
Project type and purpose
• Purpose: let users vary model parameters (spot price, volatility, time to maturity, strike, interest rate), fetch live spot prices from Yahoo Finance via yfinance, compute call/put prices, and render dynamic heatmaps.
File structure
• BlackScholes.py
– Encapsulates the core Black-Scholes pricing functions (call/put formulas, vectorized calculations).
• streamlit_app.py
– Implements the Streamlit UI: parameter inputs, calls to BlackScholes module, yfinance data fetch, and rendering of heatmaps via matplotlib.
• requirements.txt
– Declares dependencies (streamlit, yfinance, numpy, matplotlib, etc.).
• README.md
– Describes purpose, features, and links.
README for insights
• Interactive heatmap of option prices.
• Real-time updates on parameter change.
• Dependencies: yfinance for live data, numpy for math, matplotlib for plots.
Components & their relationships
a. Main components
1. User (Browser)
2. Streamlit Server (streamlit_app.py) – UI layer
3. Compute Module (BlackScholes.py) – Business logic
4. External Data Source (Yahoo Finance via yfinance)
5. Visualization Library (matplotlib)
6. Hosting Environment (Streamlit Cloud or local Python runtime)
b. Interactions
• User adjusts sliders/inputs in the browser → HTTP/WebSocket event → Streamlit server.
• Streamlit_app parses inputs, calls yfinance API to fetch spot price data.
• Streamlit_app invokes functions in BlackScholes.py to compute option price matrices.
• Computed arrays are passed to matplotlib to generate a heatmap image.
• Streamlit renders the heatmap + numeric outputs back to the browser.
c. Architectural patterns & principles
• Separation of concerns: UI logic vs. pricing logic.
• Single process, event-driven server (Streamlit).
• External integration: loosely coupled call to yfinance.
d. Key technologies
• Python 3.x, Streamlit framework
• yfinance (data ingestion)
• numpy (numerical computing)
• matplotlib (plotting)
• Hosting: Streamlit Cloud or any Python-capable server
Elements
– Blue for internal modules (Streamlit_app, BlackScholes.py)
– Green for external services (yfinance API)
– Yellow for libraries (numpy, matplotlib)
– Grey for hosting/runtime environment
Putting it all together
• Input Widgets (sliders/text)
• Data Fetch Component (yfinance client)
• Compute Component (calls to BlackScholes.py)
• Rendering Component (matplotlib)