BSAmericanBinaryOption

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

Black-Scholes formula for an American binary option.

Note

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

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.

See also

References

  • Shreve, S.E., 2004. Stochastic calculus for finance II: Continuous-time models (Vol. 11). Springer Science & Business Media.

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

Examples

>>> from pfhedge.nn import BSAmericanBinaryOption
>>>
>>> m = BSAmericanBinaryOption(strike=1.0)
>>> 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([[...],
        [...],
        [...]])
delta(log_moneyness=None, max_log_moneyness=None, time_to_maturity=None, volatility=None)[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.

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.AmericanBinaryOption) – The derivative to get the Black-Scholes formula.

Returns

BSAmericanBinaryOption

Examples

>>> from pfhedge.instruments import BrownianStock
>>> from pfhedge.instruments import AmericanBinaryOption
>>>
>>> derivative = AmericanBinaryOption(BrownianStock(), strike=1.1)
>>> m = BSAmericanBinaryOption.from_derivative(derivative)
>>> m
BSAmericanBinaryOption(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

args 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.

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

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

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

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

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

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

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

Returns

torch.Tensor

Note

args are not optional if it doesn’t accept derivative in this initialization. price seems optional in typing, but it isn’t. It is set for the compatibility to the previous versions.

inputs()

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.

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, *)\)

Note

Risk-free rate is set to zero.

Returns

torch.Tensor

Note

args 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

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