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
Predict and time series avocado hass

RECOMMENDER SYSTEM MARKETING TỔNG QUAN VỀ HỆ THỐNG DỮ LIỆU 1. Giới thiệu - Tiki là một hệ sinh thái thương mại "all in one", trong đó có tiki.vn, là

hieulmsc 3 Jan 10, 2022
Code for the paper "Regularizing Variational Autoencoder with Diversity and Uncertainty Awareness"

DU-VAE This is the pytorch implementation of the paper "Regularizing Variational Autoencoder with Diversity and Uncertainty Awareness" Acknowledgement

Dazhong Shen 4 Oct 19, 2022
Brain tumor detection using Convolution-Neural Network (CNN)

Detect and Classify Brain Tumor using CNN. A system performing detection and classification by using Deep Learning Algorithms using Convolution-Neural Network (CNN).

assia 1 Feb 07, 2022
Source code for our EMNLP'21 paper 《Raise a Child in Large Language Model: Towards Effective and Generalizable Fine-tuning》

Child-Tuning Source code for EMNLP 2021 Long paper: Raise a Child in Large Language Model: Towards Effective and Generalizable Fine-tuning. 1. Environ

46 Dec 12, 2022
Revisiting Weakly Supervised Pre-Training of Visual Perception Models

SWAG: Supervised Weakly from hashtAGs This repository contains SWAG models from the paper Revisiting Weakly Supervised Pre-Training of Visual Percepti

Meta Research 134 Jan 05, 2023
Jremesh-tools - Blender addon for quad remeshing

JRemesh Tools Blender 2.8 - 3.x addon for quad remeshing. Currently it is a wrap

Jayanam 89 Dec 30, 2022
A Novel Plug-in Module for Fine-grained Visual Classification

Pytorch implementation for A Novel Plug-in Module for Fine-Grained Visual Classification. fine-grained visual classification task.

ChouPoYung 109 Dec 20, 2022
City Surfaces: City-scale Semantic Segmentation of Sidewalk Surfaces

City Surfaces: City-scale Semantic Segmentation of Sidewalk Surfaces Paper Temporary GitHub page for City Surfaces paper. More soon! While designing s

14 Nov 10, 2022
A few stylization coreML models that I've trained with CreateML

CoreML-StyleTransfer A few stylization coreML models that I've trained with CreateML You can open and use the .mlmodel files in the "models" folder in

Doron Adler 8 Aug 18, 2022
PyTorch implementation of our method for adversarial attacks and defenses in hyperspectral image classification.

Self-Attention Context Network for Hyperspectral Image Classification PyTorch implementation of our method for adversarial attacks and defenses in hyp

22 Dec 02, 2022
Plato: A New Framework for Federated Learning Research

a new software framework to facilitate scalable federated learning research.

System <a href=[email protected] Lab"> 192 Jan 05, 2023
ProMP: Proximal Meta-Policy Search

ProMP: Proximal Meta-Policy Search Implementations corresponding to ProMP (Rothfuss et al., 2018). Overall this repository consists of two branches: m

Jonas Rothfuss 212 Dec 20, 2022
The 1st place solution of track2 (Vehicle Re-Identification) in the NVIDIA AI City Challenge at CVPR 2021 Workshop.

AICITY2021_Track2_DMT The 1st place solution of track2 (Vehicle Re-Identification) in the NVIDIA AI City Challenge at CVPR 2021 Workshop. Introduction

Hao Luo 91 Dec 21, 2022
The official implementation of the Hybrid Self-Attention NEAT algorithm

PUREPLES - Pure Python Library for ES-HyperNEAT About This is a library of evolutionary algorithms with a focus on neuroevolution, implemented in pure

Adrian Westh 91 Dec 12, 2022
End-to-End Referring Video Object Segmentation with Multimodal Transformers

End-to-End Referring Video Object Segmentation with Multimodal Transformers This repo contains the official implementation of the paper: End-to-End Re

608 Dec 30, 2022
Official Pytorch implementation of "Learning Debiased Representation via Disentangled Feature Augmentation (Neurips 2021, Oral)"

Learning Debiased Representation via Disentangled Feature Augmentation (Neurips 2021, Oral): Official Project Webpage This repository provides the off

Kakao Enterprise Corp. 68 Dec 17, 2022
The codes reproduce the figures and statistics in the paper, "Controlling for multiple covariates," by Mark Tygert.

The accompanying codes reproduce all figures and statistics presented in "Controlling for multiple covariates" by Mark Tygert. This repository also pr

Meta Research 1 Dec 02, 2021
A fuzzing framework for SMT solvers

yinyang A fuzzing framework for SMT solvers. Given a set of seed SMT formulas, yinyang generates mutant formulas to stress-test SMT solvers. yinyang c

Project Yin-Yang for SMT Solver Testing 145 Jan 04, 2023
Machine Learning Model deployment for Container (TensorFlow Serving)

try_tf_serving ├───dataset │ ├───testing │ │ ├───paper │ │ ├───rock │ │ └───scissors │ └───training │ ├───paper │ ├───rock

Azhar Rizki Zulma 5 Jan 07, 2022
Oriented Object Detection: Oriented RepPoints + Swin Transformer/ReResNet

Oriented RepPoints for Aerial Object Detection The code for the implementation of “Oriented RepPoints + Swin Transformer/ReResNet”. Introduction Based

96 Dec 13, 2022