CenterMovingAverage: Boolean;
CenterMovingAverage: boolean;
The CenterMovingAverage property determines whether to center the moving average.
Available values:
True. Moving average is centered.
False. Default value. Moving average is not centered.
Executing the example requires that the repository contains a modeling container with the MODEL_SPACE identifier, containing a model with the MODEL_CENSUS1 identifier and a variable with the OUTPUT_VAR_CENSUS identifier. The variable must contain quarterly data.
Add links to the Cubes, Dimensions, Metabase, Ms, Stat system assemblies.
Sub Census1;
Var
mb: IMetabase;
MsObj: IMetabaseObjectDescriptor;
Model: IMsModel;
Transform: IMsFormulaTransform;
Vars: IMsFormulaTransformVariables;
OutputStub: IVariableStub;
OutputVar: IMsFormulaTransformVariable;
Coord: IMsFormulaTransformCoord;
Slice: IMsFormulaTransformSlice;
Selector: IMsFormulaTransformSelector;
Formula: IMsFormula;
Census1: IMsCensus1Transform;
Calc: IMsMethodCalculation;
Data: Array Of Double;
Begin
mb := MetabaseClass.Active;
// Get modeling container
MsObj := mb.ItemById("MODEL_SPACE");
// Get the model
Model := mb.ItemByIdNamespace("MODEL_CENSUS1", MsObj.Key).Edit As IMsModel;
// Get model parameters
Transform := Model.Transform;
// Set the output variable
Vars := Transform.Outputs;
Vars.Clear;
OutputStub := mb.ItemByIdNamespace("OUTPUT_VAR_CENSUS", MsObj.Key).Edit As IVariableStub;
OutputVar := Vars.Add(OutputStub);
// Get the parameters of the method of model calculation
Coord := Transform.CreateCoord(OutputVar);
Slice := OutputVar.Slices.Add(Null);
Selector := Transform.CreateSelector;
Selector.Slice := Slice;
Formula := Transform.Transform(Selector);
// Set the calendar frequency of calculation
Formula.Level := DimCalendarLevel.Quarter;
// Set the method of calculation of the model
Formula.Kind := MsFormulaKind.Census1;
// Get the parameters of calculation of Census1 method
Census1 := Formula.Method As IMsCensus1Transform;
// Setting seasonality type
Census1.Seasonality := SeasonalityType.Additive;
// Center the moving average
Census1.CenterMovingAverage := True;
// Set the parameters of missing data treatment
Census1.MissingData.Method := MissingDataMethod.LinTrend;
Census1.OutputType := MsCensus1OutputType.RD;
// Save changes
(Model As IMetabaseObject).Save;
// Set the parameters of calculation period
Calc := Transform.CreateCalculation;
Calc.Period.IdentificationStartDate := model.Period.IdentificationStartDate;
Calc.Period.IdentificationEndDate := model.Period.IdentificationEndDate;
Calc.Period.ForecastStartDate := model.Period.ForecastStartDate;
Calc.Period.ForecastEndDate := model.Period.ForecastEndDate;
// Perform calculation
Census1.Execute(Calc, Coord);
// Display calculation results
Data := Census1.Explained.Serie(Calc);
Debug.WriteLine("Modeled data");
Print(Data); Debug.WriteLine("");
Data := Census1.MovingAverage;
Debug.WriteLine("Smoothed series");
Print(Data); Debug.WriteLine("");
Data := Census1.RatioDifferences;
Debug.WriteLine("Difference");
Print(Data); Debug.WriteLine("");
Data := Census1.Seasonal;
Debug.WriteLine("Seasonal component");
Print(Data); Debug.WriteLine("");
Data := Census1.SeasonalAdjustment;
Debug.WriteLine("Seasonal adjustment");
Print(Data); Debug.WriteLine("");
Data := Census1.TrendCycle;
Debug.WriteLine("Trend-cycle component");
Print(Data); Debug.WriteLine("");
Data := Census1.Irregula;
Debug.WriteLine("Irregular component");
Print(Data); Debug.WriteLine("");
End Sub Census1;
// Data output procedure
Sub Print(Data: Array Of Double);
Var
i: Integer;
Begin
Debug.Indent;
For i := 0 To Data.Length - 1 Do
Debug.WriteLine(i.ToString + " " + Data[i].ToString);
End For;
Debug.Unindent;
End Sub Print;
Example execution result: the MODEL_SPACE model is set up on calculation of the Census1 method, the model is calculated, the results are displayed in the console window.
The requirements and result of the Fore.NET example execution match with those in the Fore example.
Imports Prognoz.Platform.Interop.Cubes;
Imports Prognoz.Platform.Interop.Dimensions;
Imports Prognoz.Platform.Interop.Ms;
Imports Prognoz.Platform.Interop.Stat;
…
Public Shared Sub Main(Params: StartParams);
Var
mb: IMetabase;
MsObj: IMetabaseObjectDescriptor;
Model: IMsModel;
Transform: IMsFormulaTransform;
Vars: IMsFormulaTransformVariables;
OutputStub: IVariableStub;
OutputVar: IMsFormulaTransformVariable;
Coord: IMsFormulaTransformCoord;
Slice: IMsFormulaTransformSlice;
Selector: IMsFormulaTransformSelector;
Formula: IMsFormula;
Census1: IMsCensus1Transform;
Calc: IMsMethodCalculation;
Data: System.Array;
Begin
mb := Params.Metabase;
// Get modeling container
MsObj := mb.ItemById["MODEL_SPACE"];
// Get the model
Model := mb.ItemByIdNamespace["MODEL_CENSUS1", MsObj.Key].Edit() As IMsModel;
// Get model parameters
Transform := Model.Transform;
// Set the output variable
Vars := Transform.Outputs;
Vars.Clear();
OutputStub := mb.ItemByIdNamespace["OUTPUT_VAR_CENSUS", MsObj.Key].Edit() As IVariableStub;
OutputVar := Vars.Add(OutputStub);
// Get the parameters of the method of model calculation
Coord := Transform.CreateCoord(OutputVar);
Slice := OutputVar.Slices.Add(Null);
Selector := Transform.CreateSelector();
Selector.Slice := Slice;
Formula := Transform.Transform[Selector];
// Set the calendar frequency of calculation
Formula.Level := DimCalendarLevel.dclQuarter;
// Set the method of calculation of the model
Formula.Kind := MsFormulaKind.mfkCensus1;
// Get the parameters of calculation of Census1 method
Census1 := Formula.Method As IMsCensus1Transform;
// Setting seasonality type
Census1.Seasonality := SeasonalityType.sstAdditive;
// Center the moving average
Census1.CenterMovingAverage := True;
// Set the parameters of missing data treatment
Census1.MissingData.Method := MissingDataMethod.mdmLinTrend;
Census1.OutputType := MsCensus1OutputType.mc1otRD;
// Save changes
(Model As IMetabaseObject).Save();
// Set the parameters of calculation period
Calc := Transform.CreateCalculation();
Calc.Period.IdentificationStartDate := model.Period.IdentificationStartDate;
Calc.Period.IdentificationEndDate := model.Period.IdentificationEndDate;
Calc.Period.ForecastStartDate := model.Period.ForecastStartDate;
Calc.Period.ForecastEndDate := model.Period.ForecastEndDate;
// Perform calculation
Census1.Execute(Calc, Coord);
// Display calculation results
Data := Census1.Explained.Serie[Calc];
System.Diagnostics.Debug.WriteLine("Modeled data");
Print(Data); System.Diagnostics.Debug.WriteLine("");
Data := Census1.MovingAverage;
System.Diagnostics.Debug.WriteLine("Smoothed series");
Print(Data); System.Diagnostics.Debug.WriteLine("");
Data := Census1.RatioDifferences;
System.Diagnostics.Debug.WriteLine("Difference");
Print(Data); System.Diagnostics.Debug.WriteLine("");
Data := Census1.Seasonal;
System.Diagnostics.Debug.WriteLine("Seasonal component");
Print(Data); System.Diagnostics.Debug.WriteLine("");
Data := Census1.SeasonalAdjustment;
System.Diagnostics.Debug.WriteLine("Seasonal adjustment");
Print(Data); System.Diagnostics.Debug.WriteLine("");
Data := Census1.TrendCycle;
System.Diagnostics.Debug.WriteLine("Trend-cycle component");
Print(Data); System.Diagnostics.Debug.WriteLine("");
Data := Census1.Irregula;
System.Diagnostics.Debug.WriteLine("Irregular component");
Print(Data); System.Diagnostics.Debug.WriteLine("");
End Sub;
// Data output procedure
Public Shared Sub Print(Data: System.Array);
Var
i: Integer;
Begin
System.Diagnostics.Debug.Indent();
For i := 0 To Data.Length - 1 Do
System.Diagnostics.Debug.WriteLine(i.ToString() + " " + Data[i].ToString());
End For;
System.Diagnostics.Debug.Unindent();
End Sub Print;
See also: