Calculating a Model

Executing the example requires that the repository contains a modeling container with the KONT_MODEL identifier. The Model_1 model is contained in the container, it is set to calculation that uses the universal trend method.

Sub Main;

Var

MB: IMetabase;

Model: IMsModel;

Trans: IMsFormulaTransform;

TransVar: IMsFormulaTransformVariable;

Tree: IMsFormulaTransformSlicesTree;

Selector: IMsFormulaTransformSelector;

CurveEst: IMsCurveEstimationTransform;

Coo: IMsFormulaTransformCoord;

Calc: IMsMethodCalculation;

Period: IMsModelPeriod;

Result: IMsModelCalculationResult;

SmCurve: ISmCurveEstimation;

Ar: Array Of double;

i: Integer;

Begin

MB := MetabaseClass.Active;

//Calculated model

Model := MB.ItemByIdNamespace("Model_1", MB.ItemById("Kont_Model").Key).Bind As IMsModel;

Trans := Model.Transform;

TransVar := Trans.Outputs.Item(0);

Tree := TransVar.SlicesTree(TransVar);

Selector := Trans.CreateSelector;

Selector.Slice := Tree.CreateSlice(1);

CurveEst := Trans.Transform(Selector).Method As IMsCurveEstimationTransform;

//Coordinate by which the calculation is performed

Coo := Trans.CreateCoord(TransVar);

Calc := Trans.CreateCalculation;

//Set sample and forecasting periods

Period := Calc.Period;

Period.IdentificationStartDate := Model.IdentificationStartDate;

Period.IdentificationEndDate := Model.IdentificationEndDate;

Period.ForecastStartDate := Model.ForecastStartDate;

Period.ForecastEndDate := Model.ForecastEndDate;

//Model calculation with the usage of the best dependency form

Result := CurveEst.Execute(Calc, Coo);

SmCurve := Result.StatMethod As ISmCurveEstimation;

Debug.WriteLine(Smoothed series);

Ar := SmCurve.DependenceForms.Item(0).Fitted;

For i := 0 To Ar.Length - 1 Do

Debug.WriteLine(Ar[i]);

End For;

Debug.WriteLine(Forecast);

Ar := SmCurve.DependenceForms.Item(0).Forecast.Value;

For i := 0 To Ar.Length - 1 Do

Debug.WriteLine(Ar[i]);

End For;

End Sub Main;

After executing the example the model is calculated. The smoothed series and forecast values obtained as a calculation result are displayed in the development environment console.

See also:

Examples