Class Garch11
The GARCH(1,1) volatility model: σ²ₜ = ω + α u²ₜ₋₁ + β σ²ₜ₋₁, ω = γ V_L with γ = 1 − α − β and V_L the long-term variance. Volatilities are assumed to be expressed on an annual basis.
public sealed class Garch11 : VolatilityCompositor
- Inheritance
-
Garch11
- Inherited Members
Remarks
Immutable: a model built from a series is calibrated at construction, and each Calibrate returns a new model
with the receiver's mode, where QuantLib's change the object. The statics are QuantLib's:
Calculate(TimeSeries<double>, double, double, double), ToR2(ReadOnlySpan<double>), CostFunction(ReadOnlySpan<double>, double, double, double)
and CalibrateR2's six overloads, each returning the parameters and the minimization's results that QuantLib
writes through its references and returns.
Documented divergences:
- A calibration whose minimizer doesn't converge is refused, "GARCH(1,1) calibration did not
converge: optimizer stopped with end criterion …", which the mode-based calibrations catch and fall back to their
initial guess: QuantLib's master (#2844), which 1.44 doesn't check
(
Divergences/GarchConvergenceTests.cs). - The cost's gradient is the gradient of its value, the recursive ∂σ²ₜ/∂θ = (1, u²ₜ₋₁, σ²ₜ₋₁) + β
∂σ²ₜ₋₁/∂θ, where QuantLib's takes the direct term alone, 0.13 to 0.80 times the true gradient; QuantLib's own paths,
the Simplex and the ACF fit, never read it (
Divergences/GarchGradientTests.cs). - The cost refuses a conditional variance that isn't positive, which only the overloads that
subtract the mean from the squared returns can produce, where QuantLib takes its log, NaN
(
Divergences/GarchDemeanedVarianceTests.cs). - A series of fewer than two points is refused by Calculate(TimeSeries<double>, double, double, double), where QuantLib reads before its start.
- The mode-based initial guesses fit the autocorrelations by NonLinearLeastSquare on
the conjugate gradient, whose returned point is the last one its line search accepted
(
Divergences/LineSearchReturnTests.cs), so the Simplex starts a hair from QuantLib's guess and the calibrated parameters end within its tolerance, 1e-8, of QuantLib's, the log-likelihood the same. - The second initial guess (the ACF fit's, which GammaGuess and
BestOfTwo take) sets α = γ − β, as the first does, where the fit fails or its guess misses
the constraint; QuantLib leaves α there as its caller's, an uninitialized element of its guess array
(
garch.cpp:318-368,:435-439), so its value is undefined.
Constructors
Garch11(TimeSeries<double>, Garch11Mode)
Initializes a new instance of the Garch11 class calibrated to a series.
public Garch11(TimeSeries<double> qs, Garch11Mode mode = Garch11Mode.BestOfTwo)
Parameters
qsTimeSeries<double>The series of returns.
modeGarch11ModeThe initial guess.
Exceptions
- ArgumentNullException
qsis null.- ArgumentOutOfRangeException
modeisn't a Garch11Mode member.- NanoQLException
The series is too short or constant.
Garch11(double, double, double)
Initializes a new instance of the Garch11 class from its parameters.
public Garch11(double a, double b, double vl)
Parameters
Properties
Alpha
Gets α.
public double Alpha { get; }
Property Value
Beta
Gets β.
public double Beta { get; }
Property Value
LogLikelihood
Gets the log-likelihood of the calibration, 0 for a model built from its parameters.
public double LogLikelihood { get; }
Property Value
LtVol
Gets the long-term variance V_L.
public double LtVol { get; }
Property Value
Mode
Gets the initial guess the model's calibrations take.
public Garch11Mode Mode { get; }
Property Value
Omega
Gets ω = γ V_L.
public double Omega { get; }
Property Value
Methods
Calculate(TimeSeries<double>)
The volatilities the model gives on the series.
public override TimeSeries<double> Calculate(TimeSeries<double> volatilitySeries)
Parameters
volatilitySeriesTimeSeries<double>The series.
Returns
- TimeSeries<double>
The volatility series.
Exceptions
- ArgumentNullException
volatilitySeriesis null.- ArgumentException
The series has fewer than two points.
Calculate(TimeSeries<double>, double, double, double)
The model's volatilities on a series of returns: at each date after the first, the square root of the variance the returns before it give, and one more at the last date plus its spacing.
public static TimeSeries<double> Calculate(TimeSeries<double> quoteSeries, double alpha, double beta, double omega)
Parameters
quoteSeriesTimeSeries<double>The series of returns.
alphadoubleα.
betadoubleβ.
omegadoubleω.
Returns
- TimeSeries<double>
The volatility series.
Exceptions
- ArgumentNullException
quoteSeriesis null.- ArgumentException
The series has fewer than two points.
Calibrate(TimeSeries<double>)
The model calibrated to the series.
public override Garch11 Calibrate(TimeSeries<double> volatilitySeries)
Parameters
volatilitySeriesTimeSeries<double>The series.
Returns
- Garch11
A new model, or this one where calibration changes nothing.
Exceptions
- ArgumentNullException
volatilitySeriesis null.- NanoQLException
The series is too short or constant.
Calibrate(TimeSeries<double>, OptimizationMethod, EndCriteria)
The model calibrated by its mode's initial guess and an optimization method.
public Garch11 Calibrate(TimeSeries<double> quoteSeries, OptimizationMethod method, EndCriteria endCriteria)
Parameters
quoteSeriesTimeSeries<double>The series of returns.
methodOptimizationMethodThe optimization method.
endCriteriaEndCriteriaIts end criteria.
Returns
- Garch11
A new model, with this one's mode.
Exceptions
- ArgumentNullException
An argument is null.
- NanoQLException
The series is too short or constant.
Calibrate(TimeSeries<double>, OptimizationMethod, EndCriteria, ReadOnlySpan<double>)
The model calibrated from an initial guess by an optimization method.
public Garch11 Calibrate(TimeSeries<double> quoteSeries, OptimizationMethod method, EndCriteria endCriteria, ReadOnlySpan<double> initialGuess)
Parameters
quoteSeriesTimeSeries<double>The series of returns.
methodOptimizationMethodThe optimization method.
endCriteriaEndCriteriaIts end criteria.
initialGuessReadOnlySpan<double>The initial ω, α and β.
Returns
- Garch11
A new model, with this one's mode.
Exceptions
- ArgumentNullException
An argument is null.
- NanoQLException
The minimizer doesn't converge.
- ArgumentException
initialGuessholds fewer than three values, where QuantLib reads past its end.
CalibrateR2(Garch11Mode, ReadOnlySpan<double>, double)
Calibrates GARCH for r² by a mode's initial guess and QuantLib's Simplex.
public static Garch11Calibration CalibrateR2(Garch11Mode mode, ReadOnlySpan<double> r2, double meanR2)
Parameters
modeGarch11ModeThe initial guess.
r2ReadOnlySpan<double>The squared returns.
meanR2doubleTheir mean.
Returns
- Garch11Calibration
The parameters and the minimization's results, null where it fell back to its guess.
Exceptions
- ArgumentOutOfRangeException
modeisn't a Garch11Mode member.- NanoQLException
The series is too short or constant.
CalibrateR2(Garch11Mode, ReadOnlySpan<double>, double, OptimizationMethod, EndCriteria)
Calibrates GARCH for r² by a mode's initial guess and an optimization method.
public static Garch11Calibration CalibrateR2(Garch11Mode mode, ReadOnlySpan<double> r2, double meanR2, OptimizationMethod method, EndCriteria endCriteria)
Parameters
modeGarch11ModeThe initial guess.
r2ReadOnlySpan<double>The squared returns.
meanR2doubleTheir mean.
methodOptimizationMethodThe optimization method.
endCriteriaEndCriteriaIts end criteria.
Returns
- Garch11Calibration
The parameters and the minimization's results, null where it fell back to its guess.
Exceptions
- ArgumentNullException
methodorendCriteriais null.- ArgumentOutOfRangeException
modeisn't a Garch11Mode member.- NanoQLException
The series is too short or constant.
CalibrateR2(ReadOnlySpan<double>, OptimizationMethod, Constraint, EndCriteria, ReadOnlySpan<double>)
Calibrates GARCH for r² from an initial guess, by an optimization method under a constraint.
public static Garch11Calibration CalibrateR2(ReadOnlySpan<double> r2, OptimizationMethod method, Constraint constraints, EndCriteria endCriteria, ReadOnlySpan<double> initialGuess)
Parameters
r2ReadOnlySpan<double>The squared returns.
methodOptimizationMethodThe optimization method.
constraintsConstraintThe constraint.
endCriteriaEndCriteriaIts end criteria.
initialGuessReadOnlySpan<double>The initial ω, α and β.
Returns
- Garch11Calibration
The parameters and the minimization's results.
Exceptions
- ArgumentNullException
An argument is null.
- NanoQLException
The minimizer doesn't converge (#2844).
- ArgumentException
initialGuessholds fewer than three values, where QuantLib reads past its end.
CalibrateR2(ReadOnlySpan<double>, OptimizationMethod, EndCriteria, ReadOnlySpan<double>)
Calibrates GARCH for r² from an initial guess, by an optimization method under the constraint ω > 0, α, β ≥ 0, α + β < 1 − 1e-8.
public static Garch11Calibration CalibrateR2(ReadOnlySpan<double> r2, OptimizationMethod method, EndCriteria endCriteria, ReadOnlySpan<double> initialGuess)
Parameters
r2ReadOnlySpan<double>The squared returns.
methodOptimizationMethodThe optimization method.
endCriteriaEndCriteriaIts end criteria.
initialGuessReadOnlySpan<double>The initial ω, α and β.
Returns
- Garch11Calibration
The parameters and the minimization's results.
Exceptions
- ArgumentNullException
methodorendCriteriais null.- NanoQLException
The minimizer doesn't converge.
- ArgumentException
initialGuessholds fewer than three values, where QuantLib reads past its end.
CalibrateR2(ReadOnlySpan<double>, double, OptimizationMethod, Constraint, EndCriteria, ReadOnlySpan<double>)
Calibrates GARCH for r² less its mean from an initial guess, by an optimization method under a constraint.
public static Garch11Calibration CalibrateR2(ReadOnlySpan<double> r2, double meanR2, OptimizationMethod method, Constraint constraints, EndCriteria endCriteria, ReadOnlySpan<double> initialGuess)
Parameters
r2ReadOnlySpan<double>The squared returns.
meanR2doubleTheir mean, subtracted from each.
methodOptimizationMethodThe optimization method.
constraintsConstraintThe constraint.
endCriteriaEndCriteriaIts end criteria.
initialGuessReadOnlySpan<double>The initial ω, α and β.
Returns
- Garch11Calibration
The parameters and the minimization's results.
Exceptions
- ArgumentNullException
An argument is null.
- NanoQLException
The minimizer doesn't converge, or the cost reaches a conditional variance that isn't positive.
- ArgumentException
initialGuessholds fewer than three values, where QuantLib reads past its end.
CalibrateR2(ReadOnlySpan<double>, double, OptimizationMethod, EndCriteria, ReadOnlySpan<double>)
Calibrates GARCH for r² less its mean from an initial guess, by an optimization method under the constraint ω > 0, α, β ≥ 0, α + β < 1 − 1e-8.
public static Garch11Calibration CalibrateR2(ReadOnlySpan<double> r2, double meanR2, OptimizationMethod method, EndCriteria endCriteria, ReadOnlySpan<double> initialGuess)
Parameters
r2ReadOnlySpan<double>The squared returns.
meanR2doubleTheir mean, subtracted from each.
methodOptimizationMethodThe optimization method.
endCriteriaEndCriteriaIts end criteria.
initialGuessReadOnlySpan<double>The initial ω, α and β.
Returns
- Garch11Calibration
The parameters and the minimization's results.
Exceptions
- ArgumentNullException
methodorendCriteriais null.- NanoQLException
The minimizer doesn't converge, or the cost reaches a conditional variance that isn't positive.
- ArgumentException
initialGuessholds fewer than three values, where QuantLib reads past its end.
CostFunction(ReadOnlySpan<double>, double, double, double)
The model's cost on a series of returns: Σ(ln σ²ₜ + u²ₜ/σ²ₜ)/(2N), 0 on an empty series.
public static double CostFunction(ReadOnlySpan<double> values, double alpha, double beta, double omega)
Parameters
valuesReadOnlySpan<double>The returns.
alphadoubleα.
betadoubleβ.
omegadoubleω.
Returns
- double
The cost, the negated log-likelihood.
Forecast(double, double)
The variance forecast after a return r at a variance σ², γ V_L + α r² + β σ².
public double Forecast(double r, double sigma2)
Parameters
Returns
- double
The next variance.
ToR2(ReadOnlySpan<double>)
The squared returns and their mean, QuantLib's to_r2.
public static (ImmutableArray<double> R2, double MeanR2) ToR2(ReadOnlySpan<double> values)
Parameters
valuesReadOnlySpan<double>The returns.
Returns
- (ImmutableArray<double> R2, double MeanR2)
The squared returns, and their running mean.