|
<< Click to Display Table of Contents >> SIM |
![]() ![]()
|
SIM solves a Gekko .frm model (cf. MODEL) for the endogenous value. The solved values are placed in the first-position bank, thereby overwriting previous endogenous variables. The default solving method is Gauss-Seidel. If Gauss-Seidel poses problems, for instance because of bad values in some of the variables, you may try setting option solve failsafe = yes;. For harder problems, you may need to use the Newton method.
Guide: modeling For an introductory guide on modeling, see this page. |
You may solve goals/means by indicating these with the ENDO/EXO statements. The Newton method is used in that case, but please note that you need to use sim<fix> in order for such goals/means to bind. When goals are removed later on (UNFIX statement), the solve method reverts to Gauss-Seidel.
SIM may also solve a model with leaded endogenous variables. The Fair-Taylor ('fair') method is used in that case, or you may use the more powerful Newton-Fair-Taylor (called 'nfair' in Gekko). See the option solve forward method = ....
Gekko will try to calculate some reasonable starting values for the endogenous variables, by means of looking at lagged values regarding these. If you wish to use the current (non-lagged) values as starting values, you should use option solve data init = no;. For static models that are simulated over a single time period, init = no should be used.
sim < period FIX STATIC RES AFTER >;
period |
(Optional). Local period, for instance 2010 2020, 2010q1 2020q4 or %per1 %per2+1. |
AFTER |
sim <after> calculates three kinds of variables: (a) those designated with a formula beginning with Y, (b) all auto-generated variables of J- and Z-type, and (c) all table variables (variables defined after the AFTER; or AFTER$ line in a model file).
Since Y-type variables are typically also J- and Z-variables, one can think of sim <after> as a way to compute all reversed J- and Z-variables independently of the SIM statement (the SIM statement computes these after simulation), in addition to computing table variables. See the MODEL statement for more on J- and Z-variables.
On a well-specified model, reading a historical databank, and issuing a sim <after> statement on the historical period should ideally make it possible to simulate on the historical period and replicate the endogenous variables. |
FIX |
Tells Gekko to enforce any goals/means stated by the ENDO/EXO statements. It is mandatory to use sim <fix> in such cases (if a normal SIM is used, the goals/means are ignored). |
STATIC |
Changes in endogenous variables are not transferred from period to period via lags. See also the option solve static = yes. |
RES |
The sim <res> statement (residual check) performs a one-step-ahead static single-equation simulation of the entire model, i.e. the result of one equation does not affect other equations, nor does results of previous periods affect following periods.
For Gekko models, the left-hand side variables are computed. The difference between actual historical values and a static single equation solutions are the equation residuals. Residuals are used to measure how well the model equations forecasts historically. sim <res> is widely used for testing historical data against the model, or for testing a model against a historical databank. Gekko offers functionality to print results to files for subsequent inspection. See the menu item Utilities --> Check residuals… (output is grouped according to formula codes and/or model sections, and can be ordered).
For GAMS scalar models, there is no strict sense of left-hand and right-hand variables. Therefore, series/array-series are computed with names corresponding to the equation names. You may add a prefix to these names with <prefix = ...>. |
PREFIX= |
(Optional). For a GAMS scalar model, when using for instance sim <res prefix='res_'> will add res_ to the equation names when calculating the residuals. So if an equation name is for instance E_exports(agr, 2027), corresponding to the year 2027, the array-series res_E_exports[agr] will contain that residual. |
•If no period is given inside the <...> angle brackets, the global period is used (cf. TIME).
To increase all the prices p1 and p2 by 1% in 2020-2023, and inspect the effects on production x1 and x2:
time 2020 2023; read baseline; |
The result shows the difference between the values after simulation (first-position bank) and values in the Ref (reference) databank (baseline.gbk) for the variables x1 and x2. Here, it is assumed that baseline already is simulated over the period 2020-23 (otherwise, the second statement could be replaced by read baseline; sim; clone;).
If you need to solve goals/means, you can use the ENDO and EXO statements to change status of exogenous and endogenous variables, and perform a SIM afterwards. In that case, the solve method will be automatically changed to the Newton algorithm (and changed back if the goals/means are removed).
There are many options regarding SIM: please see under OPTION (in the option solve ... section). Or type option solve ?;. A single-equation static simulation can be performed with the sim <res> statement (for instance to check historical residuals).
If you want to change to the Newton algorithm manually, you can use option solve method = newton;. It typically runs a bit slower, but is generally much more robust (and precise). With option newton robust = yes, the Newton method activates a remedy against illegal starting values, like the logarithm to a negative number etc.
Static simulation (one period does not affect the next period) can be obtained by setting option static = yes.
option solve data create auto = no;
option solve data ignoremissing = no;
option solve data init = yes;
option solve data init growth = yes;
option solve data init growth max = 0.06;
option solve data init growth min = -0.02;
option solve failsafe = no;
option solve forward dump = no;
option solve forward fair conv = conv1;
option solve forward fair conv1 abs = 0.001;
option solve forward fair conv1 rel = 0.001;
option solve forward fair conv2 tabs = 1.0;
option solve forward fair conv2 trel = 0.001;
option solve forward fair damp = 0.0;
option solve forward fair itermax = 200;
option solve forward fair itermin = 0;
option solve forward method = fair;
option solve forward nfair conv = conv1;
option solve forward nfair conv1 abs = 0.001;
option solve forward nfair conv1 rel = 0.001;
option solve forward nfair conv2 tabs = 1.0;
option solve forward nfair conv2 trel = 0.001;
option solve forward nfair damp = 0.0;
option solve forward nfair itermax = 200;
option solve forward nfair itermin = 0;
option solve forward nfair updatefreq = 100;
option solve forward terminal = const;
option solve forward terminal feed = internal;
option solve gauss conv = conv1;
option solve gauss conv ignorevars = yes;
option solve gauss conv1 abs = 0.0001;
option solve gauss conv1 rel = 0.0001;
option solve gauss conv2 tabs = 1.0;
option solve gauss conv2 trel = 0.0001;
option solve gauss damp = 0.5;
option solve gauss dump = no;
option solve gauss itermax = 200;
option solve gauss itermin = 10;
option solve gauss reorder = no;
option solve method = gauss;
option solve newton backtrack = yes;
option solve newton conv abs = 0.0001;
option solve newton invert = lu;
option solve newton itermax = 200;
option solve newton robust = no;
option solve newton updatefreq = 15;
option solve print details = no;
option solve print iter = no;
option solve static = no;
CHECKOFF, CLONE, DECOMP, DISP, ENDO, EXO, FIND, ITERSHOW, MODEL, MULPRT, READ, PRT, SERIES, UNFIX, WRITE