This project implements an interactive Black-Scholes Option Pricing calculator with a Streamlit GUI, featuring dynamic heatmaps and MySQL data persistence. The project structure is designed to host different parts of the system as microservices for modularity and reliability.
The model uses the following inputs:
- Current Asset Price
- Strike Price
- Time to Maturity
- Volatility
- Risk-Free Interest Rate
The GUI allows users to:
- Enter values for the model inputs
- View an interactive heatmap of call and put option prices
- Adjust volatility and stock prices using sliding bars
- Enter purchase prices for call and put options
- View Profit/Loss (P/L) based on input and purchase prices
Heatmap features:
- Updates dynamically with user input
- Color-coded: green for higher values, red for lower values
- Displays option prices (not P/L)
- Inputs and outputs are saved to a MySQL relational database
- Database structure:
- Table with 6 rows and 5 columns
- Columns:
- Base inputs (Black Scholes model parameters)
- Volatility and future shocks against base inputs
- P/L associated with shock and input
- Calculation ID (links outputs to distinct inputs)
- Unique identifier for each shock/volatility combination
- Implement Black Scholes model calculation
- Create Streamlit GUI with input fields and heatmap visualization
- Add interactivity to GUI (sliding bars, dynamic updates)
- Implement P/L calculation
- Set up MySQL database and connection
- Implement data saving and retrieval functions
- Integrate all components and test thoroughly
To enhance security and make the project safe for public repositories, the following improvements have been implemented:
- Environment variables: Sensitive information such as database credentials are now managed using environment variables.
- Non-root user: The Dockerfile now creates and uses a non-root user for running the application.
- MySQL healthcheck: A healthcheck has been added to ensure the MySQL service is ready before the application attempts to connect.
- Secure database initialization: The MySQL service now creates a specific user for the application instead of using the root user.
-
Clone the repository:
git clone https://github.com/yourusername/black-scholes-option-pricer.git cd black-scholes-option-pricer
-
Create a
.env
file in the project root with the following content:MYSQL_HOST=mysql MYSQL_USER=options_user MYSQL_PASSWORD=your_secure_password MYSQL_DATABASE=options_db MYSQL_ROOT_PASSWORD=your_secure_root_password
Replace
your_secure_password
andyour_secure_root_password
with strong, unique passwords. -
Build and run the Docker containers:
docker-compose up --build
-
Access the application at
http://localhost:8501
Note: The .env
file contains sensitive information and should not be committed to version control. It has been added to .gitignore
for this purpose.
- Connect to a data lake or repository for testing ideas
- Optimize data usage and efficiency