CovarianceMatrix: Array;
CovarianceMatrix: System.Array;
The CovarianceMatrix property returns covariance matrix values.
It is required to use an array of Double values.
To execute the example, add a link to the Stat system assembly.
Sub UserProc;
Var
GARCH: ISmGARCH;
x: Array[10] Of Double;
y1, y2: Array[15] Of Double;
Res, i, j: Integer;
str: String;
Begin
GARCH := New SmGARCH.Create;
// Set values fornbsp;variables
x[0] := 100; y1[0] := 120; y2[0] := 122;
x[1] := 111; y1[1] := 125; y2[1] := 127;
x[2] := 123; y1[2] := 124; y2[2] := 130;
x[3] := 113; y1[3] := 130; y2[3] := 135;
x[4] := 119; y1[4] := 133; y2[4] := 140;
x[5] := 121; y1[5] := Double.Nan; y2[5] := 149;
x[6] := 125; y1[6] := 139; y2[6] := 150;
x[7] := 131; y1[7] := 140; y2[7] := 155;
x[8] := 131; y1[8] := Double.Nan; y2[8] := 155;
x[9] := 131; y1[9] := 140; y2[9] := Double.Nan;
y1[10] := 129; y2[10] := 149;
y1[11] := 139; y2[11] := 150;
y1[12] := 140; y2[12] := 155;
y1[13] := 134; y2[13] := 145;
y1[14] := 140; y2[14] := 165;
// Set explained variable
GARCH.Explained.Value := x;
// Set explanatory variables
GARCH.Explanatories.Clear;
GARCH.Explanatories.Add.Value := y1;
GARCH.Explanatories.Add.Value := y2;
// Set parameters of the sample and forecast periods
GARCH.ModelPeriod.FirstPoint := 1;
GARCH.ModelPeriod.LastPoint := 10;
// Set forecasting series parameters
GARCH.Forecast.LastPoint := 15;
// Set constant determination mode
GARCH.Intercept.Mode := InterceptMode.AutoEstimate;
// Set missing data treatment method
GARCH.MissingData.Method := MissingDataMethod.LinTrend;
//Use initial values used by default
GARCH.UseDefaultInitValues := True;
// Set maximum number of iterations for method calculation
GARCH.MaxIteration := 100;
GARCH.Tolerance := 0.0001;
// Set asymmetry order
GARCH.AssymetryOrder := 2;
// Set GARCH model type
GARCH.GARCHSpec := GARCHSpecType.GARCH;
// Calculate the method and output the results
res := GARCH.Execute;
If res <> 0 Then
Debug.WriteLine(GARCH.Errors);
Else
Debug.WriteLine("== Covariance coefficients matrix== ");
For i := 0 To GARCH.CovarianceMatrix.GetUpperBound(1) Do
str := "";
For j := 0 To GARCH.CovarianceMatrix.GetUpperBound(2) Do
str := str + " " + (GARCH.CovarianceMatrix[i, j] As Double).ToString;
End For;
Debug.WriteLine(str);
End For;
End If;
End Sub UserProc;
After executing the example the console window displays values of covariance matrix.
The requirements and result of the Fore.NET example execution match with those in the Fore example.
Imports Prognoz.Platform.Interop.Stat;
…
Public Shared Sub Main(Params: StartParams);
Var
GARCH: ISmGARCH;
x: Array[10] Of Double;
y1, y2: Array[15] Of Double;
Res, i, j: Integer;
str: String;
Matrix: System.Array;
Begin
GARCH := New SmGARCH.Create();
// Set values fornbsp;variables
x[0] := 100; y1[0] := 120; y2[0] := 122;
x[1] := 111; y1[1] := 125; y2[1] := 127;
x[2] := 123; y1[2] := 124; y2[2] := 130;
x[3] := 113; y1[3] := 130; y2[3] := 135;
x[4] := 119; y1[4] := 133; y2[4] := 140;
x[5] := 121; y1[5] := Double.Nan; y2[5] := 149;
x[6] := 125; y1[6] := 139; y2[6] := 150;
x[7] := 131; y1[7] := 140; y2[7] := 155;
x[8] := 131; y1[8] := Double.Nan; y2[8] := 155;
x[9] := 131; y1[9] := 140; y2[9] := Double.Nan;
y1[10] := 129; y2[10] := 149;
y1[11] := 139; y2[11] := 150;
y1[12] := 140; y2[12] := 155;
y1[13] := 134; y2[13] := 145;
y1[14] := 140; y2[14] := 165;
// Set explained variable
GARCH.Explained.Value := x;
// Set explanatory variables
GARCH.Explanatories.Clear();
GARCH.Explanatories.Add().Value := y1;
GARCH.Explanatories.Add().Value := y2;
// Set parameters of the sample and forecast periods
GARCH.ModelPeriod.FirstPoint := 1;
GARCH.ModelPeriod.LastPoint := 10;
// Set forecast series parameters
GARCH.Forecast.LastPoint := 15;
// Set constant determination mode
GARCH.Intercept.Mode := InterceptMode.imAutoEstimate;
// Set missing data treatment method
GARCH.MissingData.Method := MissingDataMethod.mdmLinTrend;
//Use initial values used by default
GARCH.UseDefaultInitValues := True;
// Set maximum number of iterations for method calculation
GARCH.MaxIteration := 100;
GARCH.Tolerance := 0.0001;
// Set asymmetry order
GARCH.AssymetryOrder := 2;
// Set GARCH model type
GARCH.GARCHSpec := GARCHSpecType.garchstEGARCH;
// Calculate the method and output the results
res := GARCH.Execute();
If res <> 0 Then
System.Diagnostics.Debug.WriteLine(GARCH.Errors);
Else
System.Diagnostics.Debug.WriteLine("== Covariance coefficients matrix== ");
Matrix := GARCH.CovarianceMatrix;
For i := 0 To GARCH.CovarianceMatrix.GetUpperBound(0) Do
str := "";
For j := 0 To GARCH.CovarianceMatrix.GetUpperBound(1) Do
str := str + " " + (Matrix[i, j] As Double).ToString();
End For;
System.Diagnostics.Debug.WriteLine(str);
End For;
End If;
End Sub;
See also: