CoefficientsAR: ICoefficients;
CoefficientsAR: Prognoz.Platform.Interop.Stat.ICoefficients;
The CoefficientsAR property returns coefficients of non-seasonal autoregression.
To get moving average coefficients, use the ISlARMAGARCH.CoefficientsMA property.
To execute the example, add a link to the Stat system assembly.
Sub UserProc;
Var
armagarch: ISmLinearRegress;
W: Array[12] Of Double;
X: Array[20] Of Double;
ARMA: ISlARMA;
AR, MA: Array[1] Of Integer;
Inits: Array[1] Of Double;
res: Integer;
d: Double;
CoefficientsAR, CoefficientsMA: ICoefficients;
ModelCoefficients: IModelCoefficients;
Begin
armagarch := New SmLinearRegress.Create;
// explanatory series values
w[0] := 2; w[4] := -1.9; w[8] := -0.7;
w[1] := 0.8; w[5] := Double.Nan; w[9] := Double.Nan;
w[2] := -0.3; w[6] := 3.2; w[10] := 4.3;
w[3] := -0.3; w[7] := 1.6; w[11] := 1.1;
armagarch.Explained.Value := w;
// explanatory series values
x[0] := Double.Nan; x[10] := 11;
x[1] := 2; x[11] := 12;
x[2] := 3; x[12] := 13;
x[3] := 4; x[13] := Double.Nan;
x[4] := 5; x[14] := 15;
x[5] := 6; x[15] := 16;
x[6] := Double.Nan; x[16] := 17;
x[7] := 8; x[17] := Double.Nan;
x[8] := 9; x[18] := 19;
x[9] := 10; x[19] := 20;
// sample period
armagarch.ModelPeriod.FirstPoint := 1;
armagarch.ModelPeriod.LastPoint := 12;
armagarch.Forecast.LastPoint := 19;
// Method of missing data treatment
armagarch.MissingData.Method := MissingDataMethod.AnyValue;
// exogenous variable is used in the model
armagarch.Explanatories.Clear;
armagarch.Explanatories.Add.Value := X;
// initial approximations of exogenous variable
armagarch.Explanatories.Item(0).InitValue := 0.7;
ModelCoefficients := armagarch.ModelCoefficients;
// constant will be used in the model
ModelCoefficients.Intercept.Mode := InterceptMode.AutoEstimate;
// initial approximation for constant
ModelCoefficients.Intercept.InitValue := 3;
ARMA := armagarch.ARMA;
// autoregression order
AR[0] := 2;
ARMA.OrderAR := AR;
// moving average order
MA[0] := 1;
ARMA.OrderMA := MA;
// method of initial approximations detection
ARMA.CalcInitMode := ARMAInitType.Manual;
// initial approximations of autoregression
Inits[0] := 0.2;
ARMA.InitAR := Inits;
// initial approximations of moving average
Inits[0] := 0.3;
ARMA.InitMA := Inits;
// optimization method
ARMA.EstimationMethod := ARMAEstimationMethodType.GaussNewton;
//number of iterations for optimization method
ARMA.MaxIteration := 50;
//accuracy for optimization method
ARMA.Tolerance := 0.1;
// calculate model
res := armagarch.Execute;
Debug.WriteLine(armagarch.Errors);
If (res = 0) Then
// autoregression coefficients
Debug.WriteLine("Autoregression coefficients estimates");
CoefficientsAR := ARMA.CoefficientsAR;
Debug.Indent;
d := CoefficientsAR.Estimate[0];
Debug.WriteLine("Value: " + d.ToString);
d := CoefficientsAR.StandardError[0];
Debug.WriteLine("Standard error: " + d.ToString);
d := CoefficientsAR.TStatistic[0];
Debug.WriteLine("t-statistic: " + d.ToString);
d := CoefficientsAR.Probability[0];
Debug.WriteLine("Probability: " + d.ToString);
Debug.Unindent;
// moving average coefficients
Debug.WriteLine("Estimates of moving average coefficients");
CoefficientsMA := ARMA.CoefficientsMA;
Debug.Indent;
d := CoefficientsMA.Estimate[0];
Debug.WriteLine("Value: " + d.ToString);
d := CoefficientsMA.StandardError[0];
Debug.WriteLine("Standard error: " + d.ToString);
d := CoefficientsMA.TStatistic[0];
Debug.WriteLine("t-statistic: " + d.ToString);
d := CoefficientsMA.Probability[0];
Debug.WriteLine("Probability: " + d.ToString);
Debug.Unindent;
End If;
End Sub UserProc;
As a result of the example execution, the following settings are defined:
Sample period and calculation period start date are set manually.
Autoregression order equals to 2.
Moving average order equals to 1.
Initial approximations of autoregression and moving average are set.
The console window displays estimates of autoregression coefficients and moving average coefficients.
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
armagarch: ISmLinearRegress;
W: Array[12] Of double;
X: Array[20] Of double;
ARMA: ISlARMA;
AR, MA: Array[1] Of integer;
Inits: Array[1] Of double;
res: integer;
d: double;
CoefficientsAR, CoefficientsMA: ICoefficients;
ModelCoefficients: IModelCoefficients;
Begin
armagarch := New SmLinearRegress.Create();
// explanatory series values
w[0] := 2; w[4] := -1.9; w[8] := -0.7;
w[1] := 0.8; w[5] := Double.Nan; w[9] := Double.Nan;
w[2] := -0.3; w[6] := 3.2; w[10] := 4.3;
w[3] := -0.3; w[7] := 1.6; w[11] := 1.1;
armagarch.Explained.Value := w;
// explanatory series values
x[0] := Double.Nan; x[10] := 11;
x[1] := 2; x[11] := 12;
x[2] := 3; x[12] := 13;
x[3] := 4; x[13] := Double.Nan;
x[4] := 5; x[14] := 15;
x[5] := 6; x[15] := 16;
x[6] := Double.Nan; x[16] := 17;
x[7] := 8; x[17] := Double.Nan;
x[8] := 9; x[18] := 19;
x[9] := 10; x[19] := 20;
// sample period
armagarch.ModelPeriod.FirstPoint := 1;
armagarch.ModelPeriod.LastPoint := 12;
armagarch.Forecast.LastPoint := 19;
// Method of missing data treatment
armagarch.MissingData.Method := MissingDataMethod.mdmAnyValue;
// exogenous variable is used in the model
armagarch.Explanatories.Clear();
armagarch.Explanatories.Add().Value := X;
// initial approximations of exogenous variable
armagarch.Explanatories.Item[0].InitValue := 0.7;
ModelCoefficients := armagarch.ModelCoefficients;
// constant will be used in the model
ModelCoefficients.Intercept.Mode := InterceptMode.imAutoEstimate;
// initial approximation for constant
ModelCoefficients.Intercept.InitValue := 3;
ARMA := armagarch.ARMA;
// autoregression order
AR[0] := 2;
ARMA.OrderAR := AR;
// moving average order
MA[0] := 1;
ARMA.OrderMA := MA;
// method of initial approximations detection
ARMA.CalcInitMode := ARMAInitType.armaitManual;
// initial approximations of autoregression
Inits[0] := 0.2;
ARMA.InitAR := Inits;
// initial approximations of moving average
Inits[0] := 0.3;
ARMA.InitMA := Inits;
// optimization method
ARMA.EstimationMethod := ARMAEstimationMethodType.armaemtGaussNewton;
//number of iterations for optimization method
ARMA.MaxIteration := 50;
//accuracy for optimization method
ARMA.Tolerance := 0.1;
// calculate model
res := armagarch.Execute();
System.Diagnostics.Debug.WriteLine(armagarch.Errors);
If (res = 0) Then
// autoregression coefficients
System.Diagnostics.Debug.WriteLine("Autoregression coefficients estimates");
CoefficientsAR := ARMA.CoefficientsAR;
System.Diagnostics.Debug.Indent();
//d := CoefficientsAR.Estimate[0];
d := CoefficientsAR.Estimate.GetValue(0) As double;
System.Diagnostics.Debug.WriteLine("Value: " + d.ToString());
//d := CoefficientsAR.StandardError[0];
d := CoefficientsAR.StandardError.GetValue(0) As double;
System.Diagnostics.Debug.WriteLine("Standard error: " + d.ToString());
//d := CoefficientsAR.TStatistic[0];
d := CoefficientsAR.TStatistic.GetValue(0) As double;
System.Diagnostics.Debug.WriteLine("t-statistic: " + d.ToString());
//d := CoefficientsAR.Probability[0];
d := CoefficientsAR.Probability.GetValue(0) As double;
System.Diagnostics.Debug.WriteLine("Probability: " + d.ToString());
System.Diagnostics.Debug.Unindent();
// moving average coefficients
System.Diagnostics.Debug.WriteLine("Estimates of moving average coefficients");
CoefficientsMA := ARMA.CoefficientsMA;
System.Diagnostics.Debug.Indent();
//d := CoefficientsMA.Estimate[0];
d := CoefficientsMA.Estimate.GetValue(0) As double;
System.Diagnostics.Debug.WriteLine("Value: " + d.ToString());
//d := CoefficientsMA.StandardError[0];
d := CoefficientsMA.StandardError.GetValue(0) As double;
System.Diagnostics.Debug.WriteLine("Standard error: " + d.ToString());
//d := CoefficientsMA.TStatistic[0];
d := CoefficientsMA.TStatistics.GetValue(0) As double;
System.Diagnostics.Debug.WriteLine("t-statistic: " + d.ToString());
//d := CoefficientsMA.Probability[0];
d := CoefficientsMA.Probability.GetValue(0) As double;
System.Diagnostics.Debug.WriteLine("Probability: " + d.ToString());
System.Diagnostics.Debug.Unindent();
End If;
End Sub;
See also: