IModelling.Collapse

Syntax

Collapse(Input: ITimeSeries;

         Method: MsCollapseType;

         TargetFrequency: MsFrequency;

         [MissingData: MissingDataMethod =16;]

         [NumberOfPoints: Integer = 1;]

         [SpecifiedValue: Double = 0;]

         [AdditionalSeries: ITimeSeries = Null]): Variant;

Parameters

Input. Input variable.

Method. Aggregation method.

TargetFrequency. Output frequency.

MissingData. Missing data treatment method.

NumberOfPoints. Additional parameter for missing data treatment method.

SpecifiedValue. The value, with which missing data is substituted by the MissingDataMethod.SpecifiedValue Value method.

AdditionalSeries. The series that is used to substitute missing data by the MissingDataMethod.Pattern Pattern and MissingDataMethod.Overlay Overlay methods.

Description

The Collapse method aggregates variable values.

Comments

The NumberOfPoints parameter can take only positive values. It is used for the following methods of missing data treatment:

The method aggregates data from the lower level to the higher level; it is used to calculate problems that require data aggregation. For example, data calculated by months must be summed for quarterly frequency.

On data aggregation, the following calendar frequency settings are taken into account: start period offset relative to its start/end.

Example of data aggregation from daily to weekly frequency

Example

Executing the example requires that the repository contains a modeling container with the MS identifier. This container includes a model with the MODEL_Q identifier and quarterly frequency that is calculated by the determinate equation method and contains at least one input factor.

Add links to the Metabase and Ms system assemblies.

Sub UserProc;
Var
    Mb: IMetabase;
    ModelSpace, ModelObj: IMetabaseObject;
    Transf: IMsFormulaTransform;
    Formula: IMsFormula;
    Model: IMsModel;
    Determ: IMsDeterministicTransform;
    TransVar: IMsFormulaTransformVariable;
    Slice: IMsFormulaTransformSlice;
    TermInfo: IMsFormulaTermInfo;
    Expr: IExpression;

Begin
    // Get the current repository
    Mb := MetabaseClass.Active;
    // Get modeling container
    ModelSpace := Mb.ItemById("MS").Bind;
    // Get model
    ModelObj := Mb.ItemByIdNamespace("MODEL_D_Q", ModelSpace.Key).Edit;
    Model := ModelObj As IMsModel;
    // Get model parameters
    Transf := Model.Transform;
    // Get model calculation method
    Formula := Transf.FormulaItem(0);
    Determ := Formula.Method As IMsDeterministicTransform;
    // Get the first model factor
    TransVar := Transf.Inputs.Item(0);
    // Get slice corresponding to factor
    Slice := TransVar.Slices.Item(0);
    // Create a term based on the first factor
    TermInfo := Transf.CreateTermInfo;
    TermInfo.Slice := Slice;

    // Get expression for model calculation
    Expr := Determ.Expression;
    // Set expression for model calculation
    Expr.AsString := "Collapse(" + TermInfo.TermInnerText + ", MsCollapseType.Total, " +
        "MsFrequency.Annual, MissingDataMethod.NPointsAverage, 4)";
    // Check expression correctness
    If Expr.Valid
        //If expression is correct, then save changes
        Then ModelObj.Save;
        // If expression is not correct, then display message in the console window
        Else Debug.WriteLine("Model is not saved: error in formula");
    End If;
End Sub UserProc;

After executing the example the model will aggregate data of the first input variable with quarterly frequency for annual one with missing data treatment by means of the N-Point Average method where N = 4.

Example of Use in Expressions

Expression 1:

collapse({Brazil|BCA}, MsCollapseType.Total, MsFrequency.Annual, MissingDataMethod.NPointsAverage, 4)

Result: data will be aggregated for the Brazil|BCA time series for annual frequency by summing method with missing data treatment by the N-Point Average method where N = 4.

Use: it can be used in formulas of cross functional expression editor in any platform tool where it is available.

Expression 2:

Collapse(X1,MsCollapseType.Average,MsFrequency.Annual, MissingDataMethod.LinTrend)

Result: for the X1 factor data will be aggregated for annual frequency using average value calculation method with the Linear Trend missing data treatment method.

Use: it can be used in model formulas of modeling container based on variables.

See also:

IModelling | Time Series Database: Calculator, Aggregation | Modeling Container: The Models Collapse (Series Calculation),Collapse (Pointwise Calculation), Editing Regressor or Formula