HedgeLoss

class pfhedge.nn.HedgeLoss(*args, **kwargs)[source]

Base class for hedging criteria.

cash(input, target=0.0)[source]

Returns the cash amount which is as preferable as the given profit-loss distribution in terms of the loss.

The output cash is expected to satisfy the following relation:

loss(torch.full_like(pl, cash)) = loss(pl)

By default, the output is computed by binary search. If analytic form is known, it is recommended to override this method for faster computation.

Parameters
  • input (torch.Tensor) – The distribution of the profit and loss.

  • target (torch.Tensor or float, default=0) – The target portfolio to replicate. Typically, target is the payoff of a derivative.

Shape:
  • input: \((N, *)\) where \(*\) means any number of additional dimensions.

  • target: \((N, *)\)

  • output: \((*)\)

Returns

torch.Tensor

forward(input, target=0.0)[source]

Returns the loss of the profit-loss distribution.

This method should be overridden.

Parameters
  • input (torch.Tensor) – The distribution of the profit and loss.

  • target (torch.Tensor or float, default=0) – The target portfolio to replicate. Typically, target is the payoff of a derivative.

Shape:
  • input: \((N, *)\) where \(*\) means any number of additional dimensions.

  • target: \((N, *)\)

  • output: \((*)\)

Returns

torch.Tensor