Get the Trade Balance for a variety of countries over time from the Global Macro Database (GMDB). The Trade Balance is the difference between the total value of goods and services a country exports and the total value of goods and services it imports. A positive trade balance (a “trade surplus”) means a country exports more than it imports, while a negative trade balance (a “trade deficit”) means a country imports more than it exports.

The formula is as follows:

\[\text{Trade Balance} = \text{Exports of Goods and Services} - \text{Imports of Goods and Services},\;\; \text{both the Global Macro Database's figures in millions of national currency (or of US dollars when usd=True)}\]

The balance is annual and expressed in millions of national currency, with a negative value marking a trade deficit and a positive value a surplus.

Data comes from the Global Macro Database (GMDB), further information about the variable can be found within https://www.globalmacrodata.com/documentation.html

Also known as: net exports, balance of trade.

Trade Balance in Python or via the MCP

Install the Finance Toolkit with:

pip install financetoolkit -U

Then call get_trade_balance as shown below.

from financetoolkit import Economics

economics = Economics(start_date='2020-01-01', end_date='2023-01-01')

economics.get_trade_balance(countries=['United States', 'Germany', 'China'])

Or, after setting up the Finance Toolkit MCP, ask:

How large were the trade balances of the United States, Germany and China, in national currency, from 2020 to 2023?

Which returns:

  United States Germany China
2020 -618554 181408 2.57979e+06
2021 -849233 185685 3.04482e+06
2022 -937889 96043 3.97949e+06
2023 -786495 167684 2.79265e+06

Parameters

get_trade_balance accepts the following parameters.

ParameterTypeDescriptionExample
countrieslist[str] | str | NoneA list of countries or a single country to include in the results. Defaults to None.["United States", "Germany"]
usdboolWhether to return the values in millions of US dollars, converted by the Global Macro Database, instead of millions of national currency, which makes levels comparable across countries. Defaults to False.True
rollingintThe rolling window size to use for smoothing the data (simple moving average). Defaults to None.4
trailingintThe trailing window size to use for summing the data over trailing periods (e.g. a trailing-4-quarter sum). Defaults to None.4
growthboolWhether to return the growth data or the actual data. Defaults to False.True
lagintThe number of periods to lag the growth data. Defaults to 1.4
standardizeboolWhether to standardize (Z-Score) the result. When combined with growth=True, standardizes the growth values instead of the raw values. Defaults to False.True
roundingint | NoneThe number of decimals to round the results to. Defaults to None.2
gmdb_forecastsboolWhether to include the years the Global Macro Database projects, from the IMF’s World Economic Outlook, up to five years ahead. Only applies to data from the Global Macro Database. Defaults to False, which ends a series with its last observation.True
Share