How oskarimikkila/empirical-deep-hedging works
Project type and purpose
• This is a Python-based research codebase for “Empirical Deep Hedging” (Mikkilä & Kanniainen, 2021). It implements a deep reinforcement-learning (actor-critic) approach to hedging under various volatility models (GBM, Heston, empirical).
• Key use cases:
• Train a hedging agent (main.py)
• Validate and select the best model (testing.py --validate)
• Evaluate a trained model on test scenarios (testing.py --test)
File structure
• Top-level:
• main.py, testing.py – entry points for training and evaluation
• requirements.txt, settings.json – global config and dependencies
• data/ – historical time series and param CSVs
• settings/ – preconfigured JSONs for different model/risk-factor setups
• include/ modules:
• env.py, option_functions.py – simulation environment & option payoffs
• data_keeper.py – episode buffer and batch preparation
• actor_critic.py, network.py – RL agent and neural-network architectures
• simulation.py – orchestrates scenario generation loops
• settings.py – parses JSON settings into usable parameters
• utility.py – logging, metrics, helper routines
Key insights from README
• Supports three volatility frameworks (GBM, Heston, Empirical) × three risk factors
• Default settings read from settings.json unless overridden by --settings
• Targets Python 3.8, tested on Windows; dependencies in requirements.txt
Main components
a. Data Layer
• Historical time series (data/1yr_treasury.csv)
• Model parameters (data/heston_params.csv)
• Settings JSONs (settings/*.json)
b. Simulation Layer
• env.py: market environment stepping
• option_functions.py: payoff calculations
• simulation.py: runs Monte Carlo scenarios using settings
c. Data Keeper Layer
• data_keeper.py: collects transitions, prepares training batches
d. Model Layer
• network.py: defines neural-network modules
• actor_critic.py: builds the actor and critic, loss functions
e. Orchestration/Control
• main.py:
– Load settings + data
– Initialize environment, data keeper, actor-critic agent
– Loop: simulate → collect → train → save checkpoints
• testing.py:
– Load saved model
– Re-simulate or replay validation/test episodes
– Compute metrics, pick best checkpoint
f. External Dependencies & Outputs
• PyTorch/TensorFlow (per requirements.txt)
• Checkpoint files, logs, result CSVs or figures
Relationships and interactions
• Settings JSON → parsed by settings.py → passed to env.py, simulation.py, network.py
• Raw data CSVs → loaded by simulation.py for scenario generation
• simulation.py + option_functions.py produce state, reward trajectories → data_keeper.py
• data_keeper.py yields batches → fed into actor_critic.py → updates via network.py
• main.py orchestrates the train loop; testing.py re-uses env.py + network.py for evaluation
Architectural patterns and principles
• Modular separation: data, simulation, model, orchestration
• Configuration-driven via JSON for reproducibility
• Clear pipeline: Input → Simulate → Buffer → Learn → Evaluate
• Single-process batch training (no microservices), but easily parallelizable at the simulation stage
Detail level
• Every module in include/ as its own component
• Data folder and settings folder as sources for the simulation engine
• Model checkpoint files as the output of the training pipeline