Command language

The Gekko command language takes advantage of the timeseries-oriented nature of Gekko. You can perform general programming tasks in the command language, but using it for timeseries data management or modeling show its particular forte.

See the list of all features, or read more about language and programming below.

Short-list of all main Gekko features
  • Seasonal correction via X12A.
  • Graphics by means of embedded gnuplot.
  • User-defined functions and procedures.
  • Dynamically loaded and compiled models, including failsafe mode.

Timeseries databanks are often organized using some naming patterns/schemes. For instance, the timeseries may use the pattern K{%i}{%j} to state the type {%i} and sector {%j} of capital stocks, for instance Kma, Kmo, Kba, Kbo, where the capital types are ‘m’ and ‘b’, and the sectors are ‘a’ and ‘o’. Looping over and handling such name patterns is central in Gekko, for instance:

FOR %i = m, b;
  FOR %j = a, b;
    K{%i}{%j} <2015 2020> = K{%i}{%j}[-1];

This loops over the types ‘m’ and ‘b’, combined with the sectors ‘a’ and ‘o’. Inside the loop, the capital stock is set equal to the lagged capital stock, that is, the capital stock in the previous time period, effectively telling Gekko to use the values in 2014 for the period 2015-2020. The loop is equivalent to:

Kma <2015 2020> = Kma[-1];
Kmo <2015 2020> = Kmo[-1];
Kba <2015 2020> = Kba[-1];
Kbo <2015 2020> = Kbo[-1];

These four K-timeseries might be reside in a Gekko databank, or alternatively as rows or columns in a spreadsheet or .csv file or some other file format. Central to Gekko is the idea that a string (a sequence of letters inclosed in hyphens, for instance ‘Kma’) can be used either as the string itself (the collection of these particular letters and symbols), or to refer to a timeseries. This might not sound like such a big deal, but in practice it helps to keep the Gekko syntax simple and compact.

In some languages, accessing timeseries like K{%i}{%j} above would have to be done using some function syntax, for instance something like get(“K” + i + j, t) or get(“K”, i, j, t), where t is the time period. Even the lag might not be straightforward, if the frequency is not annual, so that you would have to use a lag() function, for instance get(“K” + i + j, lag(t, -1)) instead of K{%i}{%j}[-1]. This is just an example, but if the software language is for instance matrix-oriented, timeseries manipulations quickly end up being quite verbose and unnatural.