Using the .NET Assemblies of Demetra+

Using the .NET Assemblies of Demetra+

1.

Using the .NET assemblies of Demetra+

In this short document, we explain how to use the .NET assemblies of Demetra+ for making seasonal adjustment. The example focuses on the necessary and sufficient steps to use X12 and Tramo-Seats, with default parameters. It is not aimed at exploring all the possibilities of the libraries.

1. Preliminary steps

Referencing the assemblies

For most algorithmic uses, you should only reference "tsscore.dll". That assembly is linked to "log4net.dll".

Copying the native dlls

If you want to make seasonal adjustment (the topic of this example), you need the FORTRAN native libraries that make the actual computing. Those libraries are dynamically loaded by "tsscore.dll"; they MUST be copied manually in the output directory (or in a directory that can be automatically reached by the system). The core engines contain the following libraries (12 dlls):

2. Creation of a time series

The basic object for time series computation is a TSData object, in the namespace "TSToolkit.TimeSeries.SimpleTS.Data".

See below to see how creating such a time series

double[] data =
{
...
};
// parameters of the constructor:
// 1: frequency
// 2: first year
// 3: first period (0-based)
// 4: buffer of data (array of doubles)
// 5: true if the buffer is copied, false if it is used by reference.
TSToolkit.TimeSeries.SimpleTS.Data.TSData ts = new
TSToolkit.TimeSeries.SimpleTS.Data.TSData(12, 1993, 0, data, true);
// other equivalent solution:
// ts = new TSToolkit.TimeSeries.SimpleTS.Data.TSData(12, 1993, 0, data.Length);
// for (int i = 0; i < data.Length; ++i)
// ts[i] = data[i];

3. Calling TramoSeats

The necessary classes for using TramoSeats are contained in the package:

TSToolkit.SeasonalAdjustment.TramoSeats.

The user must create a Specification object and call the Monitor, with the time series and the specifications. He gets a TramoSeatsResults, which contains all the results.

// Creates a clone of one of the default specification (be aware that the name of the spec is case sensitive!)
TSToolkit.SeasonalAdjustment.TramoSeats.Specification spec = TSToolkit.SeasonalAdjustment.TramoSeats.Specification.CreateClone("RSA4");
// Creates the monitor
TSToolkit.SeasonalAdjustment.TramoSeats.Monitor monitor = new TSToolkit.SeasonalAdjustment.TramoSeats.Monitor();
// Process the series. The name of the series could be null (just used for logging)
TSToolkit.SeasonalAdjustment.TramoSeats.TramoSeatsResults results =
monitor.Process(ts, "my series", spec);
// Retrieves information.
// Example 1: the usual decomposition
TSToolkit.TimeSeries.SimpleTS.Data.TSData sa= results.Decomposition.Series(TSToolkit.TimeSeries.SimpleTS.Data.ComponentType.SeasonallyAdjusted,
TSToolkit.TimeSeries.SimpleTS.Data.ComponentInformation.Value);
// Example 2. the outliers count
// A complete description of the output is out of the scope of this introduction
int noutliers = results.PreProcessing.RegArima.X.Select<TSToolkit.TimeSeries.SimpleTS.Regression.IOutlierVariable>().ItemsCount;

3. Calling X12

The use of X12 is nearly identical. The necessary classes are contained in the package:

TSToolkit.SeasonalAdjustment.X12

The user must create a Specification object and call the Monitor, with the time series and the specifications. He gets an X12Results, which contains all the results.

// Creates a clone of one of the default specification (be aware that the name of the spec is case sensitive!)
TSToolkit.SeasonalAdjustment.X12.Specification spec = TSToolkit.SeasonalAdjustment.X12.Specification.CreateClone("RSA4");
// Use constants for safer code:
// spec = TSToolkit.SeasonalAdjustment.X12.Specification.RSA4c;
// or
// spec = TSToolkit.SeasonalAdjustment.X12.Specification.CreateClone(
TSToolkit.SeasonalAdjustment.X12.Specification.N_RSA4);
// Creates the monitor
TSToolkit.SeasonalAdjustment.X12.Monitor monitor = new TSToolkit.SeasonalAdjustment.X12.Monitor();
// Process the series. The name of the series could be null (just used for logging)
TSToolkit.SeasonalAdjustment.X12.X12Results results =
monitor.Process(ts, "my series", spec);
// Retrieves information.
// Example 1: the usual decomposition
TSToolkit.TimeSeries.SimpleTS.Data.TSData sa= results.Decomposition.Series(TSToolkit.TimeSeries.SimpleTS.Data.ComponentType.SeasonallyAdjusted,
TSToolkit.TimeSeries.SimpleTS.Data.ComponentInformation.Value);
// Example 2. the outliers count
// A complete description of the output is out of the scope of this introduction
int noutliers = results.PreProcessing.RegArima.X.Select<TSToolkit.TimeSeries.SimpleTS.Regression.IOutlierVariable>().ItemsCount;

SA_Demetra_Example.docx