VarianceSwap¶
- class pfhedge.instruments.VarianceSwap(underlier, strike=0.04, maturity=0.08, dtype=None, device=None)[source]¶
Variance swap.
The payoff of a variance swap is given by
\[\mathrm{payoff} = \sigma^2 - K ,\]where \(\sigma^2\) is the realized variance of the underlying asset until maturity and \(K\) is the strike.
See
pfhedge.nn.functional.realized_variance()
for the definition of the realized variance.- Parameters
underlier (
BasePrimary
) – The underlying instrument.strike (float, default=0.04) – The strike variance of the swap.
maturity (float, default=20/250) – The maturity of the derivative.
- dtype¶
The dtype with which the simulated time-series are represented.
- Type
- device¶
The device where the simulated time-series are.
- Type
Examples
>>> import torch >>> from pfhedge.nn.functional import realized_variance >>> from pfhedge.instruments import BrownianStock >>> from pfhedge.instruments import VarianceSwap >>> >>> _ = torch.manual_seed(42) >>> derivative = VarianceSwap(BrownianStock(), strike=0.04, maturity=5/250) >>> 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]]) >>> realized_variance(derivative.ul().spot, dt=derivative.ul().dt) tensor([0.0114, 0.0129]) >>> derivative.payoff() tensor([-0.0286, -0.0271])
- 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.
- 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()
.
- 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 totorch.float32
.double()
: Cast totorch.float64
.half()
: Cast totorch.float16
.bfloat16()
: Cast totorch.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
.