SA_Demetra_Example

advertisement
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
Document1
2.
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.Component
Type.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.Reg
ression.IOutlierVariable>().ItemsCount;
Document1
3.
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.Component
Type.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.Reg
ression.IOutlierVariable>().ItemsCount;
Document1
Download