BlackScholes

class pfhedge.nn.BlackScholes(derivative)[source]

Creates Black-Scholes formula module from a derivative.

The forward method returns the Black-Scholes delta.

Parameters

derivative (BaseDerivative) – The derivative to get the Black-Scholes formula.

Shape:
  • input : \((N, *, H_{\mathrm{in}})\) where \(*\) means any number of additional dimensions and \(H_{\mathrm{in}}\) is the number of input features. See inputs() for the names of the input features.

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

Examples

One can instantiate Black-Scholes module by using a derivative. For example, one can instantiate BSEuropeanOption using a pfhedge.instruments.EuropeanOption. The forward method returns delta of the derivative.

>>> import torch
>>> from pfhedge.instruments import BrownianStock
>>> from pfhedge.instruments import EuropeanOption
>>> from pfhedge.nn import BlackScholes
>>>
>>> derivative = EuropeanOption(BrownianStock(), strike=1.1)
>>> m = BlackScholes(derivative)
>>> m
BSEuropeanOption(strike=1.1000)

Instantiating BSLookbackOption using a pfhedge.instruments.LookbackOption.

>>> from pfhedge.instruments import LookbackOption
>>>
>>> derivative = LookbackOption(BrownianStock(), strike=1.03)
>>> m = BlackScholes(derivative)
>>> m
BSLookbackOption(strike=1.0300)