Barrier

class pfhedge.features.Barrier(threshold, up=True)[source]

A feature which signifies whether the price of the underlier have reached the barrier. The output 1.0 means that the price have touched the barrier, and 0.0 otherwise.

Parameters
  • threshold (float) – The price level of the barrier.

  • up (bool, default True) – If True, signifies whether the price has exceeded the barrier upward. If False, signifies whether the price has exceeded the barrier downward.

Examples

>>> from pfhedge.features import Barrier
>>> from pfhedge.instruments import BrownianStock
>>> from pfhedge.instruments import EuropeanOption
...
>>> _ = torch.manual_seed(42)
>>> derivative = EuropeanOption(BrownianStock(), maturity=5/250, strike=2.0)
>>> derivative.simulate()
>>> derivative.underlier.spot
tensor([[1.0000, 1.0016, 1.0044, 1.0073, 0.9930, 0.9906]])
>>> f = Barrier(threshold=1.004, up=True).of(derivative)
>>> f.get()
tensor([[[0.],
         [0.],
         [1.],
         [1.],
         [1.],
         [1.]]])