Terms of Trade
Get the terms of trade of a variety of countries: the prices a country receives for its exports relative to the prices it pays for its imports, how many imports a unit of exports buys.
Rising terms of trade raise a country’s real income without any change in what it produces: an oil exporter gains when oil prices rise, an energy importer such as the euro area loses, as in 2022. They move the current account and, for commodity exporters, the exchange rate.
The formula is as follows:
\[\text{Terms of Trade} = \frac{\text{Export Price Index}}{\text{Import Price Index}} \cdot 100\]The export and import price indices are those of get_export_price_index and get_import_price_index, monthly from each country’s official publisher: Eurostat for the euro area, the European Union and around 35 European countries (industrial producer prices on the non-domestic market over the import prices of industrial products, both 2021 = 100), the Bureau of Labor Statistics for the United States (the export and import price indices of all commodities, 2000 = 100; the last three years without a FRED API key) and the Bank of Japan for Japan (in yen, 2020 = 100). Both indices of a country have the same base year, so the terms of trade are 100 in that year; they cover goods (for Eurostat industrial goods), not services. The indices are not seasonally adjusted, which matters little for their ratio. Quarterly and yearly values are the ratio of the averages of the months, for complete periods only.
See definition: imf.org
Also known as: terms of trade index, TOT, export to import price ratio, net barter terms of trade.
Example · Euro Area, Germany, Spain, Japan · 2021 to 2025
Install the Finance Toolkit with pip install financetoolkit -U, then call get_terms_of_trade:
from financetoolkit import Economics
economics = Economics(start_date='2021-01-01', end_date='2025-12-31')
economics.get_terms_of_trade(
countries=['Euro Area', 'Germany', 'Spain', 'Japan'], period='yearly'
)
Or, with the Finance Toolkit MCP set up, ask an AI assistant such as Claude or ChatGPT:
How did the terms of trade of the euro area, Germany, Spain and Japan develop each year from 2021 to 2025?
Which returns:
| Item | Euro Area | Germany | Spain | Japan |
|---|---|---|---|---|
| 2021 | 99.9833 | 100.0000 | 100.0080 | 89.0671 |
| 2022 | 93.6775 | 92.9962 | 93.4469 | 74.4419 |
| 2023 | 99.7690 | 100.3810 | 96.8774 | 81.2096 |
| 2024 | 101.5800 | 102.1550 | 97.3472 | 84.6061 |
| 2025 | 102.8090 | 103.8350 | 98.9871 | 87.7770 |
5 rows
Parameters
get_terms_of_trade accepts the following parameters.
| Parameter | Type | Description | Example |
|---|---|---|---|
countries | list[str] | str | None | The countries to include in the data. Defaults to None. | ["United States", "Germany"] |
period | str | None | The frequency of the data. Options are: “monthly” (monthly data), “quarterly” (quarterly data), “yearly” (yearly data). Defaults to None, which is quarterly when the Economics class was initialized with quarterly=True and monthly otherwise. | "weekly" |
rolling | int | The rolling window size to use for smoothing the data (simple moving average). Defaults to None. | 4 |
trailing | int | The trailing window size to use for summing the data over trailing periods. Defaults to None. | 4 |
transform | str | list[str] | None | Time series steps applied in order, such as “sma:12” (moving average), “ema:12”, “std:12”, “zscore:60”, “percentile:120”, “yoy”, “pct_change:3,annualize:3”, “log”, “diff”, “cumsum” or “hp_trend” and “hp_cycle” (Hodrick-Prescott). They run before growth and the date range, on the history fetched with it: at least two years of monthly and three years of quarterly data before the start date, so a longer window needs an earlier start_date. Defaults to None. | None |
growth | bool | Whether to return the growth data or the actual data. Defaults to False. | True |
lag | int | The number of periods to lag the data by. Defaults to 1. | 4 |
standardize | bool | Whether to standardize (Z-Score) the result. When combined with growth=True, standardizes the growth values instead of the raw values. Defaults to False. | True |
rounding | int | None | The number of decimals to round the results to. Defaults to None, which uses the rounding of the Economics class. | 2 |
show_columns | str | list[str] | None | The columns to keep, a name or a list of names, matched on every column level, or the rows when no column has those names (such as the line items of a financial statement). Names that do not exist are logged, and when none exist the result is returned in full. Defaults to None, which keeps every column. | None, which keeps every column |
References
- Paper International Monetary Fund (2009). Export and Import Price Index Manual: Theory and Practice. Chapter 18, “Terms of Trade and Real Gross Domestic Income”.
- Source Eurostat, Producer prices in industry, non-domestic market, monthly data (sts_inppnd_m)
- Source FRED (Federal Reserve Bank of St. Louis), Export price index, United States (IQ)
- Source U.S. Bureau of Labor Statistics, Export price index, United States (EIUIQ)
- Source Bank of Japan, Corporate Goods Price Index, export price index (PR01, PRCG20_2400000000)
- Source Eurostat, Import prices in industry, monthly data (sts_inpi_m)
- Source FRED (Federal Reserve Bank of St. Louis), Import price index, United States (IR)
- Source U.S. Bureau of Labor Statistics, Import price index, United States (EIUIR)
- Source Bank of Japan, Corporate Goods Price Index, import price index (PR01, PRCG20_2600000000)