This repository contains a simple web app for calculating European option prices using three different methods:
- Black-Scholes model
- Monte Carlo simulation
- Binomial model
The app is implemented in Python 3.9 and uses the Streamlit library for visualization.
A mathematical model used to calculate the theoretical price of European-style options, based on factors like current stock price, strike price, time to expiration, risk-free rate, and volatility.
A probabilistic method that uses random sampling to estimate option prices by simulating multiple possible price paths of the underlying asset.
A discrete-time model that represents the evolution of the underlying asset's price as a binomial tree, allowing for the calculation of option prices at different time steps.
- Fetches latest stock price data from Yahoo Finance API using pandas-datareader
- Caches data using requests-cache to avoid duplicate API calls
- Allows users to input various parameters:
- Strike price
- Risk-free rate (%)
- Sigma (Volatility) (%)
- Exercise date
- Calculates option prices based on user inputs
- Provides a user-friendly interface for testing different scenarios
demo/
: Contains GIF files demonstrating the Streamlit appoption_pricing/
: Python package containing model implementationsstreamlit_app.py
: Main script for the Streamlit web appRequirements.txt
: List of required Python packagesDockerfile
: Configuration for running the app in a Docker container
The easiest way to run the app is using Docker. Make sure you have Docker installed on your machine before proceeding.
-
Navigate to the repository directory in your terminal.
-
Build the Docker image:
docker build -t options-pricing:latest .
-
Verify the image was built successfully:
docker image ls
-
Run the Docker container:
docker run -p 8080:8080 options-pricing:latest
-
Access the app in your web browser at:
http://0.0.0.0:8080/
To deploy the Docker container to Google Cloud Platform (GCP), follow these steps:
-
Prerequisites:
- Have a Google account
- Create a project on Google Cloud Console
- Set up billing for your project (be aware of GCP's pricing structure)
- Install and set up Google Cloud SDK
-
Verify and set your GCP project:
- Check the current project:
gcloud config get-value project
- Set a different project if needed:
gcloud config set project YOUR_PROJECT_NAME
- Check the current project:
-
Deploy the application:
- Run the following command (uses the app.yaml file in your project):
gcloud app deploy
- Select the nearest server location when prompted
- Wait for the deployment process to complete
- Run the following command (uses the app.yaml file in your project):
-
Access your web app:
- After deployment, you'll receive a URL for your app
- The URL format will be: https://YOUR_PROJECT_NAME.REGION.r.appspot.com/
- You can also find this URL in the Google Cloud Console
Note: Ensure you understand GCP's pricing before deploying to avoid unexpected charges.
By following these instructions, you can easily set up and explore the option pricing models using the Streamlit web app. Feel free to experiment with different parameters and see how they affect the calculated option prices.