pfhedge.nn.functional.pl¶
- pfhedge.nn.functional.pl(spot, unit, cost=None, payoff=None, deduct_first_cost=True, deduct_final_cost=False)[source]¶
Returns the final profit and loss of hedging.
For hedging instruments indexed by \(h = 1, \dots, H\) and time steps \(i = 1, \dots, T\), the final profit and loss is given by
\[\text{PL}(Z, \delta, S) = - Z + \sum_{h = 1}^{H} \sum_{t = 1}^{T} \left[ \delta^{(h)}_{t - 1} (S^{(h)}_{t} - S^{(h)}_{t - 1}) - c^{(h)} |\delta^{(h)}_{t} - \delta^{(h)}_{t - 1}| S^{(h)}_{t} \right] ,\]where \(Z\) is the payoff of the derivative. For each hedging instrument, \(\{S^{(h)}_t ; t = 1, \dots, T\}\) is the spot price, \(\{\delta^{(h)}_t ; t = 1, \dots, T\}\) is the number of shares held at each time step. We define \(\delta^{(h)}_0 = 0\) for notational convenience.
A hedger sells the derivative to its customer and obliges to settle the payoff at maturity. The dealer hedges the risk of this liability by trading the underlying instrument of the derivative. The resulting profit and loss is obtained by adding up the payoff to the customer, capital gains from the underlying asset, and the transaction cost.
References
Buehler, H., Gonon, L., Teichmann, J. and Wood, B., 2019. Deep hedging. Quantitative Finance, 19(8), pp.1271-1291. [arXiv:1802.03042 [q-fin]]
- Parameters
spot (torch.Tensor) – The spot price of the underlying asset \(S\).
unit (torch.Tensor) – The signed number of shares of the underlying asset \(\delta\).
cost (list[float], default=None) – The proportional transaction cost rate of the underlying assets.
payoff (torch.Tensor, optional) – The payoff of the derivative \(Z\).
deduct_first_cost (bool, default=True) – Whether to deduct the transaction cost of the stock at the first time step. If
False
, \(- c |\delta_0| S_1\) is omitted the above equation of the terminal value.
- Shape:
spot: \((N, H, T)\) where \(N\) is the number of paths, \(H\) is the number of hedging instruments, and \(T\) is the number of time steps.
unit: \((N, H, T)\)
payoff: \((N)\)
output: \((N)\).
- Returns
torch.Tensor