SyntheticRestOfTheWorld¶
The SyntheticRestOfTheWorld class is an abstract base class that manages data related to the Rest of the World (ROW) agent, which represents all countries not explicitly simulated in the model.
Core Functionality¶
The class handles:
-
Trade Relationships:
- Aggregating exports to non-simulated countries
- Tracking imports from non-simulated countries
- Managing international price levels
- Handling exchange rate effects
-
Data Aggregation:
- Combining economic data from non-simulated countries
- Scaling trade flows appropriately
- Preserving global trade balance
- Maintaining consistent units
-
Growth Modeling:
- Processing historical growth patterns
- Estimating export/import trends
- Handling structural changes
- Projecting future relationships
-
Market Structure:
- Determining number of trading agents
- Allocating market shares
- Setting initial conditions
- Preserving key relationships
Key Attributes¶
country_name: Always "ROW" for this classyear: Reference year for the datarow_data: Main DataFrame containing ROW economic dataexports_model: Model for export growth trendsimports_model: Model for import growth trendsn_exporters_by_industry: Number of exporting agents by industryn_importers: Number of importing agents
Data Structure¶
The ROW data is organized in a DataFrame with columns:
- Exports: Value of exports to simulated countries
- Imports in USD: Value of imports from simulated countries in USD
- Imports in LCU: Value of imports in local currency units
- Price in USD: Price levels in USD
- Price in LCU: Price levels in local currency units
Implementation¶
Module for preprocessing Rest of the World (ROW) data in macroeconomic simulations.
This module provides the abstract base class for managing data related to the Rest of the World (ROW) agent, which represents all countries not explicitly simulated in the model. The ROW agent is crucial for:
- Trade Relationships:
- Aggregating exports to non-simulated countries
- Tracking imports from non-simulated countries
- Managing international price levels
-
Handling exchange rate effects
-
Data Aggregation:
- Combining economic data from non-simulated countries
- Scaling trade flows appropriately
- Preserving global trade balance
-
Maintaining consistent units
-
Growth Modeling:
- Processing historical growth patterns
- Estimating export/import trends
- Handling structural changes
-
Projecting future relationships
-
Market Structure:
- Determining number of trading agents
- Allocating market shares
- Setting initial conditions
- Preserving key relationships
Note
This module focuses on preprocessing and organizing ROW data for initialization. The actual trade dynamics are implemented in the simulation package.
Example
SyntheticRestOfTheWorld
¶
Abstract base class for Rest of the World (ROW) data preprocessing.
This class provides the framework for managing data related to countries not explicitly simulated in the model. It handles: 1. Trade data aggregation and scaling 2. Price level and exchange rate processing 3. Export/import relationship modeling 4. Market structure initialization
The ROW data is organized in a DataFrame with columns
- Exports: Value of exports to simulated countries
- Imports in USD: Value of imports from simulated countries in USD
- Imports in LCU: Value of imports in local currency units
- Price in USD: Price levels in USD
- Price in LCU: Price levels in local currency units
Attributes:
| Name | Type | Description |
|---|---|---|
country_name |
str
|
Always "ROW" for this class |
year |
int
|
Reference year for the data |
row_data |
DataFrame
|
Aggregated economic data for non-simulated countries |
exports_model |
Optional[LinearRegression]
|
Model for export growth trends |
imports_model |
Optional[LinearRegression]
|
Model for import growth trends |
n_exporters_by_industry |
ndarray
|
Number of exporting agents by industry |
n_importers |
int
|
Number of importing agents |
country_name = 'ROW'
instance-attribute
¶
year = year
instance-attribute
¶
row_data = row_data
instance-attribute
¶
exports_model = exports_model
instance-attribute
¶
imports_model = imports_model
instance-attribute
¶
n_exporters_by_industry = n_exporters_by_industry
instance-attribute
¶
n_importers = n_importers
instance-attribute
¶
__init__(year: int, row_data: pd.DataFrame, n_exporters_by_industry: np.ndarray, n_importers: int, exports_model: Optional[LinearRegression], imports_model: Optional[LinearRegression])
abstractmethod
¶
Initialize the Rest of the World agent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
year
|
int
|
Reference year for the data |
required |
row_data
|
DataFrame
|
Aggregated economic data for ROW |
required |
n_exporters_by_industry
|
ndarray
|
Number of exporting agents by industry |
required |
n_importers
|
int
|
Number of importing agents |
required |
exports_model
|
Optional[LinearRegression]
|
Model for export growth |
required |
imports_model
|
Optional[LinearRegression]
|
Model for import growth |
required |
DefaultSyntheticRestOfTheWorld¶
DefaultSyntheticRestOfTheWorld is a concrete implementation of SyntheticRestOfTheWorld that provides standard preprocessing of ROW data using common data sources.
Data Source Integration¶
The class integrates data from multiple sources:
- Trade flow data
- Exchange rate information
- Industry-level statistics
- Historical growth patterns
Initial State Processing¶
The class processes:
- Trade data aggregation
- Currency conversion
- Market structure initialization
- Growth model fitting
Parameter Estimation¶
Key parameters estimated include:
- Export growth models
- Import growth models
- Exporter counts by industry
- Importer numbers
Factory Methods¶
The class provides a factory method from_readers that creates a DefaultSyntheticRestOfTheWorld instance by:
- Reading and processing data from various sources
- Converting currencies using exchange rates
- Fitting growth models if configured
- Initializing market structure
- Setting up initial conditions
Implementation¶
Default implementation of Rest of the World (ROW) data preprocessing.
This module provides the standard implementation for managing Rest of the World data, focusing on:
- Data Integration:
- Reading from standard data sources
- Converting between currencies
- Aggregating trade flows
-
Computing market shares
-
Market Structure:
- Determining exporter counts
- Scaling importer numbers
- Preserving trade relationships
-
Initializing agent distributions
-
Growth Modeling:
- Fitting export growth models
- Estimating import trends
- Processing historical patterns
-
Handling missing data
-
Configuration Options:
- Flexible exporter allocation
- Configurable growth modeling
- Currency conversion handling
- Market structure settings
Note
This implementation provides reasonable defaults for ROW preprocessing, suitable for most standard simulation scenarios. Custom implementations can extend this class for specific requirements.
Example
from macro_data.readers import DataReaders
from macro_data.configuration import ROWDataConfiguration
readers = DataReaders(...)
config = ROWDataConfiguration(...)
row = DefaultSyntheticRestOfTheWorld.from_readers(
year=2023,
readers=readers,
industry_data=industry_data,
n_sellers_by_industry=sellers,
n_buyers=buyers,
row_configuration=config
)
DefaultSyntheticRestOfTheWorld
¶
Default implementation of Rest of the World data preprocessing.
This class provides a standard implementation for ROW data management with: 1. Automated data reading and currency conversion 2. Flexible market structure initialization 3. Configurable growth model fitting 4. Trade flow aggregation and scaling
The implementation supports: - Optional growth model fitting for exports/imports - Configurable exporter allocation by industry - Automatic scaling of importer numbers - Currency conversion handling
__init__(year: int, row_data: pd.DataFrame, n_exporters_by_industry: np.ndarray, n_importers, exports_model: Optional[LinearRegression], imports_model: Optional[LinearRegression])
¶
Initialize the default ROW implementation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
year
|
int
|
Reference year for the data |
required |
row_data
|
DataFrame
|
Aggregated economic data for ROW |
required |
n_exporters_by_industry
|
ndarray
|
Number of exporting agents by industry |
required |
n_importers
|
int
|
Number of importing agents |
required |
exports_model
|
Optional[LinearRegression]
|
Model for export growth |
required |
imports_model
|
Optional[LinearRegression]
|
Model for import growth |
required |
from_readers(year: int, readers: DataReaders, industry_data: dict[str, dict[str, pd.DataFrame]], n_sellers_by_industry: np.ndarray, n_buyers: int, row_configuration: ROWDataConfiguration, row_exports_growth: Optional[pd.Series] = None, row_imports_growth: Optional[pd.Series] = None)
classmethod
¶
Create a ROW instance from data readers and configuration.
This method: 1. Aggregates trade data for non-simulated countries 2. Converts currencies using exchange rates 3. Fits growth models if configured 4. Initializes market structure
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
year
|
int
|
Reference year for the data |
required |
readers
|
DataReaders
|
Data source readers |
required |
industry_data
|
dict[str, dict[str, DataFrame]]
|
Industry data by country |
required |
n_sellers_by_industry
|
ndarray
|
Number of sellers by industry in simulated countries |
required |
n_buyers
|
int
|
Number of buyers in simulated countries |
required |
row_configuration
|
ROWDataConfiguration
|
Configuration settings for ROW |
required |
row_exports_growth
|
Optional[Series]
|
Historical export growth data. Required if fit_exports is True. |
None
|
row_imports_growth
|
Optional[Series]
|
Historical import growth data. Required if fit_imports is True. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
DefaultSyntheticRestOfTheWorld |
Initialized ROW instance |
Raises:
| Type | Description |
|---|---|
ValueError
|
If growth data is required but not provided |