Class Gsr
The one-factor GSR model, formulated in the forward measure of its numeraire time: piecewise constant volatilities on the step dates, and a constant reversion or piecewise constant reversions on the same dates.
public sealed class Gsr : Gaussian1dModel, ITermStructureConsistentModel, ICalibratedModel
- Inheritance
-
Gsr
- Implements
- Inherited Members
- Extension Methods
Remarks
Immutable, a Gaussian1dModel implementing ICalibratedModel over its two arguments, the
reversions and the volatilities, in QuantLib's order (the playbook's calibration row): a calibration returns a new
model. QuantLib's quotes are values (the playbook's quote row), so its four constructors are two. Its memo of the
process's integrals lives for one call, so QuantLib's flushCache and its observers have no counterpart.
WithNumeraireTime(double) returns a copy, its process moved to the new forward measure time with its core, and
refuses a time below the last step time, as QuantLib's master does after the pin (#2842); QuantLib 1.44's moves the
process and leaves its core at the constructor's time. A curve given to the numeraire is read with extrapolation, as
the model's own is, where QuantLib's reads a given one at the numeraire time without it
(Divergences/Gaussian1dNumeraireExtrapolationTests.cs).
Constructors
Gsr(YieldTermStructure, IEnumerable<Date>, IEnumerable<double>, IEnumerable<double>, double)
Initializes a new instance of the Gsr class, with piecewise constant reversions.
public Gsr(YieldTermStructure termStructure, IEnumerable<Date> volstepdates, IEnumerable<double> volatilities, IEnumerable<double> reversions, double T = 60)
Parameters
termStructureYieldTermStructureThe model's curve.
volstepdatesIEnumerable<Date>The step dates of the volatilities and reversions, increasing, after the curve's reference date.
volatilitiesIEnumerable<double>The volatilities: one more than the step dates.
reversionsIEnumerable<double>The reversions: one, constant, or one more than the step dates.
TdoubleThe numeraire time, the process's forward measure time; 60 by default, QuantLib's. It may lie below the last step date, as QuantLib accepts it: a step past it moves nothing, and nothing past it is read.
Exceptions
- ArgumentNullException
An argument is null.
- ArgumentException
A step date isn't after the reference date or after the date before it, or the volatilities or the reversions don't match the step dates.
Gsr(YieldTermStructure, IEnumerable<Date>, IEnumerable<double>, double, double)
Initializes a new instance of the Gsr class, with a constant reversion.
public Gsr(YieldTermStructure termStructure, IEnumerable<Date> volstepdates, IEnumerable<double> volatilities, double reversion, double T = 60)
Parameters
termStructureYieldTermStructureThe model's curve.
volstepdatesIEnumerable<Date>The volatilities' step dates, increasing, after the curve's reference date.
volatilitiesIEnumerable<double>The volatilities: one more than the step dates.
reversiondoubleThe constant reversion.
TdoubleThe numeraire time, the process's forward measure time; 60 by default, QuantLib's. It may lie below the last step date, as QuantLib accepts it: a step past it moves nothing, and nothing past it is read.
Exceptions
- ArgumentNullException
termStructure,volstepdatesorvolatilitiesis null.- ArgumentException
A step date isn't after the reference date or after the date before it, or the volatilities aren't one more than the step dates.
Properties
Arguments
Gets the model's arguments, the parameters calibration works on, in order.
public ImmutableArray<Parameter> Arguments { get; }
Property Value
Constraint
Gets the constraint the model imposes on its parameters: each argument's own, on its slice.
public Constraint Constraint { get; }
Property Value
NumeraireTime
Gets the numeraire time, the state process's forward measure time.
public double NumeraireTime { get; }
Property Value
Reversion
Gets the reversions: QuantLib's reversion(), the reversion argument's parameters.
public ImmutableArray<double> Reversion { get; }
Property Value
Volatility
Gets the volatilities: QuantLib's volatility(), the volatility argument's parameters.
public ImmutableArray<double> Volatility { get; }
Property Value
Methods
CalibrateReversionsIterative(IEnumerable<BlackCalibrationHelper>, OptimizationMethod, EndCriteria, EvaluationContext, Constraint?, ReadOnlySpan<double>)
Calibrates the reversions one by one to the given helpers, the volatilities fixed: QuantLib's
calibrateReversionsIterative, each step calibrating one reversion to its own helper.
public CalibrationResults<Gsr> CalibrateReversionsIterative(IEnumerable<BlackCalibrationHelper> helpers, OptimizationMethod method, EndCriteria endCriteria, EvaluationContext context, Constraint? constraint = null, ReadOnlySpan<double> weights = default)
Parameters
helpersIEnumerable<BlackCalibrationHelper>The helpers, one per reversion to move, in order; the step dates should follow their maturities.
methodOptimizationMethodThe optimization method.
endCriteriaEndCriteriaThe criteria that end each step.
contextEvaluationContextThe evaluation context the helpers price under.
constraintConstraintA constraint added to the model's own; null, QuantLib's empty constraint, by default.
weightsReadOnlySpan<double>One weight per helper, each step weighted by its own helper's; empty, the default, for all 1.
Returns
- CalibrationResults<Gsr>
The last step's record, its model the calibrated one: what QuantLib's model reports after the loop.
Remarks
As CalibrateVolatilitiesIterative(IEnumerable<BlackCalibrationHelper>, OptimizationMethod, EndCriteria, EvaluationContext, Constraint?, ReadOnlySpan<double>)'s, for the weights and an empty set of helpers.
Exceptions
- ArgumentNullException
An argument but the constraint is null.
- ArgumentException
No helper is given, or a null one; the weights aren't one per helper; or a helper has no reversion to move.
- NanoQLException
An optimization or a helper's pricing fails.
CalibrateVolatilitiesIterative(IEnumerable<BlackCalibrationHelper>, OptimizationMethod, EndCriteria, EvaluationContext, Constraint?, ReadOnlySpan<double>)
Calibrates the volatilities one by one to the given helpers, the reversions fixed: QuantLib's
calibrateVolatilitiesIterative, each step calibrating one volatility to its own helper.
public CalibrationResults<Gsr> CalibrateVolatilitiesIterative(IEnumerable<BlackCalibrationHelper> helpers, OptimizationMethod method, EndCriteria endCriteria, EvaluationContext context, Constraint? constraint = null, ReadOnlySpan<double> weights = default)
Parameters
helpersIEnumerable<BlackCalibrationHelper>The helpers, one per volatility to move, in order; the step dates should be their fixing dates but the last.
methodOptimizationMethodThe optimization method.
endCriteriaEndCriteriaThe criteria that end each step.
contextEvaluationContextThe evaluation context the helpers price under.
constraintConstraintA constraint added to the model's own; null, QuantLib's empty constraint, by default.
weightsReadOnlySpan<double>One weight per helper, each step weighted by its own helper's; empty, the default, for all 1.
Returns
- CalibrationResults<Gsr>
The last step's record, its model the calibrated one: what QuantLib's model reports after the loop.
Remarks
QuantLib's passes the whole weight vector to each one-helper step, which its calibration refuses for every
non-empty vector of more than one weight: a documented divergence
(Divergences/GsrIterativeWeightsTests.cs). With no helper, QuantLib's loop does nothing and leaves the
model's last record; here there is no record to return, so it is refused with its calibration's text.
Exceptions
- ArgumentNullException
An argument but the constraint is null.
- ArgumentException
No helper is given, or a null one; the weights aren't one per helper; or a helper has no volatility to move.
- NanoQLException
An optimization or a helper's pricing fails.
FixedReversions()
The calibration flags that fix the reversions, the volatilities free.
public ImmutableArray<bool> FixedReversions()
Returns
- ImmutableArray<bool>
One flag per parameter: the reversions' set, the volatilities' clear.
FixedVolatilities()
The calibration flags that fix the volatilities, the reversions free.
public ImmutableArray<bool> FixedVolatilities()
Returns
- ImmutableArray<bool>
One flag per parameter: the reversions' clear, the volatilities' set.
MoveReversion(int)
The calibration flags that leave only one reversion free.
public ImmutableArray<bool> MoveReversion(int i)
Parameters
iintThe reversion's index.
Returns
- ImmutableArray<bool>
One flag per parameter, every one set but the reversion's.
Exceptions
- ArgumentOutOfRangeException
iis negative.- ArgumentException
No reversion has the index.
MoveVolatility(int)
The calibration flags that leave only one volatility free.
public ImmutableArray<bool> MoveVolatility(int i)
Parameters
iintThe volatility's index.
Returns
- ImmutableArray<bool>
One flag per parameter, every one set but the volatility's.
Exceptions
- ArgumentOutOfRangeException
iis negative.- ArgumentException
No volatility has the index.
NumeraireImpl(double, double, YieldTermStructure?)
The numeraire at a time, for a value of the standardized state: the hook a derived model implements.
protected override double NumeraireImpl(double t, double y, YieldTermStructure? yts)
Parameters
tdoubleThe time.
ydoubleThe standardized state.
ytsYieldTermStructureThe curve to read instead of the model's, or null.
Returns
- double
The numeraire.
Params()
The parameters calibration works on: every argument's parameters, in order.
public Vector Params()
Returns
- Vector
A new vector holding them.
WithNumeraireTime(double)
A copy of the model at another numeraire time: QuantLib's numeraireTime(T).
public Gsr WithNumeraireTime(double T)
Parameters
TdoubleThe numeraire time.
Returns
- Gsr
The copy; the receiver doesn't change.
Exceptions
- ArgumentException
Tis below the last step time.
WithParams(Vector)
A new model, of the receiver's type, with the given parameters: QuantLib's setParams.
public ICalibratedModel WithParams(Vector parameters)
Parameters
Returns
- ICalibratedModel
The new model; the receiver doesn't change.
Remarks
QuantLib's setParams with its generateArguments: the process takes the new volatilities and
reversions, its step times and forward measure time kept. As QuantLib's, the parameters aren't checked against
the arguments' constraints, and the refusals of a wrong size come before any write. The copy's core takes its
zero-reversion flags from the new reversions, the model built at them; QuantLib's recomputes them from the old
ones before it sets the new, so its model keeps the previous parameters' flags
(Divergences/GsrWithParamsTests.cs).
ZerobondImpl(double, double, double, YieldTermStructure?)
The zero bond maturing at a time, at another time, for a value of the standardized state: the hook a derived model implements.
protected override double ZerobondImpl(double T, double t, double y, YieldTermStructure? yts)
Parameters
TdoubleThe maturity.
tdoubleThe time.
ydoubleThe standardized state at
t.ytsYieldTermStructureThe curve to read instead of the model's, or null.
Returns
- double
The zero bond.