Deep Learning Algorithms for Hedging with Frictions

Overview

Deep Learning Algorithms for Hedging with Frictions

This repository contains the Forward-Backward Stochastic Differential Equation (FBSDE) solver and the Deep Hedging, as described in reference [2]. Both of them are implemented in PyTorch.

Basic Setup

The special case with following assumptions is considered:

  • the dynamic of the market satisfies that return and voalatility are constant;
  • the cost parameter is constant;
  • the endowment volatility is in the form of where is constant;
  • the frictionless strategy satisfies that and

On top of that, we consider two calibrated models: a quadratic transaction cost models, and a power cost model with elastic parameter of 3/2. In both experiments, the FBSDE solver and the Deep Hedging are implemented, as well as the asymptotic formula from Theorem 3.6 in reference [2].

For the case of quadratic costs, the ground truth from equation (3.7) in reference [2] is also compared. See Script/sample_code_quadratic_cost.py for details.

For the case of 3/2 power costs, the ground truth is no longer available in closed form. Meanwhile, in regard to the asymptotic formula g(x) in equation (3.8) in reference [2], the numerical solution by SciPy is not stable, thus it is solved via MATHEMATICA (see Script/power_cost_ODE.nb). Consequently, the value of g(x) corresponding to x ranging from 0 to 50 by 0.0001, is stored in table Data/EVA.txt. Benefitted from the oddness and the growth conditions (equation (3.9) in reference [2]), the value of g(x) on is obatinable. Following that, the numerical result of the asymptotic solution is compared with two machine learning methods. See Script/sample_code_power_cost.py for details.

The general variables and the market parameters in the code are summarized below:

Variable Meaning
q power of the trading cost, q
S_OUTSTANDING total shares in the market, s
TIME trading horizon, T
TIME_STEP time discretization, N
DT
GAMMA risk aversion,
XI_1 endowment volatility parameter,
PHI_INITIAL initial holding,
ALPHA market volatility,
MU_BAR market return,
LAM trading cost parameter,
test_samples number of test sample path, batch_size

FBSDE solver

For the detailed implementation of the FBSDE solver, see Script/sample_code_FBSDE.py;
The core dynamic is defined in the method System.forward(), and the key variables in the code are summarized below:

Variable Meaning
time_step time discretization, N
n_samples number of sample path, batch_size
dW_t iid normally distributed random variables with mean zero and variance ,
W_t Brownian motion at time t,
XI_t Brownian motion at time t,
sigma_t vector of 0
sigmaxi_t vector of 1
X_t vector of 1
Y_t vector of 0
Lam_t 1
in_t input of the neural network
sigmaZ_t output of the neural network ,
Delta_t difference between the frictional and frictionless positions (the forward component) divided by the endowment parameter,
Z_t the backward component,

Deep Hedging

For the detailed implementation of the Deep Hedging, see Script/sample_code_Deep_Hedging.py;
The core dynamic of the Deep Hedging is defined in the function TRAIN_Utility(), and the key variables in the code are summarized below:

Variable Meaning
time_step time discretization, N
n_samples number of sample path, batch_size
PHI_0_on_s initial holding divided by the total shares in the market,
W collection of the Brownian motion, throughout the trading horizon,
XI_W_on_s collection of the endowment volatility divided by the total shares in the market, throughout the trading horizon,
PHI_on_s collection of the frictional positions divided by the total shares in the market, throughout the trading horizon,
PHI_dot_on_s collection of the frictional trading rate divided by the total shares in the market, throughout the trading horizon,
loss_Utility minus goal function,

Example

Here we proivde an example for the quadratic cost case (q=2) with the trading horizon of 21 days (TIME=21).

The trading horizon is discretized in 168 time steps (TIME_STEP=168). The parameters are taken from the calibration in [1]:

Parameter Value Code
agent risk aversion GAMMA=1.66*1e-13
total shares outstanding S_OUTSTANDING=2.46*1e11
stock volatility ALPHA=1.88
stock return MU_BAR=0.5*GAMMA*ALPHA**2
endowment volatility parameter XI_1=2.19*1e10
trading cost parameter LAM=1.08*1e-10

And these lead to the optimal trading rate (left panel) and the optimal position (right panel) illustrated below, leanrt by the FBSDE solver and the Deep Hedging, as well as the ground truth and the Leading-order solution based on the asymptotic formula:

TR=21_q=2
With the same simulation with test batch size of 3000 (test_samples=3000), the expectation and the standard deviation of the goal function and the mean square error of the terminal trading rate are calculated, as summarized below:

Method
FBSDE
Deep Q-learning
Leading Order Approximation
Ground Truth

See more examples and discussion in Section 4 of paper [2].

Acknowledgments

Reference

[1] Asset Pricing with General Transaction Costs: Theory and Numerics, L. Gonon, J. Muhle-Karbe, X. Shi. [Mathematical Finance], 2021.

[2] Deep Learning Algorithms for Hedging with Frictions, X. Shi, D. Xu, Z. Zhang. [arXiv], 2021.

You might also like...
Time-series-deep-learning - Developing Deep learning LSTM, BiLSTM models, and NeuralProphet for multi-step time-series forecasting of stock price.
Time-series-deep-learning - Developing Deep learning LSTM, BiLSTM models, and NeuralProphet for multi-step time-series forecasting of stock price.

Stock Price Prediction Using Deep Learning Univariate Time Series Predicting stock price using historical data of a company using Neural networks for

FTIR-Deep Learning - FTIR Deep Learning With Python

CANDIY-spectrum Human analyis of chemical spectra such as Mass Spectra (MS), Inf

 Deep Learning: Architectures & Methods Project: Deep Learning for Audio Super-Resolution
Deep Learning: Architectures & Methods Project: Deep Learning for Audio Super-Resolution

Deep Learning: Architectures & Methods Project: Deep Learning for Audio Super-Resolution Figure: Example visualization of the method and baseline as a

A toolkit for developing and comparing reinforcement learning algorithms.

Status: Maintenance (expect bug fixes and minor updates) OpenAI Gym OpenAI Gym is a toolkit for developing and comparing reinforcement learning algori

Metric learning algorithms in Python

metric-learn: Metric Learning in Python metric-learn contains efficient Python implementations of several popular supervised and weakly-supervised met

Parris, the automated infrastructure setup tool for machine learning algorithms.
Parris, the automated infrastructure setup tool for machine learning algorithms.

README Parris, the automated infrastructure setup tool for machine learning algorithms. What Is This Tool? Parris is a tool for automating the trainin

FedJAX is a library for developing custom Federated Learning (FL) algorithms in JAX.

FedJAX: Federated learning with JAX What is FedJAX? FedJAX is a library for developing custom Federated Learning (FL) algorithms in JAX. FedJAX priori

A fast, distributed, high performance gradient boosting (GBT, GBDT, GBRT, GBM or MART) framework based on decision tree algorithms, used for ranking, classification and many other machine learning tasks.

Light Gradient Boosting Machine LightGBM is a gradient boosting framework that uses tree based learning algorithms. It is designed to be distributed a

PyTorch version of Stable Baselines, reliable implementations of reinforcement learning algorithms.
PyTorch version of Stable Baselines, reliable implementations of reinforcement learning algorithms.

PyTorch version of Stable Baselines, reliable implementations of reinforcement learning algorithms.

Owner
Xiaofei Shi
Xiaofei Shi
deep-table implements various state-of-the-art deep learning and self-supervised learning algorithms for tabular data using PyTorch.

deep-table implements various state-of-the-art deep learning and self-supervised learning algorithms for tabular data using PyTorch.

null 63 Oct 17, 2022
Machine Learning From Scratch. Bare bones NumPy implementations of machine learning models and algorithms with a focus on accessibility. Aims to cover everything from linear regression to deep learning.

Machine Learning From Scratch About Python implementations of some of the fundamental Machine Learning models and algorithms from scratch. The purpose

Erik Linder-Norén 21.8k Jan 9, 2023
Machine learning framework for both deep learning and traditional algorithms

NeoML is an end-to-end machine learning framework that allows you to build, train, and deploy ML models. This framework is used by ABBYY engineers for

NeoML 704 Dec 27, 2022
Predict stock movement with Machine Learning and Deep Learning algorithms

Project Overview Stock market movement prediction using LSTM Deep Neural Networks and machine learning algorithms Software and Library Requirements Th

Naz Delam 46 Sep 13, 2022
SLIDE : In Defense of Smart Algorithms over Hardware Acceleration for Large-Scale Deep Learning Systems

The SLIDE package contains the source code for reproducing the main experiments in this paper. Dataset The Datasets can be downloaded in Amazon-

Intel Labs 72 Dec 16, 2022
PyTorch implementations of deep reinforcement learning algorithms and environments

Deep Reinforcement Learning Algorithms with PyTorch This repository contains PyTorch implementations of deep reinforcement learning algorithms and env

Petros Christodoulou 4.7k Jan 4, 2023
Deep learning algorithms for muon momentum estimation in the CMS Trigger System

Deep learning algorithms for muon momentum estimation in the CMS Trigger System The Compact Muon Solenoid (CMS) is a general-purpose detector at the L

anuragB 2 Oct 6, 2021
PyTorch implementation of Federated Learning with Non-IID Data, and federated learning algorithms, including FedAvg, FedProx.

Federated Learning with Non-IID Data This is an implementation of the following paper: Yue Zhao, Meng Li, Liangzhen Lai, Naveen Suda, Damon Civin, Vik

Youngjoon Lee 48 Dec 29, 2022
Ivy is a templated deep learning framework which maximizes the portability of deep learning codebases.

Ivy is a templated deep learning framework which maximizes the portability of deep learning codebases. Ivy wraps the functional APIs of existing frameworks. Framework-agnostic functions, libraries and layers can then be written using Ivy, with simultaneous support for all frameworks. Ivy currently supports Jax, TensorFlow, PyTorch, MXNet and Numpy. Check out the docs for more info!

Ivy 8.2k Jan 2, 2023
Deep learning (neural network) based remote photoplethysmography: how to extract pulse signal from video using deep learning tools

Deep-rPPG: Camera-based pulse estimation using deep learning tools Deep learning (neural network) based remote photoplethysmography: how to extract pu

Terbe Dániel 138 Dec 17, 2022