iode.Simulation.model_exchange

Simulation.model_exchange(self, list_exo: str | List[str] = None)

Set a list of endogenous-exogenous pairs for goal seeking. For each pair, the status of the variables is exchanged: endogenous becomes exogenous and vice versa. This enables the model to be run through known endogenous values and to deduce the necessary values for the associated exogenous variables. The exogenous variables take on the value calculated over the entire workspace period.

Parameters:
list_exostr or list(str)

List of endogenous-exogenous pairs. Each pair must be written as endogenous_name-exogenous_name. If the passed list is empty, the internal list of endogenous-exogenous pairs is reset. Default to None (empty).

Examples

>>> from iode import SAMPLE_DATA_DIR, equations, identities, scalars, variables 
>>> from iode import Simulation
>>> equations.load(f"{SAMPLE_DATA_DIR}/fun.eqs")
>>> identities.load(f"{SAMPLE_DATA_DIR}/fun.idt")
>>> scalars.load(f"{SAMPLE_DATA_DIR}/fun.scl")
>>> variables.load(f"{SAMPLE_DATA_DIR}/fun.var")
>>> equations["UY"].lec
'UY := NATY-NDOMY-NIY-NGY-(EFXY-EFMY)-NFY'
>>> identities["XNATY"]
'grt NATY'
>>> # endogenous variable
>>> variables["XNATY", "2000Y1:2015Y1"]     
[0.22, 0.699999988079071, 0.4, 0.7, ..., -0.20000000298023224, -0.20000000298023224]
>>> # reset exogeneous variable
>>> variables["UY", "2000Y1:2015Y1"] = 0.0
>>> variables["UY", "2000Y1:2015Y1"]    
[0.0, 0.0, ..., 0.0, 0.0]
>>> simu = Simulation()
>>> simu.model_simulate("2000Y1", "2015Y1")
>>> # endogenous variable (unchanged)
>>> variables["XNATY", "2000Y1:2015Y1"]     
[0.22, 0.699999988079071, 0.4, 0.7, ..., -0.20000000298023224, -0.20000000298023224]
>>> # exogeneous variable
>>> variables["UY", "2000Y1:2015Y1"]         
[624.1781881798956, 645.0542977503601, 661.6074127102179, ..., 525.1258272992568]
>>> # exchange UY and XNATY
>>> simu.model_exchange("UY-XNATY")
>>> # update endogenous variable (now UY)
>>> variables["UY", "2000Y1:2002Y1"] = [630.0, 650.0, 670.0]
>>> # rerun simulation
>>> simu.model_simulate("2000Y1", "2015Y1")
>>> # exogeneous variable (now XNATY)
>>> variables["XNATY", "2000Y1:2015Y1"]     
[0.3508274950028535, 0.6702440874066322, 0.5092369210188463, ..., -0.19926923081414763]