A Python package which implements the deep hedging algorithm. Target is learning optimal hedges through a deep feed forward neural network (DFNN), in order to minimize terminal loss when hedging a written European call option.
- Simulates stock prices following a geometric Brownian motion
- Calculates call prices under the Black Scholes model
- Trains a DFNN at each timestep on stocks, calls & strike to minimize terminal error
- Runs predictions using the trained model
- Benchmarks model performance against Black Scholes visible in charts, KPIs & KRIs
- Python 3.11+ (tested with 3.11.9)
- Required dependencies (see requirements.txt for details):
numpy==2.1.3
tensorflow==2.19.0
scipy==1.16.0
matplotlib==3.10.5
seaborn==0.13.2
-
Clone the repository:
git clone https://github.com/hb84ffm/deep-hedging.git
cd deep_call_hedger -
Create & activate your virtual environment:
python3 -m venv venv
source venv/bin/activate # On Mac/Linux
venv\Scripts\activate # On Windows -
Install dependencies:
pip install -r requirements.txt
-
Train the deep hedging model (or use the pretrained model deep_hedging_64.keras):
python main_training.py
-> Saves a trained ".keras" model to the models/ folder. -
Run prediction & analysis:
python main_prediction.py
-> Uses the trained model to run simulations & generate plots.
deep_call_hedger/
├─── __init__.py
├─── main_prediction.py # Orchestrates the prediction
├─── main_training.py # Orchestrates the training
├─── dh_model/
├─── __init__.py
├─── dh_model.py # Designs the model (computational graph) by Keras functional API
├─── models/
├─── deep_hedging_64.keras # Pretrained deep_hedging_64.keras model trained across 64 timesteps
├── options/
├─── __init__.py
├─── bs.py # Black Scholes calculator for European calls
├── prediction/
├─── analysis.py # Derives analytics (charts, KPIs & KRIs) on predicted data
├─── prediction.py # Generates prediction data & runs prediction using the trained model
├── stocks/
├── __init__.py
├─── stocks.py # Stock simulation
├── training/
├─── __init__.py
├─── training.py # Compiles the model & starts the training
See provided Jupyter notebook example for explanation.
Josef Teichmann's implementation
For questions or feedback reach out to me via: GitHub.