AmericanBinaryOption

class pfhedge.instruments.AmericanBinaryOption(underlier, call=True, strike=1.0, maturity=0.08, dtype=None, device=None)[source]

American binary option.

The payoff of an American binary call option is given by:

\[\begin{split}\mathrm{payoff} = \begin{cases} 1 & (\mathrm{Max} \geq K) \\ 0 & (\text{otherwise}) \end{cases} ,\end{split}\]

where \(\mathrm{Max}\) is the maximum of the underlier’s spot price until maturity and \(K\) is the strike.

The payoff of an American binary put option is given by:

\[\begin{split}\mathrm{payoff} = \begin{cases} 1 & (\mathrm{Min} \leq K) \\ 0 & (\text{otherwise}) \end{cases} ,\end{split}\]

where \(\mathrm{Min}\) is the minimum of the underlier’s spot price until maturity.

Parameters
  • underlier (BasePrimary) – The underlying instrument of the option.

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

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

  • maturity (float, default=20/250) – The maturity of the option.

dtype

The dtype with which the simulated time-series are represented.

Type

torch.dtype

device

The device where the simulated time-series are.

Type

torch.device

Examples

>>> import torch
>>> from pfhedge.instruments import BrownianStock
>>> from pfhedge.instruments import AmericanBinaryOption
>>>
>>> _ = torch.manual_seed(42)
>>> derivative = AmericanBinaryOption(
...     BrownianStock(), maturity=5/250, strike=1.01)
>>> derivative.simulate(n_paths=2)
>>> derivative.underlier.spot
tensor([[1.0000, 1.0016, 1.0044, 1.0073, 0.9930, 0.9906],
        [1.0000, 0.9919, 0.9976, 1.0009, 1.0076, 1.0179]])
>>> derivative.payoff()
tensor([0., 1.])
list(pricer, cost=0.0)

Make self a listed derivative.

After this method self will be a exchange-traded derivative which can be transacted at any time with the spot price given by self.spot.

See an example in EuropeanOption for a usage.

Parameters
  • pricer (Callable[[BaseDerivative], Tensor]]) – A function that takes self and returns the spot price tensor of self.

  • cost (float, optional) – The transaction cost rate.

log_moneyness(time_step=None)

Returns log-moneyness of self.

Log-moneyness reads \(\log(S / K)\) where \(S\) is the spot price of the underlying instrument and \(K\) is the strike of the derivative.

Returns

torch.Tensor

moneyness(time_step=None, log=False)

Returns the moneyness of self.

Moneyness reads \(S / K\) where \(S\) is the spot price of the underlying instrument and \(K\) is the strike of the derivative.

Parameters
  • time_step (int, optional) – The time step to calculate the moneyness. If None (default), the moneyness is calculated at all time steps.

  • log (bool, default=False) – If True, returns log moneyness.

Shape:
  • Output: \((N, T)\) where \(N\) is the number of paths and \(T\) is the number of time steps. If time_step is given, the shape is \((N, 1)\).

Returns

torch.Tensor

simulate(n_paths=1, init_state=None)

Simulate time series associated with the underlier.

Parameters
  • n_paths (int) – The number of paths to simulate.

  • init_state (tuple[torch.Tensor | float], optional) – The initial state of the underlier.

  • **kwargs – Other parameters passed to self.underlier.simulate().

time_to_maturity(time_step=None)

Returns the time to maturity of self.

Parameters

time_step (int, optional) – The time step to calculate the time to maturity. If None (default), the time to maturity is calculated at all time steps.

Shape:
  • Output: \((N, T)\) where \(N\) is the number of paths and \(T\) is the number of time steps. If time_step is given, the shape is \((N, 1)\).

Returns

torch.Tensor

to(*args, **kwargs)

Moves and/or casts the buffers of the instrument.

This can be called as

to(device=None, dtype=None)
to(tensor)
to(instrument)

Its signature is similar to torch.nn.Module.to(). It only accepts floating point dtypes. See Instrument dtype and device for details.

Note

This method modifies the instrument in-place.

See also

  • float(): Cast to torch.float32.

  • double(): Cast to torch.float64.

  • half(): Cast to torch.float16.

  • bfloat16(): Cast to torch.bfloat16.

  • cuda(): Move to CUDA memory.

  • cpu(): Move to CPU memory.

Parameters
  • dtype (torch.dtype) – The desired floating point dtype of the buffers in this instrument.

  • device (torch.device) – The desired device of the buffers in this instrument.

  • tensor (torch.Tensor) – Tensor whose dtype and device are the desired dtype and device of the buffers in this instrument.

  • instrument (BaseInstrument) – Instrument whose dtype and device are the desired dtype and device of the buffers in this instrument.

Returns

self

ul(index=0)

Alias for self.underlier.