Skip to main content

demetrapy

CI

demetrapy provides Python and command-line access to the seasonal-adjustment procedures in JDemetra+. It runs the JDemetra+ X13 and TRAMO/SEATS implementations through JPype; it does not reimplement either procedure in Python.

The package is intended for empirical work in which adjustment specifications must be recorded, repeated, and applied to several series. It accepts regular monthly, quarterly, half-yearly, and yearly observations. Calendar effects, intervention variables, outliers, ARIMA specifications, forecasts, and the principal decomposition options can be set in code or in a JSON file.

Seasonal adjustment is an inferential procedure, not merely a filter applied to a column of numbers. Results depend on the transformation, regression effects, ARIMA model, decomposition method, and span of the sample. Published series should therefore be accompanied by their specification and revision policy. demetrapy exposes JDemetra+ diagnostics and processing messages for this purpose, but it does not decide whether a specification is economically appropriate.

Installation

demetrapy requires Python 3.9 or later and Java 8 or later.

python -m pip install demetrapy

For development from a clone:

python -m venv .venv
source .venv/bin/activate
python -m pip install -e .

The first calculation downloads the pinned demetra-tstoolkit 2.2.6 JAR from Maven Central and stores it in ~/.cache/demetrapy. Set DEMETRAPY_JAR to the path of a local copy when automatic download is not suitable. The Windows guide covers Command Prompt, proxy-restricted, and offline installations.

Python interface

For a pandas object with a regular DatetimeIndex, adjust_dataframe() infers the observation frequency and adjusts each column separately:

import pandas as pd

from demetrapy import adjust_dataframe

data = pd.DataFrame(
	{"production": observations},
	index=pd.date_range("2015-01-01", periods=len(observations), freq="MS"),
)

result = adjust_dataframe(data, method="x13", spec="RSA4")
adjusted = result[("production", "sa")]

The lower-level adjust() function accepts one regular sequence and an explicit starting period:

from demetrapy import adjust

result = adjust(
	values,
	frequency="Quarterly",
	start_year=2005,
	start_period=1,
	method="tramoseats",
	spec="RSA4",
)
adjusted = result["sa"]

By default, both functions return the five compact components used in routine work:

Name Series
y observed series
sa seasonally adjusted series
t trend-cycle
s seasonal component
i irregular component

Set detailed=True when the calculation must retain the full JDemetra+ result dictionary, diagnostics, processing messages, forecasts, backcasts, and fitted ARIMA model:

detailed = adjust(
	values,
	frequency="Monthly",
	start_year=2015,
	forecast_horizon=12,
	detailed=True,
)

print(detailed.arima_model.notation)
forecast = detailed.series["final.sa_f"]

Command line

The command-line interface reads a regular CSV file with date and value columns:

date,value
2019-01-01,101.2
2019-02-01,103.8

The default calculation is monthly X13 with the RSA4 preset:

demetrapy input.csv --output adjusted.csv

A JSON file records a fuller specification:

demetrapy \
  --data input.csv \
  --config examples/full_config.json \
  --output adjusted.csv

The output contains y, sa, t, s, and i, aligned with the input dates. See the usage guide for the complete command-line and Python API.

Specifications and regressors

The package constructs an isolated JDemetra+ processing context for each calculation. Preset defaults remain those of JDemetra+ unless an option is overridden explicitly.

Area Available controls
Methods X13 and TRAMO/SEATS presets
RegARIMA transformation, explicit ARIMA, automatic model selection, estimation controls
Calendar built-in trading days, working days, leap year, Easter, and UserDefined variables
Regression user variables, fixed coefficients, interventions, and ramps
Outliers prespecified and automatic detection
Decomposition X11 filters and limits; SEATS approximation and boundary controls
Output forecasts, backcasts, benchmarking, diagnostics, and processing messages

UserDefined trading-day variables follow the distinction made in the JDemetra+ graphical interface: a calendar pool may contain several registered series while each target selects only the variables relevant to its own equation. The target observations and calendar pool may be supplied as separate DataFrames, provided their frequencies agree and the calendar domain covers the estimation sample.

The configuration reference documents processing order, valid option groups, preset behavior, and result semantics.

Inspection

A static summary plot can be produced from the command line:

demetrapy --data input.csv --plot-output adjustment.png

The local dashboard is included in the standard installation:

demetrapy-dashboard

It accepts observation, configuration, and calendar-pool files and reports the adjusted series together with diagnostics, model information, processing messages, and downloadable results. The dashboard is a convenient inspection tool; it uses the same calculation path as the Python and command-line interfaces.

Examples

Example Subject
automatic_arima_example.py automatic model selection with both methods
explicit_arima_example.py prespecified seasonal ARIMA models
quarterly_example.py quarterly frequency inference and period-four seasonality
compare_methods.py component-wise X13 and TRAMO/SEATS comparison
dataframe_user_variables_example.py multiple targets and a separate calendar pool
full_tramoseats_user_calendar_example.py detailed TRAMO/SEATS specification with UserDefined trading days
RETAIL_CASE_STUDY.md reproducible multi-series case study
dashboard files ready-to-upload dashboard inputs

Reproducibility and compatibility

The compact result schema is versioned, and the supported Python, Java, and JDemetra+ combinations are stated in COMPATIBILITY.md. Tests use both processing engines and include synthetic seasonal and calendar effects with known structure. CI runs on Linux, Windows, and macOS.

python -m unittest discover -s tests

demetrapy is an independent interface to JDemetra+ and is not an official publication of the JDemetra+ project.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

demetrapy-0.1.2.tar.gz (45.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

demetrapy-0.1.2-py3-none-any.whl (39.4 kB view details)

Uploaded Python 3

File details

Details for the file demetrapy-0.1.2.tar.gz.

File metadata

  • Download URL: demetrapy-0.1.2.tar.gz
  • Upload date:
  • Size: 45.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.11.13

File hashes

Hashes for demetrapy-0.1.2.tar.gz
Algorithm Hash digest
SHA256 4610d58a5b17b52df8f2936c4392067bf46e9ef903cb56783bb06800da0b2ca1
MD5 1c27df6ce5fec5ead5ab384c51ae3fcb
BLAKE2b-256 967cb577509dbbb541ee9c162520b05be89637ef427224ea960eb6822ae1c46e

See more details on using hashes here.

File details

Details for the file demetrapy-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: demetrapy-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 39.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.11.13

File hashes

Hashes for demetrapy-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 003e4385eedff2a85111a1bc22269827869b1d40172ebd65d09b634f48f6ce24
MD5 638311e78a425ebc3093e89c17b5c1bc
BLAKE2b-256 219b22ed1ec8e550a1ccebf218db0461661224fa352b403f1098d197cacfacde

See more details on using hashes here.

Release history Release notifications | RSS feed

0.3.2

2 files

0.3.1

2 files

0.3.0

2 files

0.2.2

2 files

0.2.1

2 files

0.2.0

2 files

0.1.5

2 files

0.1.4

2 files

0.1.3

2 files

This release

0.1.2 This release

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page