ParseAR(Value: String; [AssignOrder: Boolean = True]);
ParseAR(Value: String; AssignOrder: boolean);
Value. String representation of autoregression order.
AssignOrder. Indicates whether the obtained value is set into the ISlARMAGARCH.OrderAR property.
The ParseAR method parses strings with parameters of non-seasonal autoregression.
The Value parameter should contain numbers or ranges of autoregression orders, separated with commas. For example:
ParseAR("1-3,5,7-9", True);
If AssignOrder = True, after executing the ParseAR the obtained value is set into the ISlARMAGARCH.OrderAR property. If AssignOrder = False, the order of parameters of non-seasonal autoregression is unchanged.
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;
// parsing strings with AR and MA
armagarch.ARMA.ParseAR("2", True);
armagarch.ARMA.ParseMA("1", True);
ARMA := armagarch.ARMA;
// 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;
// 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);
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);
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 parameter equals to 2.
Moving average parameter 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;
// parsing strings with AR and MA
armagarch.ARMA.ParseAR("2", True);
armagarch.ARMA.ParseMA("1", True);
ARMA := armagarch.ARMA;
// autoregression order
// the 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;
// 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.GetValue(0) As double;
System.Diagnostics.Debug.WriteLine("Value: " + 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.GetValue(0) As double;
System.Diagnostics.Debug.WriteLine("Value: " + d.ToString());
System.Diagnostics.Debug.Unindent();
End If;
End Sub;
See also: