Creating a Determinate Equation Model with Lagged Operands

Contents

Description

Requirements

Example

Description

Consider an example of creating a model of determinate equation with operands, for which lag is set.

Requirements

Executing the example requires that the repository contains a modeling container with the MS identifier and a database with the TSDB identifier. This time series database must contain mandatory custom attributes of series being references to the dictionary.

Add links to the Cubes, Dimensions, Metabase, Ms system assemblies.

Example

Sub UserProc;
Var
    Mb: IMetabase;
    CrInf: IMetabaseObjectCreateInfo;
    Model: IMsModel;
    Transform: IMsFormulaTransform;
    TransformVarables: IMsFormulaTransformVariables;
    RubrDescr: IMetabaseObjectDescriptor;
    Stub: IVariableStub;
    TransVar: IMsFormulaTransformVariable;
    Tree: IMsFormulaTransformSlicesTree;
    Slice: IMsFormulaTransformSlice;
    Selector: IMsFormulaTransformSelector;
    Formula: IMsFormula;
    Determ: IMsDeterministicTransform;
    TermX1, TermX2: IMsFormulaTerm;
    TermInfo: IMsFormulaTermInfo;
    Period: IMsModelPeriod;
Begin
    Mb := MetabaseClass.Active;
    // Specify basic parameters of the model as a repository object
    CrInf := Mb.CreateCreateInfo;
    CrInf.ClassId := MetabaseObjectClass.KE_CLASS_MSMODEL;
    // Specify model identifier
    CrInf.Id := Mb.GenerateId("MODEL_DETERMINISTIC_LAG", Mb.ItemById("MS").Key);
    // Specify model name
    CrInf.Name := "Determinate equation with lagged operands";
    // Specify modeling container which will contain the model
    CrInf.Parent := Mb.ItemById("MS");
    // Create a model
    Model := Mb.CreateObject(CrInf).Edit As IMsModel;
    // Get object to set up model parameters
    Transform := Model.Transform;
    // Get object to work with output variable
    TransformVarables := Transform.Outputs;
    // Get time series database (TSDB)
    RubrDescr := Mb.ItemById("TSDB");
    // Cast the obtained TSDB to the abstract data source
    Stub := RubrDescr.Bind As IVariableStub;
    // Use TSDB as a data source of output variable
    TransVar := TransformVarables.Add(Stub);
    // Specify output variable slice
    Tree := TransVar.SlicesTree(TransVar);
    Slice := Tree.CreateSlice(1);
    // Get model settings for output variable slice
    Selector := Transform.CreateSelector;
    Selector.Slice := Slice;
    Formula := Transform.Transform(Selector);
    // Specify calculation method - determinate equation
    Formula.Kind := MsFormulaKind.Deterministic;
    // Set the calendar frequency of calculation
    Formula.Level := DimCalendarLevel.Year;
    // Get object for setting up determinate equation
    Determ := Formula.Method As IMsDeterministicTransform;
    // Add the factor with the TSDB data source in the model
    TransVar := Transform.Inputs.Add(Stub);
    Tree := TransVar.SlicesTree(TransVar);
    Slice := Tree.CreateSlice(2);
    // Add the first factor to the collection of elements of expressions used for equation creation
    TermX1 := Determ.Operands.Add(Slice);
    // Get expression element parameters
    TermInfo := TermX1.TermInfo;
    // Set type of expression element: date-specific value
    TermInfo.Type := MsFormulaTermType.Date;
    // Set date for expression element
    TermInfo.SetDate(DateTime.ComposeDay(201411), "YYYY");
    // Set changed parameters for expression element
    TermX1.TermInfo := TermInfo;
    // Add the factor with the TSDB data source in the model
    TransVar := Transform.Inputs.Add(Stub);
    Tree := TransVar.SlicesTree(TransVar);
    Slice := Tree.CreateSlice(3);
    // Add the second factor to the collection of elements of expressions used for equation creation
    TermX2 := Determ.Operands.Add(Slice);
    // Get expression element parameters
    TermInfo := TermX2.TermInfo;
    // Set lag for expression element
    TermInfo.Lag := "-2";
    // Set changed parameters for expression element
    TermX2.TermInfo := TermInfo;
    // Set expression for determinate equation calculation
    Determ.Expression.AsString := "Iif(" + TermX1.TermToInnerText + ">-0.5, " +
        TermX2.TermToInnerText + "+1, " + TermX2.TermToInnerText + "-1)";
    // Specify model calculation periods
    Period := Transform.Period;
    Period.IdentificationStartDate := DateTime.ComposeDay(200011);
    Period.IdentificationEndDate := DateTime.ComposeDay(20141231);
    Period.ForecastStartDate := DateTime.ComposeDay(201511);
    Period.ForecastEndDate := DateTime.ComposeDay(20201231);
    // Save the model to the repository
    (Model As IMetabaseObject).Save;
End Sub UserProc;

See also:

Examples | IMsDeterministicTransform