gcubed.model_parameters.parameters

This module contains the classes that are responsible for loading and calibrating model parameters.

class Parameters(gcubed.base.Base):

Overview

This is the base class for all Parameter calibration classes.

It manages loading, calculation and provision of model parameters.

Parameters are stored as a dictionary of data frames, keyed by parameter name and with the dataframe being the grid of parameter values associated with that parameter name, as specified in the file of user-specified parameter values.

Note that the keys in this dictionary match the parameter names in the list of parameter names read in from the varmap file generated by SYM processing. When populating the vector of parameter values, each dataframe in parameters needs to be vectorised by stacking the transposed rows of the dataframe.

Subclasses add or modify various parameter calibration methods. Each model version and build combination has its own associated subclass of the Parameters class.

Setting up the model's parameter calibration class

The python directory for the model version and build must contain a file called parameters_<VERSION>_<BUILD>.py. <VERSION> and <BUILD> are the version and build of the model respectively.

That file must contain a class called Parameters<VERSION>BUILD>.

The custom parameter class must be a subclass of the Parameters class.

Parameters(database: gcubed.data.database.Database, base_year: int)

Overview

Base class for parameter loading and calibration.

Arguments

database: The model database.

base_year: The base year to use for the database when doing parameter calibration.

def validate(self):

Run from subclass initialisation after the subclass initialisation has completed. Raise an exception if the parameter setting information is invalid

calibration_year: int
non_sym_parameter_names

Returns a tuple containing the names of parameters that are assigned values in the user-set parameter values by region but where those parameters are not defined in the SYM model definition.

Carbon coefficients for each region.

has_carbon_coefficients: bool

True if carbon coefficients are available and False otherwise.

Emissions coefficients for each region.

has_emissions_coefficients: bool

True if emissions coefficients are available and False otherwise.

all_parameters: dict[str, pandas.core.frame.DataFrame]

A dictionary of all parameters, keyed by parameter name. Each parameter is represented by a dataframe of parameter values.

def parameter(self, parameter_name: str) -> pandas.core.frame.DataFrame:

Arguments

parameter_name: The name of the parameter to return.

Returns

The value of the named parameter.

Exceptions

Raise an exception if the parameter is not available.

def has_parameter(self, parameter_name: str) -> bool:

Arguments

parameter_name: The name of the parameter to return.

Returns

True if the parameter is available and False otherwise.

parameter_values: pandas.core.frame.DataFrame

The vectorised parameter values in SYM model order as a data frame indexed by the full parameter name.

parameter_values_vector: numpy.ndarray

Used when evaluating the model equations for linearisation.

discrate: pandas.core.frame.DataFrame

Discount rates by region

TCAX: pandas.core.frame.DataFrame

The TCAX parameter values are 1 for regions where the TCAX (unit tax on carbon) is to be used for the region and 0 if it is not to be used for the region. This feeds into the stable manifold calculation.

EMZT: pandas.core.frame.DataFrame

The EMZT parameter values are 1 for regions where the EMZT (carbon emissions) is to be used for the region and 0 if it is not to be used for the region. This feeds into the stable manifold calculation.

def set_carbon_coefficients(self):

Overview

Set the carbon coefficient values

We are setting values for a column vector: CCfinal=zeros(((numsecstd)numenercountopt),1); There is a row for each energy good for each standard sector for each region.

CCfinal is a vectorised version of the CCstacked matrix, stacking the first column then the second column etc through to the last column of CCstacked.

Each column of CCstacked is the vectorised CC matrix, with column 1 of CC followed by column 2 of CC etc.

The CC matrix is the matrix of carbon coefficients for a given region.

Set the values of co2coef and co2coeffd

def set_emissions_coefficients(self):

Overview

Set the emissions coefficient values.

If the model uses emissions coefficients, then coefficients are required for sectors, for consumers and for government.

Sector input coefficients

For the sectors there is a coefficient for the cartesian product of:

  1. GHG Gas (4 gases CO2, CH4, Flurocarbons, N2O)
  2. Good
  3. Sector
  4. Region

Sector labor coefficients

For the sectors there is a labor-related emission intensity coefficient for the cartesian product of:

  1. GHG Gas (4 gases CO2, CH4, Flurocarbons, N2O)
  2. Sector
  3. Region

Sector capital coefficients

For the sectors there is a capital-related emission intensity coefficient for the cartesian product of:

  1. GHG Gas (4 gases CO2, CH4, Flurocarbons, N2O)
  2. Sector
  3. Region

Sector output coefficients

For the sectors there is a output-related emission intensity coefficient for the cartesian product of:

  1. GHG Gas (4 gases CO2, CH4, Flurocarbons, N2O)
  2. Sector
  3. Region

Household coefficients

For the households there is a coefficient for the cartesian product of:

  1. GHG Gas (4 gases CO2, CH4, Flurocarbons, N2O)
  2. Good
  3. Region

Government coefficients

For the government there is a coefficient for the cartesian product of:

  1. GHG Gas (4 gases CO2, CH4, Flurocarbons, N2O)
  2. Good
  3. Region

The coefficients are grouped by gas then good then region.

def set_a_matrix_parameters(self):

Overview

Calibrate parameters that are used to determine the way regions accumulate their holdings of financial assets in each regional currency.

Mechanical calibration algorithm

Set the following matrices:

  • ashr - The asset split among currencies.
  • aeye - Identity matrix that has the same dimensions as ashr.
  • ainv - Inverse of (aeye - ashr)

Start with ashr, a matrix that has one row for each currency and one column for each owner.

Populate ashr based on the ratio of nominal GDP in each region to nominal GDP in the USA. Specifically:

  1. Get the region-count by 1 column vector that is the value of YRATN(XX) for each region XX in the calibration year. YRATN is the required ratio of nominal GDP in each region to nominal GDP in the USA. Call this column vector yra.
  2. Replicate the yra column vector, once for each region, to create a square matrix and then obtain its lower triangular matrix, (zeroing out the values above the main diagonal). Use the numpy.tril function to get the lower triangular matrix.
  3. Subtract the lower triangular matrix from the original matrix to get zero everywhere except above the main diagonal.
  4. Sum down the rows for each column of this resulting matrix to get the total for each column.
  5. For each column (asset owner), if the column total is above zero, divide all elements in the column by the column total to ensure that the column sums to 1. This will be the case for all columns except the first because all regions have positive GDP.
  6. For the first column, where the column total is zero by construction, set the first element in that column to 1.

Financial asset accumulation of regions

ASSE(currency, owner) is financial assets in each currency including the owner's own currency, valued in that region's own currency.

The model includes rules for how these stocks of financial assets (one stock per denomination currency), evolve for each region.

It is important to track what currency the assets are denominated in because exchange rate movements lead to asset valuation effects.

Each region's stocks of financial assets reflect the history of current account surpluses for that region. Current account surpluses measured in USD, CURR(region), are given by:

CURR(region) = TBAU(region) + PBAL(region) + IRAS(region)

Simplify by ignoring exogenous PBAL for now.

TBAU(region) is the trade surplus for the region, valued in USD.

IRAS(region) is the net income payments to the region from other regions, at the real interest rate (why the real interest rate?), again valued in USD.

Increments to ASSE(currency,owner)

To understand the evolution of ASSE(currency,owner), we need to undestand the increments for each currency, in USD values:

increment(currency, region) = ashr(currency,region) ABUY(region) + aeye(currency, region) (CURR(region) - ABUY(region))

The ashr and aeye matrices are set to ensure that increments are as follows.

The sum of increments, in USD values, across all currencies for a given region, must be equal to the current account surplus for that region, CURR(region).

Each region invests a part of their current account surplus in assets denominated in their own currency, CURR(region)-ABUY(region) and the remainder, ABUY(region), is spread across other currencies.

ABUY(region) is defined as the region's new purchases of foreign assets, denominated in foreign currencies rather than the region's own currency, but all valued in USD.

The spread of ABUY(region) across other currencies is determined by the order of the regions and the relative sizes of the regions.

The order of the regions matters because each region only invests in its assets denominated in its own currency or the currency of regions that come before it in the model's list of regions.

The relative size of the regions matters because the proportion of foreign currency denominated investment that is invested in each foreign currency is the nominal GDP of the region with that currency, divided by the nominal GDP of the other regions with currencies that investments are denominated in.

For example, if Australia is third in the region list, after the USA and Japan, then Australia splits ABUY(AA) between the USA and Japan and the fraction invested in the USA is the nominal GDP of the USA divided by the sum of nominal GDP for the USA and Japan.

All nominal GDP values are converted to USD before comparison.

All nominal GDP values are for the parameter calibration year.

To determine exact increments, the model needs to determine ABUY(region).

Define the set of investible regions for a given region as those regions with currencies that the given region can have foreign assets denominated in. Thus, the USA only has itself as an investible region. Japan has itself and the USA as investible regions.

Define total investible GDP for a given region as the sum of GDP across all all of its investible regions. Thus, for Japan, its total investible GDP is the sum of USA GDP and Japanese GDP.

For all regions except the last region, ABUY(region) is the difference between two parts.

The first part is the region's own current account surplus times one minus its GDP as a fraction of its total investible GDP.

The second part is the sum of the current account surpluses of all investible regions other than the region of interest times its GDP as a fraction of its total investible GDP.

For the last region, ABUY(last region) = CURR(last region) so it invests entirely in foreign currency denominated assets.

ABUY example in model 20J 164

The USA is the USA's only investible region so:

ABUY(USA) = CURR(USA) + CURR(JJ) + CURR(AA) + ... + CURR(PP) = 0

For Japan, if its fraction of investible GDP (across investible regions, USA and Japan) is 0.28, then ABUY(JJ) is given by :

ABUY(JJ) = 0.72 CURR(JJ) - 0.28 CURR(USA)

For Australia, if its fraction of investible GDP (across investible regions,Australia, USA and Japan) is 0.07, then ABUY(AA) is given by :

ABUY(AA) = 0.93 CURR(AA) - 0.07 (CURR(USA) + CURR(JJ))

Across all regions we have:

ABUY(USA) = CURR(USA) + CURR(JJ) + CURR(AA) + ... + CURR(PP) = 0
ABUY(JJ) = 0.72 CURR(JJ) - 0.28 CURR(USA)
ABUY(AA) = 0.93 CURR(AA) - 0.07 (CURR(USA) + CURR(JJ))
ABUY(EE) = 0.54 CURR(EE) - 0.46 ( CURR(USA) + CURR(JJ) + CURR(AA) )
ABUY(OO) = 0.96 CURR(OO) - 0.04 ( CURR(USA) + CURR(JJ) + CURR(AA) + CURR(EE) )
ABUY(CC) = 0.86 CURR(CC) - 0.14 ( CURR(USA) + CURR(JJ) + CURR(AA) + CURR(EE) + CURR(OO) )
ABUY(DD) = 0.97 CURR(DD) - 0.03 ( CURR(USA) + CURR(JJ) + CURR(AA) + CURR(EE) + CURR(OO) + CURR(CC) )
ABUY(LL) = 0.71 CURR(LL) - 0.29 ( CURR(USA) + CURR(JJ) + CURR(AA) + CURR(EE) + CURR(OO) + CURR(CC) + CURR(DD) )
ABUY(BB) = 0.98 CURR(BB) - 0.02 ( CURR(USA) + CURR(JJ) + CURR(AA) + CURR(EE) + CURR(OO) + CURR(CC) + CURR(DD) + CURR(LL) )
ABUY(PP) = CURR(PP)

Foreign asset accumulation with 2 regions

Using model 2R 164, ashr, aeye and ainv imply the following equations:

Value of the assets in each currency for each owner (currency, owner:

ASSE(USA,USA)(t+1) = ASSE(USA,USA)(1-labgrow)+(0*ABUY(USA)+1*(CURR(USA)-ABUY(USA)))/exp(REXN(USA))
ASSE(USA,ROW)(t+1) = ASSE(USA,ROW)(1-labgrow)+(1*ABUY(ROW)+0*(CURR(ROW)-ABUY(ROW)))/exp(REXN(USA))
ASSE(ROW,USA)(t+1) = ASSE(ROW,USA)(1-labgrow)+(0*ABUY(USA)+0*(CURR(USA)-ABUY(USA)))/exp(REXN(ROW))
ASSE(ROW,ROW)(t+1) = ASSE(ROW,ROW)(1-labgrow)+(0*ABUY(ROW)+1*(CURR(ROW)-ABUY(ROW)))/exp(REXN(ROW))

New purchases of foreign assets:

ABUY(USA) = (1*CURR(USA) +1*CURR(ROW)) = 0 # the sum of USD current account balances should be zero.
ABUY(ROW) = (0*CURR(USA) +1*CURR(ROW)) = CURR(ROW)

Doing a substitution back into the ASSE equations and using CURR(USA) = 0 - CURR(ROW):

ASSE(USA,USA)(t+1) = ASSE(USA,USA)(1-labgrow) + CURR(USA)/exp(REXN(USA))
ASSE(USA,ROW)(t+1) = ASSE(USA,ROW)(1-labgrow) + CURR(ROW)/exp(REXN(USA))
ASSE(ROW,USA)(t+1) = ASSE(ROW,USA)(1-labgrow) = 0
ASSE(ROW,ROW)(t+1) = ASSE(ROW,ROW)(1-labgrow) = 0
def set_investment_parameters(self):

Overview

base_jk parameter - base investment (J) divided by capital (K) for the calibration year for each region/standard industry combination:

This corresponds to a matrix formed from elements in each row of data provided in the calibration year database.

def set_cd_parameters(self):

Overview

cd_* parameters are all switches to flip between the Constant Elasticity of Substitution (CES) production function and the Cobb-Douglas production function.

A value of 1 means Cobb-Douglas and 0 means CES.

These parameters are all inferred from the supplied elasticities of substitution. If the elasticities of substitution are close enough to 1 then the elasticity of substitution is effectively set to 1 by working with the Cobb-Douglas function.

def set_delta_parameters(self):

Overview

TODO: Document the definitions of each of these parameters and the economics behind their calibration.

delta_dom delta_e delta_m delta_ff delta_mH - C: consumption column of IO table delta_mR - I: investment column of IO table delta_mG - G: government column of IO table delta_eH - C: consumption column of IO table - energy sectors delta_eR - I: investment column of IO table - energy sectors delta_eG - G: government column of IO table - energy sectors delta_oG - C: consumption column of IO table delta_oH - I: investment column of IO table delta_oR - G: government column of IO table

def set_weight_parameters(self):

prid_weight - Domestic production for each sector in a region. as a fraction of total domestic production across all sectors for that region.

prim_weight - DF imports by good type divided by the value of imports in total at the destination.

prix_weight - Exports by non-electricity generating sector as a fraction of region total exports where exports are measured as a percentage of real GDP for the region.

eer_weight - trade weights, NEER (trade-weighted exch rate, FC/domestic) and REER (trade-weighted real exch rate, FC/domestic)

All of these parameters are set using data from the calibration year.

def set_other_parameters(self):

Overview

transgdp - transfers per unit of GDP - set to 6%.

mongdp - coefficient on money-demanded in the equation for total wealth for a region

makeinv - Supposed to be the Leontief inverse (of the make table) matrix but currently being set up as a matrix of zeros and 1's.

def set_emissions_parameters(self):

This function is intended for gcubed module internal use. It is exposed only for documentation purposes.

Set the values of the emissions parameters. TODO: These parameters need more detailed descriptions in SYM. carcoef - carbon emissions coefficients btucoef - emissions coefficients, energy gwhcoef - gigawatt hours electricity per annum

def insert_parameter( self, parameter_name: str, parameter_value: pandas.core.frame.DataFrame):

Overview

Saves the calibrated parameter values in two forms:

  1. the vectorised set of values for a parameter are stored in the full parameter values vector in the correct elements.
  2. The dataframe of parameter values, with columns corresponding to regions, are stored in a dictionary of all parameters.

The dataframes of parameter values can be helpful when debugging parameter calibration.

Arguments

parameter_name: the name of the parameter. This must be one of the parameters named in the SYM model definition.

parameter_value: the value of the parameter. This must be a dataframe. The dataframe must have the same number of elements (across rows and columns) as the parameter does in the SYM model definition.

Exceptions

Raises an exception if the parameter value is not a dataframe.