Skip to content

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:

  1. Trade Relationships:

    • Aggregating exports to non-simulated countries
    • Tracking imports from non-simulated countries
    • Managing international price levels
    • Handling exchange rate effects
  2. Data Aggregation:

    • Combining economic data from non-simulated countries
    • Scaling trade flows appropriately
    • Preserving global trade balance
    • Maintaining consistent units
  3. Growth Modeling:

    • Processing historical growth patterns
    • Estimating export/import trends
    • Handling structural changes
    • Projecting future relationships
  4. Market Structure:

    • Determining number of trading agents
    • Allocating market shares
    • Setting initial conditions
    • Preserving key relationships

Key Attributes

  • country_name: Always "ROW" for this class
  • year: Reference year for the data
  • row_data: Main DataFrame containing ROW economic data
  • exports_model: Model for export growth trends
  • imports_model: Model for import growth trends
  • n_exporters_by_industry: Number of exporting agents by industry
  • n_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:

  1. Trade Relationships:
  2. Aggregating exports to non-simulated countries
  3. Tracking imports from non-simulated countries
  4. Managing international price levels
  5. Handling exchange rate effects

  6. Data Aggregation:

  7. Combining economic data from non-simulated countries
  8. Scaling trade flows appropriately
  9. Preserving global trade balance
  10. Maintaining consistent units

  11. Growth Modeling:

  12. Processing historical growth patterns
  13. Estimating export/import trends
  14. Handling structural changes
  15. Projecting future relationships

  16. Market Structure:

  17. Determining number of trading agents
  18. Allocating market shares
  19. Setting initial conditions
  20. 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
from macro_data.processing.synthetic_rest_of_the_world import SyntheticRestOfTheWorld

class CustomROW(SyntheticRestOfTheWorld):
    def __init__(self, year, row_data, ...):
        super().__init__(...)
        # Custom initialization logic

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:

  1. Reading and processing data from various sources
  2. Converting currencies using exchange rates
  3. Fitting growth models if configured
  4. Initializing market structure
  5. 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:

  1. Data Integration:
  2. Reading from standard data sources
  3. Converting between currencies
  4. Aggregating trade flows
  5. Computing market shares

  6. Market Structure:

  7. Determining exporter counts
  8. Scaling importer numbers
  9. Preserving trade relationships
  10. Initializing agent distributions

  11. Growth Modeling:

  12. Fitting export growth models
  13. Estimating import trends
  14. Processing historical patterns
  15. Handling missing data

  16. Configuration Options:

  17. Flexible exporter allocation
  18. Configurable growth modeling
  19. Currency conversion handling
  20. 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