A Flask application for calculating and monitoring option Greeks in a portfolio, with support for position (buy/sell) and lot-based quantities to accurately measure portfolio risk.
- Accurate Greeks Calculation: Individual and portfolio-level option Greeks (Delta, Gamma, Theta, Vega, Rho)
- Dynamic Lot Size Fetching: Real-time lot sizes from OpenAlgo API instead of hardcoded values
- Position-Aware Calculations: Proper sign conventions for buy/sell positions following standard option theory
- Lot-Based Display: Individual option Greeks multiplied by lots for realistic position sizing
- Portfolio Aggregation: Portfolio Greeks calculated as sum of individual option display values
- Real-Time Market Data: Live spot prices and option prices via OpenAlgo API
- Implied Volatility Calculation: Dynamic IV calculation from market prices using Black-Scholes
- Modern UI: Built with Tailwind CSS and Daisy UI for responsive design
- Secure API Management: Protected API key storage with settings page
- Caching System: Intelligent caching to prevent API overuse while maintaining data freshness
- Fixed sign conventions: Proper Greeks signs for all position types (BUY/SELL × CE/PE)
- Corrected portfolio aggregation: Portfolio Greeks now correctly sum individual display values
- Interest rate standardization: Set to 0% as per standard practice
- Dynamic lot size fetching: Uses OpenAlgo
symbolAPI instead of hardcoded values - Improved IV calculation: Dynamic implied volatility from market prices with fallbacks
- Individual Greeks: Now properly multiplied by lots (standard convention)
- Portfolio Greeks: Sum of individual option display values (no double multiplication)
- Consistent calculations: Same logic for both web interface and API endpoints
- Clone the repository
- Install the required packages:
pip install -r requirements.txt- Run the application:
python app.pyThe application will be available at http://localhost:5001
You'll need to obtain an OpenAlgo API key to use this application:
- Set up and run your OpenAlgo application (typically on
http://127.0.0.1:5000) - Log in to your OpenAlgo application
- Navigate to your account settings or API section
- Generate a new API key or copy your existing one
- Enter this key in the Settings page of the Portfolio Greeks application
The application expects option symbols in the following format:
NIFTY31JUL2525200CE where:
NIFTYis the underlying symbol31JUL25is the expiration date (DD-MMM-YY)25200is the strike priceCEis the option type (CE for Call, PE for Put)
Individual option Greeks are multiplied by the number of lots to show position-level risk:
- Display Formula:
Greek × Lots - Example: If delta = 0.5 per unit and you have 2 lots, display shows 1.0
Portfolio Greeks are calculated by summing all individual option display values:
- Portfolio Formula:
Sum of (Greek × Lots)for all options - Proper Risk Aggregation: Shows total portfolio exposure
Portfolio Greeks follow standard option theory, accounting for position type:
| Position | Delta | Gamma | Theta | Vega | Rho |
|---|---|---|---|---|---|
| Long Call | + | + | - | + | + |
| Short Call | - | - | + | - | - |
| Long Put | - | + | - | + | - |
| Short Put | + | - | + | - | + |
Sign Convention:
- Long positions: Keep original Black-Scholes signs
- Short positions: Flip all Greeks signs (consistent across all Greeks)
- Interest Rate: 0% (standard for Indian options)
- Implied Volatility: Calculated from market prices using mibian library
- Lot Sizes: Fetched dynamically from OpenAlgo API
- Greeks Calculation: Uses mibian library for Black-Scholes calculations
- API Integration: OpenAlgo API for market data and lot sizes
- Caching: Response caching with configurable expiry
- Error Handling: Comprehensive error handling and fallbacks
- Template:
templates/index.htmlwith dynamic Greeks display - Styling: Tailwind CSS with DaisyUI components
- Real-time Updates: JavaScript for dynamic data refresh
- Lot Size Fetching:
get_lot_size()function uses OpenAlgo symbol API - API Client:
get_api_client()with secure key management - Portfolio Management: JSON-based portfolio storage
- Flask: Web framework with CSRF protection
- Mibian: Black-Scholes options pricing and Greeks calculation
- OpenAlgo API: Market data provider and lot size information
- Tailwind CSS & DaisyUI: Modern, responsive UI framework
- JavaScript: Dynamic UI updates and real-time data refresh
- JSON: Configuration and portfolio data storage
- Large Portfolio Greeks Values: Ensure you're using the latest version with corrected aggregation
- API Connection: Verify OpenAlgo is running on
http://127.0.0.1:5000 - Symbol Format: Check option symbols follow the expected format
- Lot Size Issues: Verify API key has permissions to access symbol information
Enable Flask debug mode for detailed error messages:
export FLASK_DEBUG=1
python app.py- Fork the repository
- Create a feature branch
- Make your changes with appropriate tests
- Submit a pull request
MIT