This repository contains the Forward-Backward Stochastic Differential Equation (FBSDE) solver, the Deep Hedging, and the ST-Hedging, as described in reference [2]. All of them are implemented in PyTorch.
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
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, the Deep Hedging, and the ST-Hedging, are implemented, as well as the asymptotic formula from Equation (3.4) in reference [2].
For the case of quadratic costs, the ground truth from equation (4.1) 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.5) 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 (A.5) 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:
For high dimensional case with three stocks, we consider the quadratic transaction cost model. The asymptotic formula from Equation (3.4) in reference [2], and the ground truth from equation (4.1) in reference [2] are included in leading_order_quad
and ground_truth
of DynamicsFactory
class in
SingleAgent-Stage2/SingleAgentPipe.py
. And we implement the ST-Hedging algorithm illustrated in Section (4.3) in reference [2].
The general variables and the market parameters in the code are summarized below:
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:
For the detailed implementation of the FBSDE solver, see the class DynamicsFactory
in
SingleAgent-Stage2/SingleAgentPipe.py
;
The core dynamic is defined in the function fbsde_quad
, and the key variables in the code are summarized below:
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:
For the detailed implementation of the Deep Hedging, see the class DynamicsFactory
in
SingleAgent-Stage2/SingleAgentPipe.py
;
The core dynamic is defined in the function deep_hedging
, and the key variables in the code are summarized below:
For the detailed implementation of the ST-Hedging Algorithm, see the class DynamicsFactory
in
SingleAgent-Stage2/SingleAgentPipe.py
;
The core dynamic is defined in the function st_hedging
, and the key variables in the code are summarized below:
We provide an example for each of the quadratic cost case and the power cost case.
Here is 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]:
And these lead to the optimal trading rate (left panel) and the optimal position (right panel) illustrated below, leanrt by the FBSDE solver, the Deep Hedging, and the ST-Hedging as well as the ground truth and the Leading-order solution based on the asymptotic formula:
With the simulation of a 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 Solver | ||
Deep Hedging | ||
ST Hedging | ||
Leading Order Approximation | ||
Ground Truth |
Here is an example for the 3/2 power cost case (q=3/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]:
And these lead to the optimal trading rate (left panel) and the optimal position (right panel) illustrated below, leanrt by the FBSDE solver, the Deep Hedging, and the ST-Hedging as well as the Leading-order solution based on the asymptotic formula:
With the simulation of a 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 Solver | ||
Deep Hedging | ||
ST Hedging | ||
Leading Order Approximation |
To illustrate the scalability of our ST-Hedging algorithm, we proivde examples with three risky assets in the market.
Here is an example with three risky assets in the market with cross sectional effect, for the quadratic cost case(q=2
). The trading horizon is 2520 days (TR=2520
), discretized in 2520 time steps (T=2520
), and the switching threshold is 100 days before maturity.
The parameters are taken from the calibration in [1]:
And these lead to the optimal position (the first plot) and the optimal trading rates illustrated below, leanrt by the ST-Hedging as well as the ground truth and the Leading-order solution based on the asymptotic formula:
With the simulation of a test batch size of 3000 (N_SAMPLE = 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 | ||
---|---|---|
ST Hedging | ||
Leading Order Approximation | ||
Ground Truth |
Here is an example with three risky assets in the market, for the power cost case (q=3/2
). The trading horizon is 2520 days (TR=2520
), discretized in 2520 time steps (T=2520
), and the switching threshold is 100 days before maturity.
The parameters are taken from the calibration in [1]:
And these lead to the optimal position (the first plot) and the optimal trading rates illustrated below, leanrt by the ST-Hedging as well as the ground truth and the Leading-order solution based on the asymptotic formula:
With the simulation of a test batch size of 3000 (N_SAMPLE = 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 | ||
---|---|---|
ST Hedging | ||
Leading Order Approximation |
See more examples and discussion in Section 4 of paper [2].
[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.