IMFReader¶
This module provides functionality for reading and processing International Monetary Fund (IMF) data, including banking statistics, national accounts, inflation, and labor market indicators. It handles data from multiple IMF databases including the Financial Access Survey (FAS) and International Financial Statistics (IFS).
Key Features: - Read IMF banking sector demographics - Process national accounts growth rates - Calculate inflation rates from CPI and PPI - Access labor market statistics - Scale data for model compatibility - Handle missing data and country codes
Example
from pathlib import Path
from macro_data.readers.economic_data.imf_reader import IMFReader
from macro_data.configuration.countries import Country
# Initialize reader with data directory and scaling factors
scale_dict = {Country.FRANCE: 1000, Country.GERMANY: 1000}
reader = IMFReader.from_data(
data_path=Path("path/to/imf/data"),
scale_dict=scale_dict
)
# Get banking sector statistics
n_banks = reader.number_of_commercial_banks(2020, "FRA")
deposits = reader.total_commercial_deposits(2020, "FRA")
# Get macroeconomic indicators
inflation = reader.get_inflation("DEU")
growth = reader.get_na_growth_rates("DEU")
labor = reader.get_labour_stats("DEU")
Note
Monetary values are in domestic currency units. Growth rates and ratios are returned as decimals.
IMFReader
¶
A class for reading and processing IMF data across multiple databases.
This class handles: 1. Banking sector statistics (FAS database) 2. National accounts and growth rates (IFS) 3. Price indices and inflation rates 4. Labor market indicators
Parameters¶
data : dict[str, pd.DataFrame] Dictionary containing loaded IMF data by category scale_dict : dict[Country, int] Dictionary mapping countries to scaling factors
Attributes¶
scale_dict : dict[Country, int] Scaling factors for each country data : dict[str, pd.DataFrame] Processed IMF data by category
Notes¶
- Banking data is scaled according to model requirements
- Growth rates and ratios are converted to decimals
- Missing data is handled through optional returns
scale_dict = scale_dict
instance-attribute
¶
data = {key: (data[key])for key in (data.keys())}
instance-attribute
¶
__init__(data: dict[str, pd.DataFrame], scale_dict: dict[Country, int])
¶
from_data(data_path: Path | str, scale_dict: dict[Country, int]) -> IMFReader
classmethod
¶
Create an IMFReader instance from data files.
Parameters¶
data_path : Path | str Path to directory containing IMF data files scale_dict : dict[Country, int] Dictionary mapping countries to scaling factors
Returns¶
IMFReader Initialized reader with loaded IMF data
Notes¶
- Expects 'imf_fas_bank_demographics.csv' and 'IFS.csv' in data_path
- Files should use latin-1 encoding
get_files_with_codes() -> dict[str, str]
staticmethod
¶
Get mapping of data categories to file names.
Returns¶
dict[str, str] Dictionary mapping data categories to file names
get_value(year: int, country: str, stat: str) -> float
¶
number_of_commercial_banks(year: int, country: str | Country) -> float
¶
number_of_commercial_depositors(year: int, country: str | Country) -> float
¶
number_of_commercial_borrowers(year: int, country: str | Country) -> float
¶
total_commercial_deposits(year: int, country: str | Country) -> float
¶
total_commercial_loans(year: int, country: str | Country) -> float
¶
get_inflation(country: Country | str) -> Optional[pd.DataFrame]
¶
Get inflation rates from CPI and PPI for a country.
Parameters¶
country : Country | str Country identifier
Returns¶
Optional[pd.DataFrame] DataFrame with CPI and PPI inflation rates, or None if data not available
Notes¶
- Returns quarterly data
- Uses PPI if CPI not available and vice versa
- Returns None for Argentina (uses central bank data instead)
- Rates are returned as decimals
get_na_growth_rates(country: str | Country) -> pd.DataFrame
¶
Get national accounts growth rates for a country.
This method calculates growth rates for various national accounts components: - GDP and its components - Consumption (household, NPISH, government) - Investment (fixed capital, inventories) - Trade (exports and imports of goods and services)
Parameters¶
country : str | Country Country identifier
Returns¶
pd.DataFrame DataFrame with growth rates for each component
Notes¶
- Returns quarterly data
- Uses seasonally adjusted data when available
- Growth rates are returned as decimals
- Combines household and NPISH consumption
get_labour_stats(country: str | Country) -> Optional[pd.DataFrame]
¶
Get labor market statistics for a country.
Parameters¶
country : str | Country Country identifier
Returns¶
Optional[pd.DataFrame] DataFrame with labor market indicators: - Labor force size - Employment numbers - Unemployment numbers and rate Returns None if data not available
Notes¶
- Returns quarterly data
- Unemployment rate is converted to decimal