Country API Reference¶
This section documents the country-level aggregation and parameter management in the macromodel package.
Country Module¶
macromodel.country.country.Country
¶
A complete national economy with interacting agents and markets.
This class represents a single country's economy, integrating all economic agents (individuals, households, firms, banks, government) and markets (labor, credit, housing, goods). It manages their interactions and evolution over time.
The economy operates in discrete timesteps, with each iteration: 1. Updating exchange rates and monetary conditions 2. Running agent-level planning and decision-making 3. Clearing all markets sequentially 4. Recording economic outcomes and updating metrics
The timestep length is configurable (typically quarterly) and determined by how the input data is preprocessed (see ICIOReader's yearly_factor parameter).
Attributes:
| Name | Type | Description |
|---|---|---|
country_name |
str
|
Identifier for the country |
scale |
int
|
Scaling factor for population-based calculations |
individuals |
Individuals
|
Population of individual economic agents |
households |
Households
|
Collection of household units |
firms |
Firms
|
Collection of producing firms |
central_government |
CentralGovernment
|
Fiscal authority |
government_entities |
GovernmentEntities
|
Public sector bodies |
banks |
Banks
|
Commercial banking sector |
central_bank |
CentralBank
|
Monetary authority |
economy |
Economy
|
Aggregate economic metrics and tracking |
labour_market |
LabourMarket
|
Employment matching and wage setting |
credit_market |
CreditMarket
|
Lending and borrowing |
housing_market |
HousingMarket
|
Property sales and rentals |
exchange_rate_usd_to_lcu |
float
|
Exchange rate to USD |
exogenous |
Exogenous
|
External economic conditions |
forecasting_window |
int
|
Periods ahead for forecasting |
assume_zero_growth |
bool
|
Whether to assume no growth |
assume_zero_noise |
bool
|
Whether to assume no random shocks |
configuration |
CountryConfiguration
|
Model parameters |
from_pickled_country(synthetic_country: SyntheticCountry, country_configuration: CountryConfiguration, exchange_rates: ExchangeRates, country_name: str, all_country_names: list[str], industries: list[str], initial_year: int, t_max: int, running_multiple_countries: bool, emission_factors_usd: np.ndarray) -> Country
classmethod
¶
Create a Country instance from preprocessed synthetic data.
This factory method constructs a complete country economy from preprocessed data, initializing all agents and markets with calibrated starting conditions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
synthetic_country
|
SyntheticCountry
|
Preprocessed country data |
required |
country_configuration
|
CountryConfiguration
|
Model parameters |
required |
exchange_rates
|
ExchangeRates
|
Exchange rate dynamics |
required |
country_name
|
str
|
Country identifier |
required |
all_country_names
|
list[str]
|
All countries in simulation |
required |
industries
|
list[str]
|
Industry sectors |
required |
initial_year
|
int
|
Starting year |
required |
t_max
|
int
|
Maximum simulation periods |
required |
running_multiple_countries
|
bool
|
If True, part of multi-country sim |
required |
emission_factors_usd
|
ndarray
|
Emission factors in USD |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Country |
Country
|
Initialized country economy |
reset(configuration: CountryConfiguration) -> None
¶
Reset the country economy to its initial state.
Resets all agents, markets, and state variables to their initial conditions, optionally with new configuration parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
configuration
|
CountryConfiguration
|
New model parameters |
required |
initialisation_phase(exchange_rate_usd_to_lcu: float) -> None
¶
Initialize the monthly economic cycle.
Sets up the initial conditions for the current timestep, including exchange rates and firm counts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
exchange_rate_usd_to_lcu
|
float
|
Current exchange rate to USD |
required |
estimation_phase() -> None
¶
Run economic forecasting and estimation.
Updates agent expectations about growth, inflation, and other key economic variables used in decision-making.
update_planning_metrics() -> None
¶
Update forward-looking economic indicators.
Computes expected profits, asset values, benefits, and other metrics used by agents in their planning decisions.
update_realised_metrics() -> None
¶
Update realized economic outcomes after market clearing.
This method coordinates the comprehensive updating of all economic metrics after markets have cleared. It processes the results of market interactions and computes derived economic indicators across eight major categories:
- Economic Indicators:
- Price indices (PPI, CPI)
- Economic growth rates
- House price indices
- Labor market metrics (employment, unemployment)
-
Rental market aggregates
-
Global Trade and Capital Formation:
- International trade flows
- Import/export tracking
- Gross fixed capital formation
-
Input costs (intermediate and capital)
-
Firm Production and Costs:
- Production volumes and nominal values
- Wages and labor costs
- Inventory management
- Input utilization
-
Emissions (if enabled)
-
Firm Financial Metrics:
- Sales and revenue
- Profits and taxes
- Corporate financial positions
- Insolvency metrics
-
Debt aggregates
-
Individual and Household Income:
- Employment income
- Social transfers
- Financial asset income
- Rental income
-
Total household income
-
Household Wealth and Consumption:
- Consumption patterns
- Investment decisions
- Wealth positions
- Debt management
-
Insolvency handling
-
Government and Banking:
- Tax collection
- Government revenue and deficit
- Bank profits and equity
- Interest payments
-
Market share metrics
-
GDP and National Accounts:
- GDP components
- Value added
- National income
- Sectoral balances
The method ensures consistency between micro-level agent behaviors and macro-level economic outcomes, maintaining stock-flow consistency throughout the economy.
Note
This method should be called after all markets (goods, labor, credit, housing) have cleared and agents have executed their planned transactions.
Side Effects
Updates numerous time series variables across all economic agents and markets, reflecting the realized outcomes of the current period's economic activity.
update_population_structure() -> None
¶
Update demographic composition.
Applies demographic changes (aging, retirement, etc.) to the population of individual agents.
get_goods_market_participants() -> list[Agent | RestOfTheWorld]
¶
Get all participants in the goods market.
Returns:
| Type | Description |
|---|---|
list[Agent | RestOfTheWorld]
|
list[Agent | RestOfTheWorld]: List of agents participating in goods market transactions |
save_to_h5(h5_file: h5py.File) -> None
¶
Save complete country state to HDF5.
Saves the full state of all agents, markets, and economic variables to an HDF5 file for later analysis or continuation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
h5_file
|
File
|
Open HDF5 file to save to |
required |
shallow_output() -> pd.DataFrame
¶
Create summary DataFrame of key economic indicators.
Returns:
| Type | Description |
|---|---|
DataFrame
|
pd.DataFrame: DataFrame containing main economic metrics (GDP, inflation, unemployment, etc.) |