VasicekRate¶
- class pfhedge.instruments.VasicekRate(kappa=1.0, theta=0.04, sigma=0.04, cost=0.0, dt=0.004, dtype=None, device=None)[source]¶
A rate which follow the Vasicek model.
See also
pfhedge.stochastic.generate_vasicek()
: The stochastic process.
- Parameters
kappa (float, default=1.0) – The parameter \(\kappa\).
theta (float, default=0.04) – The parameter \(\theta\).
sigma (float, default=0.04) – The parameter \(\sigma\).
cost (float, default=0.0) – The transaction cost rate.
dt (float, default=1/250) – The intervals of the time steps.
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.
- Buffers:
spot (
torch.Tensor
): The spot rate of the instrument. This attribute is set by a methodsimulate()
. The shape is \((N, T)\) where \(N\) is the number of simulated paths and \(T\) is the number of time steps.
Examples
>>> from pfhedge.instruments import VasicekRate ... >>> _ = torch.manual_seed(42) >>> rate = VasicekRate() >>> rate.simulate(n_paths=2, time_horizon=5/250) >>> rate.spot tensor([[0.0400, 0.0409, 0.0412, 0.0418, 0.0423, 0.0395], [0.0400, 0.0456, 0.0439, 0.0451, 0.0457, 0.0471]])
- property default_init_state¶
Returns the default initial state of simulation.
- 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