gcubed.linearisation.linear_model

This module contains the LinearModel class.

It is used to linearise the model by producing the partial derivative matrices that embody the model dynamics. at a point satisfying the model equations.

class LinearModel(gcubed.base.Base):

Overview

The algebra embodied in this class follows https://www.msgpl.com.au/Manuals2021/GGGv20JManual/softwaremanual/algorithm.pdf

The notation has been extended to also include equations for expected endogenous variables to include exogenous variables.

This class provides the ability to work with the model equations. It:

  1. Computes the partial derivatives of the model equations so that an approximation of the model can be expressed as a set of linear equations.
  2. Constructs the matrices of constants associated with the state-space form of the linearised model. This involves eliminating the endogenous variables from the model via substitution.

To use this class:

  1. instantiate it with a model.
  2. run the __compute_partial_derivatives() method.

Once this sequence of steps has been completed without raising an exception, the matrices associated with the state space form will be accessible as properties of the linear model to support solving the model.

Instantiation determines the values for the RHS variable vectors based upon the model's database and the year that has been chosen to determine the variable values that the model will be linearised around.

These RHS variable vector values, and the implied LHS variable vector values are exposed as properties of the linear model. The names of these vector properties are 3 character acronyms:

The linear model supports evaluation of the model equations to obtain values for the LHS and RHS vectors of variables defined in sym_data.

To understanding the naming conventions, the partial derivatives matrix associated with the partials of x1l with respect to z1r are stored in a property called x1l_z1r_partials. The same naming convention is used for all partials matrices: __partials.

LinearModel( model: gcubed.model.Model, use_neutral_real_interest_rate: bool = True)

Arguments

model: The model that is to be linearised with the linearisation year specified as part of the model configuration.

use_neutral_real_interest_rate: If True, use the neutral real interest rate for the values around which linearisation is done, otherwise use the real interest rate from the database (which may be negative). This parameter defaults to True.

The database containing the values that will be utilised to populate variable values for the linearisation.

linear_model_is_available: bool

True if the model has been linearised successfully and False otherwise (either because linearisation has not finished or linearisation was not possible for whatever reason).

use_neutral_real_interest_rate: bool

This property is checked when doing baseline projections to ensure that baseline projections never start from the neutral real interest rate unless the linearisation was done around the neutral real interest rate.

True if the linearisation used the neutral real interest rate and False otherwise.

equations

The equations subclass instance that implements the functions for each of the nonlinear equations in the model.

model

The model being linearised.

The SYM data for the model being linearised.

The configuration details for the model being linearised.

equations_map: dict[tuple[str, int], list[tuple[str, int]]]

Overview

This is only a public property to assist with unit testing. Do not use it directly for other purposes.

The map is populated from the SYM processor output and is used to make the calculation of partial derivatives more efficient, only calculating those derivatives that are not zero by definition.

Returns

The map from each RHS variable in the model to the list of LHS variables (equations) that depend on it.

def get_vector_by_name(self, vector_name) -> numpy.ndarray:

Overview

Use the name of the vector to retrieve its numpy array value. These values have been set using data in the database.

Arguments

vector_name: The name of the LHS or RHS vector.

Returns

The named column vector.

def get_original_lhs_vector_by_name(self, lhs_vector_name: str) -> numpy.ndarray:

Overview

This function is useful for benchmarking the model's nonlinear equation evaluations.

Use the name of the vector to retrieve its numpy array value. These values have been set by evaluating the model's non-linear equations using the RHS vector values for the base year chosen for the linearisation.

Arguments

lhs_vector_name: The name of the LHS vector, e.g. 'x1l' or 'j1l'.

Returns

The named LHS column vector.

def get_partials(self, lhs_vector_name: str, rhs_vector_name: str) -> numpy.ndarray:

Overview

Use the name of the LHS vector and the RHS vector to retrieve the numpy matrix value for the partial derivatives.

The matrices of partial derivatives are stored in a dictionary indexed by the lhs and rhs vector names.

Arguments

lhs_vector_name: The name of the LHS vector, e.g. 'x1l' or 'j1l'.

rhs_vector_name: The name of the RHS vector, e.g. 'yxr' or 'j1r'.

Returns

The required partial derivatives as a dataframe with variable names as the row and column labels.

def get_partials_as_dataframe( self, lhs_vector_name: str, rhs_vector_name: str) -> pandas.core.frame.DataFrame:

Arguments

lhs_vector_name: The name of the LHS vector, e.g. 'x1l' or 'j1l'.

rhs_vector_name: The name of the RHS vector, e.g. 'yxr' or 'j1r'.

Returns

The required partial derivatives as a dataframe with variable names as the row and column labels.

nonlinear_equation_differences: pandas.core.frame.DataFrame

Details about the differences between the LHS and RHS values for all endogenous variables as at the point of linearisation. This is only used for unit testing purposes.

def select_partial_derivatives( self, lhs_vector_name: str, rhs_vector_name: str, lhs_variable_name_prefix: str = None, rhs_variable_name_prefix: str = None) -> pandas.core.frame.DataFrame:

Overview Retrieve the partial derivatives for the specified LHS vector.

Arguments

lhs_vector_name: The name of the LHS vector, e.g. x1l or j1l.

rhs_vector_name: The name of the RHS vector, e.g. yxr or j1r.

lhs_variable_name_prefix: The prefix to use for the LHS variable names, e.g. PRID(USA. Defaults to None in which case all rows are returned.

rhs_variable_name_prefix: The prefix to use for the RHS variable names, e.g. TCPS(a11,g02,USA. Defaults to None in which case all columns are returned.

Returns

The dataframe with the matched rows and columns of the chosen partial derivatives matrix.

def partial_derivatives_for_given_lhs_variable( self, lhs_variable_name_prefix: str = None) -> pandas.core.frame.DataFrame:

Overview Retrieve the partial derivatives for the specified LHS variables.

Arguments

lhs_variable_name_prefix: The prefix to use for the LHS variable names, e.g. PRID(USA. Defaults to None in which case all rows are returned.

Returns

The dataframe with the partial derivatives for the selected LHS variables.