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.

Owner
Xiaofei Shi
Xiaofei Shi
People log into different sites every day to get information and browse through these sites one by one

HyperLink People log into different sites every day to get information and browse through these sites one by one. And they are exposed to advertisemen

0 Feb 17, 2022
Video-face-extractor - Video face extractor with Python

Python face extractor Setup Create the srcvideos and faces directories Put your

2 Feb 03, 2022
A PyTorch implementation of a Factorization Machine module in cython.

fmpytorch A library for factorization machines in pytorch. A factorization machine is like a linear model, except multiplicative interaction terms bet

Jack Hessel 167 Jul 06, 2022
Benchmarking Pipeline for Prediction of Protein-Protein Interactions

B4PPI Benchmarking Pipeline for the Prediction of Protein-Protein Interactions How this benchmarking pipeline has been built, and how to use it, is de

Loïc Lannelongue 4 Jun 27, 2022
Implementation of "DeepOrder: Deep Learning for Test Case Prioritization in Continuous Integration Testing".

DeepOrder Implementation of DeepOrder for the paper "DeepOrder: Deep Learning for Test Case Prioritization in Continuous Integration Testing". Project

6 Nov 07, 2022
A Joint Video and Image Encoder for End-to-End Retrieval

Frozen️ in Time ❄️ ️️️️ ⏳ A Joint Video and Image Encoder for End-to-End Retrieval project page | arXiv | webvid-data Repository containing the code,

225 Dec 25, 2022
The code for the CVPR 2021 paper Neural Deformation Graphs, a novel approach for globally-consistent deformation tracking and 3D reconstruction of non-rigid objects.

Neural Deformation Graphs Project Page | Paper | Video Neural Deformation Graphs for Globally-consistent Non-rigid Reconstruction Aljaž Božič, Pablo P

Aljaz Bozic 134 Dec 16, 2022
MetaBalance: High-Performance Neural Networks for Class-Imbalanced Data

This repository is the official PyTorch implementation of Meta-Balance. Find the paper on arxiv MetaBalance: High-Performance Neural Networks for Clas

Arpit Bansal 20 Oct 18, 2021
A denoising diffusion probabilistic model (DDPM) tailored for conditional generation of protein distograms

Denoising Diffusion Probabilistic Model for Proteins Implementation of Denoising Diffusion Probabilistic Model in Pytorch. It is a new approach to gen

Phil Wang 108 Nov 23, 2022
Web mining module for Python, with tools for scraping, natural language processing, machine learning, network analysis and visualization.

Pattern Pattern is a web mining module for Python. It has tools for: Data Mining: web services (Google, Twitter, Wikipedia), web crawler, HTML DOM par

Computational Linguistics Research Group 8.4k Jan 03, 2023
A Multi-modal Perception Tracker (MPT) for speaker tracking using both audio and visual modalities

MPT A Multi-modal Perception Tracker (MPT) for speaker tracking using both audio and visual modalities. Implementation for our AAAI 2022 paper: Multi-

yidiLi 4 May 08, 2022
Website which uses Deep Learning to generate horror stories.

Creepypasta - Text Generator Website which uses Deep Learning to generate horror stories. View Demo · View Website Repo · Report Bug · Request Feature

Dhairya Sharma 5 Oct 14, 2022
Code for Multiple Instance Active Learning for Object Detection, CVPR 2021

MI-AOD Language: 简体中文 | English Introduction This is the code for Multiple Instance Active Learning for Object Detection (The PDF is not available tem

Tianning Yuan 269 Dec 21, 2022
Seeing if I can put together an interactive version of 3b1b's Manim in Streamlit

streamlit-manim Seeing if I can put together an interactive version of 3b1b's Manim in Streamlit Installation I had to install pango with sudo apt-get

Adrien Treuille 6 Aug 03, 2022
code for "Self-supervised edge features for improved Graph Neural Network training",

Self-supervised edge features for improved Graph Neural Network training Data availability: Here is a link to the raw data for the organoids dataset.

Neal Ravindra 23 Dec 02, 2022
PyTorch code for our paper "Gated Multiple Feedback Network for Image Super-Resolution" (BMVC2019)

Gated Multiple Feedback Network for Image Super-Resolution This repository contains the PyTorch implementation for the proposed GMFN [arXiv]. The fram

Qilei Li 66 Nov 03, 2022
Source code of our TTH paper: Targeted Trojan-Horse Attacks on Language-based Image Retrieval.

Targeted Trojan-Horse Attacks on Language-based Image Retrieval Source code of our TTH paper: Targeted Trojan-Horse Attacks on Language-based Image Re

fine 7 Aug 23, 2022
This repository accompanies the ACM TOIS paper "What can I cook with these ingredients?" - Understanding cooking-related information needs in conversational search

In this repository you find data that has been gathered when conducting in-situ experiments in a conversational cooking setting. These data include tr

6 Sep 22, 2022
Runtime type annotations for the shape, dtype etc. of PyTorch Tensors.

torchtyping Type annotations for a tensor's shape, dtype, names, ... Turn this: def batch_outer_product(x: torch.Tensor, y: torch.Tensor) - torch.Ten

Patrick Kidger 1.2k Jan 03, 2023
Tensorflow implementation of Semi-supervised Sequence Learning (https://arxiv.org/abs/1511.01432)

Transfer Learning for Text Classification with Tensorflow Tensorflow implementation of Semi-supervised Sequence Learning(https://arxiv.org/abs/1511.01

DONGJUN LEE 82 Oct 22, 2022