MertonJumpStock

class pfhedge.instruments.MertonJumpStock(mu=0.0, sigma=0.2, jump_per_year=68, jump_mean=0.0, jump_std=0.01, cost=0.0, dt=0.004, dtype=None, device=None, engine=<built-in method randn of type object>)[source]

A stock of which spot price and variance follow Merton Jump Diffusion process.

See also

Parameters
  • mu (float, default=0.0) – The drift parameter \(\mu\).

  • sigma (float, default=0.2) – The volatility parameter \(\sigma\).

  • jump_per_year (float, default=1.0) – The average number of jumps per year.

  • jump_mean (float, default=0.0) – The mean of jumnp sizes.

  • jump_std (float, default=0.3) – The standard deviation of jump sizes.

  • cost (float, default=0.0) – The transaction cost rate.

  • dt (float, default=1/250) – The time step interval.

  • dtype (torch.device, optional) – Desired device of returned tensor. Default: If None, uses a global default (see torch.set_default_tensor_type()).

  • device (torch.device, optional) – Desired device of returned tensor. Default: if None, uses the current device for the default tensor type (see torch.set_default_tensor_type()). device will be the CPU for CPU tensor types and the current CUDA device for CUDA tensor types.

  • engine (callable, default=torch.randn) – The desired generator of random numbers from a standard normal distribution. A function call engine(size, dtype=None, device=None) should return a tensor filled with random numbers from a standard normal distribution.

Buffers:
  • spot (torch.Tensor): The spot price of the instrument. This attribute is set by the method simulate(). The shape is \((N, T)\) where \(N\) is the number of simulated paths and \(T\) is the number of time steps.

  • variance (torch.Tensor): The variance of the instrument. Note that this is different from the realized variance of the spot price. This attribute is set by the method simulate(). The shape is \((N, T)\).

Examples

>>> from pfhedge.instruments import MertonJumpStock
>>>
>>> _ = torch.manual_seed(42)
>>> stock = MertonJumpStock()
>>> stock.simulate(n_paths=2, time_horizon=5/250)
>>> stock.spot
tensor([[1.0000, 1.0100, 1.0135, 1.0141, 1.0208, 1.0176],
        [1.0000, 1.0066, 0.9955, 1.0047, 1.0063, 1.0172]])
>>> stock.variance
tensor([[0.0400, 0.0400, 0.0400, 0.0400, 0.0400, 0.0400],
        [0.0400, 0.0400, 0.0400, 0.0400, 0.0400, 0.0400]])
>>> stock.volatility
tensor([[0.2000, 0.2000, 0.2000, 0.2000, 0.2000, 0.2000],
        [0.2000, 0.2000, 0.2000, 0.2000, 0.2000, 0.2000]])
property default_init_state

Returns the default initial state of simulation.

simulate(n_paths=1, time_horizon=0.08, init_state=None)[source]

Simulate the spot price and add it as a buffer named spot.

The shape of the spot is \((N, T)\), where \(N\) is the number of simulated paths and \(T\) is the number of time steps. The number of time steps is determinded from dt and time_horizon.

Parameters
  • n_paths (int, default=1) – The number of paths to simulate.

  • time_horizon (float, default=20/250) – The period of time to simulate the price.

  • init_state (tuple[torch.Tensor | float], optional) – The initial state of the instrument. This is specified by a tuple \((S(0), V(0))\) where \(S(0)\) and \(V(0)\) are the initial values of spot and variance, respectively. If None (default), it uses the default value (See default_init_state).

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

property variance

Returns the volatility of self.

It is a tensor filled with the square of self.sigma.

property volatility

Returns the volatility of self.

It is a tensor filled with self.sigma.