Below is the example of using the GetMs operation to calculate an equation. The request contains an instance of opened modeling container, equation calculation pattern, and parameters of operation execution. The response contains an instance of the model that contains an equation with calculation results.
To execute the example, the equation must be calculated with the Hodrick-Prescott Filter method.
{ "GetMs" : { "tMs" : { "id" : "PELGIOLKGDNBFOAEMPCPNCBIABJENAHENIJLOHGDPPOCJNCA!M!S!CBHOPGCMKGDNBFOAECKKFBPJGBCNNGAHENIINDPGAMOCGIBAG" }, "tArg" : { "pattern" : { "obInst" : "false", "all" : "false", "item" : { "key" : "89669", "problem" : { "metamodel" : { "calculationChain" : "Get", "calcChainPattern" : { "modelPattern" : { "transform" : { "outputs" : "Get", "formulaCount" : "true", "formulas" : { "method" : { "series" : "true" } }, "displayId" : "true", "equationsFormula" : { "method" : "" }, "series" : "Get", "kind" : "true", "displaySettings" : "true", "additionalAttributes" : "true", "calculationType" : "true", "calculationDirection" : "true", "transformVariable" : { "slices" : "Get", "transformSlice" : { "selection" : "Get" } } }, "stochastic" : "true", "calculationPeriod" : "true", "useModelPeriod" : "true", "useExistingData" : "true", "treatNullsAsZeros" : "true", "autoName" : "true", "generatedName" : "true", "period" : "true", "isExclusive" : "true", "useAutoPeriod" : "true" }, "entryKeys" : { "l" : "4" } } } } } }, "execParams" : { "k" : "0", "modelKeys" : { "l" : "4" }, "scenarioKeys" : "", "execMethod" : "true", "execEvaluateSeries" : "true" } } } }
{ "GetMsResult" : { "id" : { "id" : "PELGIOLKGDNBFOAEMPCPNCBIABJENAHENIJLOHGDPPOCJNCA!M!S!CBHOPGCMKGDNBFOAECKKFBPJGBCNNGAHENIINDPGAMOCGIBAG" }, "meta" : { "item" : { "k" : "89669", "id" : "MODEL_NEW", "n" : "MODEL_NEW", "vis" : "1", "type" : "Problem", "problemMd" : { "metamodel" : { "k" : "89670", "calculationChain" : { "its" : { "Item" : { "k" : "4", "id" : "OBJ4", "n" : "MyOutputVavable|A[t] = HPFilter(MyInputVavable[t], Lambda = 100.000), (From parent)-(From parent)", "vis" : "1", "type" : "Model", "excluded" : "0", "graphMeta" : "", "model" : { "transform" : { "outputs" : { "its" : { "Item" : { "k" : "1", "id" : "VARIABLES_89670", "n" : "Variables", "vis" : "1", "slices" : { "its" : { "Item" : { "k" : "0", "id" : "MyOutputVavable|A", "n" : "MyOutputVavable|A", "vis" : "1", "variableKey" : "1", "stubKey" : "89671", "selections" : { "its" : { "Item" : { "id" : { "id" : "89683" }, "variant" : "2" } } }, "aggregator" : "None", "parametrizedDimensions" : { "its" : { "Item" : { "dimension" : "0", "parameter" : "0" } } }, "unitInfo" : { "unit" : "4294967295", "measure" : "4294967295", "baseUnit" : "4294967295", "unitsDimensionKey" : "0" }, "level" : "Year" } } }, "variableStubKey" : "89671", "parameterID" : "", "kind" : "Stub", "attributeId" : "", "attributeType" : "Series" } } }, "formulaCount" : "1", "formulas" : { "its" : { "it" : [ { "k" : "0", "kind" : "HodrickPrescottFilter", "method" : { "hodrickPrescottFilter" : { "missingData" : { "specifiedVector" : "", "method" : "None", "methodParameter" : "5", "specifiedValue" : "0", "specifiedTerm" : { "k" : "4294967295" } }, "smoothingParameter" : "100", "smoothingParameterMode" : "EditDirectly", "power" : "2", "smSmoothingParameter" : "100", "explained" : { "slice" : { "k" : "0", "id" : "MyOutputVavable|A", "n" : "MyOutputVavable|A", "vis" : "1", "variableKey" : "1", "stubKey" : "89671", "selections" : { "its" : { "Item" : { "id" : { "id" : "89683" }, "variant" : "2" } } }, "aggregator" : "None", "parametrizedDimensions" : { "its" : { "Item" : { "dimension" : "0", "parameter" : "0" } } }, "unitInfo" : { "unit" : "4294967295", "measure" : "4294967295", "baseUnit" : "4294967295", "unitsDimensionKey" : "0" }, "level" : "Year" }, "lag" : "", "key" : "0", "termToText" : "{MyOutputVavable|A[t]}", "termToInnerText" : "@_1:0[]", "termInfo" : { "k" : "4294967295", "lag" : "0", "inversion" : { "type" : "None", "lag" : "PrecidingValue", "previousLag" : "-1", "seasonality" : "None", "dependence" : "Linear", "K" : "3" }, "slice" : { "k" : "0", "id" : "MyOutputVavable|A", "n" : "MyOutputVavable|A", "vis" : "1", "variableKey" : "1", "stubKey" : "89671", "selections" : { "its" : { "Item" : { "id" : { "id" : "89683" }, "variant" : "2" } } }, "aggregator" : "None", "parametrizedDimensions" : { "its" : { "Item" : { "dimension" : "0", "parameter" : "0" } } }, "unitInfo" : { "unit" : "4294967295", "measure" : "4294967295", "baseUnit" : "4294967295", "unitsDimensionKey" : "0" }, "level" : "Year" }, "date" : "1899-12-30" }, "unitInfo" : { "unit" : "4294967295", "measure" : "4294967295", "baseUnit" : "4294967295", "unitsDimensionKey" : "0" }, "included" : "0" } }, "name" : "HPFilter(X, Lambda = 100.000)", "series" : { "input" : { "k" : "4294967295", "lag" : "0", "inversion" : { "type" : "None", "lag" : "PrecidingValue", "previousLag" : "-1", "seasonality" : "None", "dependence" : "Linear", "K" : "3" }, "slice" : { "k" : "0", "id" : "1", "n" : "MyInputVavable", "vis" : "1", "variableKey" : "2", "stubKey" : "89671", "selections" : { "its" : { "Item" : { "id" : { "id" : "89683" }, "variant" : "1" } } }, "aggregator" : "None", "parametrizedDimensions" : { "its" : { "Item" : { "dimension" : "0", "parameter" : "0" } } }, "unitInfo" : { "unit" : "4294967295", "measure" : "4294967295", "baseUnit" : "4294967295", "unitsDimensionKey" : "0" }, "level" : "Year" }, "date" : "1899-12-30" } }, "evaluateSeries" : { "its" : { "Item" : { "scenarioKey" : "4294967295", "fact" : { "d" : [ "1", "4", "2", "7", "7.5", "9.1", "10.7", "12.3", "13.9", "15.5", "17.1", "18.7", "20.3", "21.9", "23.5", "25.1", "26.7", "28.3", "29.9", "31.5", "33.1", "34.7", "36.3", "37.9", "39.5", "41.1", "NaN", "NaN", "NaN" ] }, "modelling" : { "d" : [ "1.110301648779354", "2.702470023930953", "4.293535382594759", "5.895370008043668", "7.496910829724635", "9.098141077004177", "10.69907487095158", "12.29974492186606", "13.90019319133736", "15.50046419173652", "17.10060050352123", "18.70064006523181", "20.30061481037338", "21.90055027179873", "23.50046583425696", "25.10037537977917", "26.70028813205387", "28.30020956097182", "29.90014225510319", "31.50008670740845", "33.10004198829701", "34.7000063011042", "36.29997742928238", "37.89995309327283", "39.49993123922401", "41.09991028235167", "NaN", "NaN", "NaN" ] }, "residuals" : { "d" : [ "-0.1103016487793536", "1.297529976069047", "-2.293535382594759", "1.104629991956332", "0.003089170275365483", "0.001858922995822354", "0.0009251290484222352", "0.0002550781339358821", "-0.000193191337361398", "-0.0004641917365209025", "-0.0006005035212304222", "-0.0006400652318099276", "-0.0006148103733742971", "-0.0005502717987297956", "-0.0004658342569570095", "-0.0003753797791645752", "-0.00028813205387479", "-0.0002095609718217872", "-0.0001422551031957653", "-8.670740845317937e-05", "-4.198829700641227e-05", "-6.301104193084939e-06", "2.257071761846419e-05", "4.690672717089228e-05", "6.876077598860775e-05", "8.971764832921281e-05", "NaN", "NaN", "NaN" ] }, "input" : { "d" : [ "3", "7", "2", "6", "4", "1", "5", "3.42857143", "3.28571429", "3.14285714", "3", "2.85714286", "2.71428571", "2.57142857", "2.42857143", "2.28571429", "2.14285714", "2", "1.85714286", "1.71428571", "1.57142857", "1.42857143", "1.28571429", "1.14285714", "1", "0.85714286", "0.71428571", "0.57142857", "NaN", "NaN", "NaN" ] }, "indicators" : { "its" : "" } } }, "dates" : { "it" : [ "1990A1", "1991A1", "1992A1", "1993A1", "1994A1", "1995A1", "1996A1", "1997A1", "1998A1", "1999A1", "2000A1", "2001A1", "2002A1", "2003A1", "2004A1", "2005A1", "2006A1", "2007A1", "2008A1", "2009A1", "2010A1", "2011A1", "2012A1", "2013A1", "2014A1", "2015A1", "2016A1", "2017A1", "2018A1", "2019A1", "2020A1" ] } }, "inversionInfo" : { "type" : "None", "lag" : "PrecidingValue", "previousLag" : "-1", "seasonality" : "None", "dependence" : "Linear", "K" : "3" }, "doUseR" : "0", "supportsR" : "1" }, "calendarLevel" : "Year", "outputSliceKey" : "0" } ] } }, "displayId" : "0", "series" : { "its" : "" }, "kind" : "Simple", "displaySettings" : { "displayTermsAs" : "Derive" }, "additionalAttributes" : "", "calculationType" : "Serie", "calculationDirection" : "Forward" }, "stochastic" : "0", "calculationPeriod" : "Forecast", "useModelPeriod" : "1", "useExistingData" : "0", "treatNullsAsZeros" : "0", "autoName" : "1", "period" : { "identificationStartDate" : "1990-01-01", "identificationEndDate" : "2018-04-24", "forecastStartDate" : "2018-04-25", "forecastEndDate" : "2020-01-01", "identificationStartDateParamID" : "", "identificationEndDateParamID" : "", "forecastStartDateParamID" : "", "forecastEndDateParamID" : "", "autoPeriod" : "28672", "identificationStartOffset" : "0", "identificationEndOffset" : "0", "forecastEndOffset" : "0", "isIdentStartCorrect" : "1", "isIdentEndCorrect" : "1", "isForecastEndCorrect" : "1" }, "isExclusive" : "1", "useAutoPeriod" : "1", "generatedName" : "MyOutputVavable|A[t] = HPFilter(MyInputVavable[t], Lambda = 100.000)", "warnings" : "", "readOnly" : "0" } } } }, "visualController" : { "userRPath" : "", "isRExist" : "0" }, "suppressEmptyFilter" : { "suppressEmpty" : "0", "suppressEmptyArea" : "SerieBounds" }, "readOnly" : "0", "variableTestUseR" : "0", "calculateIdentOnFact" : "0" }, "useScenarios" : "0", "readOnly" : "0" } } } } }
The GetMsHpf function calculates the specified equation. Input parameters:
ms. Opened modeling container instance.
modelKey. Key of the model that contains the equation.
eqKey. Equation key.
After executing the function returns a model that contains calculated equation. Calculation results are displayed in the console window. The following auxiliary procedures described in the Calculating Equation section are used to output the results: PrintArray and PrintSeries.
To execute the example, the equation must be calculated with the Hodrick-Prescott Filter method.
public static MsCalculationChainEntry GetMsHpf(MsId ms, ulong modelKey, ulong eqKey) { var getMsOp = new GetMs(); // Set operation execution parameters getMsOp.tMs = ms; getMsOp.tArg = new GetMsArg() { // Set data getting pattern pattern = new MsMdPattern() { obInst = false, all = false, item = new MsItemPattern() { // Specify calculated model key key = modelKey, problem = new MsProblemPattern() { metamodel = new MsMetaModelPattern() { calculationChain = ListOperation.Get, calcChainPattern = new MsCalculationChainPattern() { // Specify calculated equation key entryKeys = new long[] { (long)eqKey }, modelPattern = new MsModelPattern() { autoName = true, calculationPeriod = true, generatedName = true, isExclusive = true, period = true, stochastic = true, treatNullsAsZeros = true, useAutoPeriod = true, useExistingData = true, useModelPeriod = true, transform = new MsFormulaTransformPattern() { additionalAttributes = true, calculationDirection = true, calculationType = true, displayId = true, displaySettings = true, formulaCount = true, outputs = ListOperation.Get, series = ListOperation.Get, kind = true, formulas = new TsFormulaPattern() { method = new TsMethodPattern() { series = true } }, equationsFormula = new TsFormulaPattern() { method = new TsMethodPattern() { } }, transformVariable = new MsFormulaTransformVariablePattern() { slices = ListOperation.Get, transformSlice = new MsFormulaTransformSlicePattern() { selection = ListOperation.Get } } } } } } } } }, // Set equation calculation parameters execParams = new MsMdExecParams() { k = 0, execMethod = true, execEvaluateSeries = true, scenarioKeys = new long[] { }, modelKeys = new long[] { (long)eqKey } } }; // Create a proxy object for operation calculation var somClient = new SomPortTypeClient(); GetMsResult getMsResult = somClient.GetMs(getMsOp); MsMetaModel meta = getMsResult.meta.item.problemMd.metamodel; MsCalculationChainEntry chainEntry = meta.calculationChain.its.GetValue(0) as MsCalculationChainEntry; // Display errors and warnings MsModel eq = chainEntry.model; if (eq.warnings != null) { Console.WriteLine("-- Warnings --"); Console.WriteLine("".PadRight(3) + printArray(eq.warnings)); } if (eq.error == null) //Check if errors occurred on equation calculation { // Equation is calculated without errors // Get calculation results TsFormula formula = eq.transform.formulas.its.GetValue(0) as TsFormula; TsHodrickPrescottFilterMethod hpf = formula.method.hodrickPrescottFilter; // Get smoothing parameter value and display into console window Console.WriteLine("-- Smoothing parameter --"); Console.WriteLine(hpf.smSmoothingParameter); // Get calculated values and display into console window MsEvaluateSeriesResult seriesRes = formula.method.evaluateSeries; printSeries(seriesRes); } else // Errors occurred on equation calculation { Console.WriteLine("-- Errors --"); Console.WriteLine(eq.error); } // Return the model that contains equation return chainEntry; }
See also:
GetMs: Operation | Hodrick-Prescott Filter