BSLookbackOption

class pfhedge.nn.BSLookbackOption(call=True, strike=1.0, derivative=None)[source]

Black-Scholes formula for a lookback option with a fixed strike.

Note

  • The formulas are for continuous monitoring while pfhedge.instruments.LookbackOption monitors spot prices discretely. To get adjustment for discrete monitoring, see, for instance, Broadie, Glasserman, and Kou (1999).

See also

References

  • Conze, A., 1991. Path dependent options: The case of lookback options. The Journal of Finance, 46(5), pp.1893-1907.

  • Broadie, M., Glasserman, P. and Kou, S.G., 1999. Connecting discrete and continuous path-dependent options. Finance and Stochastics, 3(1), pp.55-82.

Parameters
  • call (bool, default=True) – Specifies whether the option is call or put.

  • strike (float, default=1.0) – The strike price of the option.

Shape:
  • Input: \((N, *, 4)\) where \(*\) means any number of additional dimensions. See inputs() for the names of input features.

  • Output: \((N, *, 1)\). All but the last dimension are the same shape as the input.

Examples

>>> from pfhedge.nn import BSLookbackOption
>>>
>>> m = BSLookbackOption()
>>> m.inputs()
['log_moneyness', 'max_log_moneyness', 'time_to_maturity', 'volatility']
>>> input = torch.tensor([
...     [-0.01, -0.01, 0.1, 0.2],
...     [ 0.00,  0.00, 0.1, 0.2],
...     [ 0.01,  0.01, 0.1, 0.2]])
>>> m(input)
tensor([[0.9208],
        [1.0515],
        [1.0515]])
delta(log_moneyness=None, max_log_moneyness=None, time_to_maturity=None, volatility=None, create_graph=False)[source]

Returns delta of the derivative.

Parameters
  • log_moneyness (torch.Tensor, optional) – Log moneyness of the underlying asset.

  • max_log_moneyness (torch.Tensor, optional) – Cumulative maximum of the log moneyness.

  • time_to_maturity (torch.Tensor, optional) – Time to expiry of the option.

  • volatility (torch.Tensor, optional) – Volatility of the underlying asset.

  • create_graph (bool, default=False) – If True, graph of the derivative will be constructed. This option is used to compute gamma.

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

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

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

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

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

Returns

torch.Tensor

Note

Parameters are not optional if the module has not accepted a derivative in its initialization.

forward(input)

Returns delta of the derivative.

Parameters

input (torch.Tensor) – The input tensor. Features are concatenated along the last dimension. See inputs() for the names of the input features.

Returns

torch.Tensor

classmethod from_derivative(derivative)[source]

Initialize a module from a derivative.

Parameters

derivative (pfhedge.instruments.LookbackOption) – The derivative to get the Black-Scholes formula.

Returns

BSLookbackOption

Examples

>>> from pfhedge.instruments import BrownianStock
>>> from pfhedge.instruments import LookbackOption
>>>
>>> derivative = LookbackOption(BrownianStock(), strike=1.1)
>>> m = BSLookbackOption.from_derivative(derivative)
>>> m
BSLookbackOption(strike=1.1000)
gamma(log_moneyness=None, max_log_moneyness=None, time_to_maturity=None, volatility=None)[source]

Returns gamma of the derivative.

Parameters
  • log_moneyness (torch.Tensor, optional) – Log moneyness of the underlying asset.

  • max_log_moneyness (torch.Tensor, optional) – Cumulative maximum of the log moneyness.

  • time_to_maturity (torch.Tensor, optional) – Time to expiry of the option.

  • volatility (torch.Tensor, optional) – Volatility of the underlying asset.

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

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

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

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

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

Returns

torch.Tensor

Note

Arguments are not optional if it doesn’t accept derivative in this initialization.

implied_volatility(log_moneyness=None, max_log_moneyness=None, time_to_maturity=None, price=None, precision=1e-06)[source]

Returns implied volatility of the derivative.

Parameters
  • log_moneyness (torch.Tensor, optional) – Log moneyness of the underlying asset.

  • max_log_moneyness (torch.Tensor, optional) – Cumulative maximum of the log moneyness.

  • time_to_maturity (torch.Tensor, optional) – Time to expiry of the option.

  • price (torch.Tensor) – Price of the derivative.

  • precision (float, default=1e-6) – Precision of the implied volatility.

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

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

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

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

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

Returns

torch.Tensor

Note

  • Arguments are not optional if it doesn’t accept derivative in this initialization.

inputs()[source]

Returns the names of input features.

Returns

list

price(log_moneyness=None, max_log_moneyness=None, time_to_maturity=None, volatility=None)[source]

Returns price of the derivative.

The price is given by:

\[\begin{split}\begin{cases} S(0) \{ N(d_1) + \sigma \sqrt{T} [N'(d_1) + d_1 N(d_1)] \} - K N(d_2) & (M \leq K) \\ S(0) \{ N(d_1') + \sigma \sqrt{T} [N'(d_1') + d_1' N(d_1')] \} - K + M [1 - N(d_2')] & (M > K) \\ \end{cases}\end{split}\]

where \(M = \max_{t < 0} S(t)\), \(d_1' = [\log(S(0) / M) + \frac12 \sigma^2 T] / \sigma \sqrt{T}\), and \(d_2' = [\log(S(0) / M) - \frac12 \sigma^2 T] / \sigma \sqrt{T}\).

Parameters
  • log_moneyness (torch.Tensor, optional) – Log moneyness of the underlying asset.

  • max_log_moneyness (torch.Tensor, optional) – Cumulative maximum of the log moneyness.

  • time_to_maturity (torch.Tensor, optional) – Time to expiry of the option.

  • volatility (torch.Tensor, optional) – Volatility of the underlying asset.

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

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

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

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

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

Returns

torch.Tensor

Note

Parameters are not optional if the module has not accepted a derivative in its initialization.

theta(log_moneyness=None, max_log_moneyness=None, time_to_maturity=None, volatility=None)[source]

Returns theta of the derivative.

Parameters
  • log_moneyness (torch.Tensor, optional) – Log moneyness of the underlying asset.

  • max_log_moneyness (torch.Tensor, optional) – Cumulative maximum of the log moneyness.

  • time_to_maturity (torch.Tensor, optional) – Time to expiry of the option.

  • volatility (torch.Tensor, optional) – Volatility of the underlying asset.

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

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

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

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

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

Returns

torch.Tensor

Note

  • Risk-free rate is set to zero.

  • Arguments are not optional if it doesn’t accept derivative in this initialization.

vega(log_moneyness=None, max_log_moneyness=None, time_to_maturity=None, volatility=None)[source]

Returns vega of the derivative.

Parameters
  • log_moneyness (torch.Tensor, optional) – Log moneyness of the underlying asset.

  • max_log_moneyness (torch.Tensor, optional) – Cumulative maximum of the log moneyness.

  • time_to_maturity (torch.Tensor, optional) – Time to expiry of the option.

  • volatility (torch.Tensor, optional) – Volatility of the underlying asset.

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

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

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

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

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

Returns

torch.Tensor

Note

  • Arguments are not optional if it doesn’t accept derivative in this initialization.