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
ByteTrack超详细教程!训练自己的数据集&&摄像头实时检测跟踪

ByteTrack超详细教程!训练自己的数据集&&摄像头实时检测跟踪

Double-zh 45 Dec 19, 2022
Multiwavelets-based operator model

Multiwavelet model for Operator maps Gaurav Gupta, Xiongye Xiao, and Paul Bogdan Multiwavelet-based Operator Learning for Differential Equations In Ne

Gaurav 33 Dec 04, 2022
HuSpaCy: industrial-strength Hungarian natural language processing

HuSpaCy: Industrial-strength Hungarian NLP HuSpaCy is a spaCy model and a library providing industrial-strength Hungarian language processing faciliti

HuSpaCy 120 Dec 14, 2022
Grad2Task: Improved Few-shot Text Classification Using Gradients for Task Representation

Grad2Task: Improved Few-shot Text Classification Using Gradients for Task Representation Prerequisites This repo is built upon a local copy of transfo

Jixuan Wang 10 Sep 28, 2022
Fast Differentiable Matrix Sqrt Root

Official Pytorch implementation of ICLR 22 paper Fast Differentiable Matrix Square Root

YueSong 42 Dec 30, 2022
[CVPR 2021] Generative Hierarchical Features from Synthesizing Images

[CVPR 2021] Generative Hierarchical Features from Synthesizing Images

GenForce: May Generative Force Be with You 148 Dec 09, 2022
A way to store images in YAML.

YAMLImg A way to store images in YAML. I made this after seeing Roadcrosser's JSON-G because it was too inspiring to ignore this opportunity. Installa

5 Mar 14, 2022
State-of-the-art language models can match human performance on many tasks

Status: Archive (code is provided as-is, no updates expected) Grade School Math [Blog Post] [Paper] State-of-the-art language models can match human p

OpenAI 259 Jan 08, 2023
AITUS - An atomatic notr maker for CYTUS

AITUS an automatic note maker for CYTUS. 利用AI根据指定乐曲生成CYTUS游戏谱面。 效果展示:https://www

GradiusTwinbee 6 Feb 24, 2022
Simplified interface for TensorFlow (mimicking Scikit Learn) for Deep Learning

SkFlow has been moved to Tensorflow. SkFlow has been moved to http://github.com/tensorflow/tensorflow into contrib folder specifically located here. T

3.2k Dec 29, 2022
Official Pytorch implementation of the paper "MotionCLIP: Exposing Human Motion Generation to CLIP Space"

MotionCLIP Official Pytorch implementation of the paper "MotionCLIP: Exposing Human Motion Generation to CLIP Space". Please visit our webpage for mor

Guy Tevet 173 Dec 26, 2022
⚡ H2G-Net for Semantic Segmentation of Histopathological Images

H2G-Net This repository contains the code relevant for the proposed design H2G-Net, which was introduced in the manuscript "Hybrid guiding: A multi-re

André Pedersen 8 Nov 24, 2022
[CVPR21] LightTrack: Finding Lightweight Neural Network for Object Tracking via One-Shot Architecture Search

LightTrack: Finding Lightweight Neural Networks for Object Tracking via One-Shot Architecture Search The official implementation of the paper LightTra

Multimedia Research 290 Dec 24, 2022
VideoGPT: Video Generation using VQ-VAE and Transformers

VideoGPT: Video Generation using VQ-VAE and Transformers [Paper][Website][Colab][Gradio Demo] We present VideoGPT: a conceptually simple architecture

Wilson Yan 470 Dec 30, 2022
Code for the RA-L (ICRA) 2021 paper "SeqNet: Learning Descriptors for Sequence-Based Hierarchical Place Recognition"

SeqNet: Learning Descriptors for Sequence-Based Hierarchical Place Recognition [ArXiv+Supplementary] [IEEE Xplore RA-L 2021] [ICRA 2021 YouTube Video]

Sourav Garg 63 Dec 12, 2022
University of Rochester 2021 Summer REU focusing on music sentiment transfer using CycleGAN

Music-Sentiment-Transfer University of Rochester 2021 Summer REU focusing on music sentiment transfer using CycleGAN Poster: Music Sentiment Transfer

Miles Sigel 2 Jan 24, 2022
This tutorial repository is to introduce the functionality of KGTK to first-time users

Welcome to the KGTK notebook tutorial The goal of this tutorial repository is to introduce the functionality of KGTK to first-time users. The Knowledg

USC ISI I2 58 Dec 21, 2022
NeRF visualization library under construction

NeRF visualization library using PlenOctrees, under construction pip install nerfvis Docs will be at: https://nerfvis.readthedocs.org import nerfvis s

Alex Yu 196 Jan 04, 2023
The official implementation of CircleNet: Anchor-free Detection with Circle Representation, MICCAI 2030

CircleNet: Anchor-free Detection with Circle Representation The official implementation of CircleNet, MICCAI 2020 [PyTorch] [project page] [MICCAI pap

The Biomedical Data Representation and Learning Lab 45 Nov 18, 2022
Source code of the paper "Deep Learning of Latent Variable Models for Industrial Process Monitoring".

Source code of the paper "Deep Learning of Latent Variable Models for Industrial Process Monitoring".

Xiangyin Kong 7 Nov 08, 2022