Gekko 2.4 to 3.x cheat sheet

<< Click to Display Table of Contents >>

Navigation:  Appendix >

Gekko 2.4 to 3.x cheat sheet

Previous pageReturn to chapter overviewNext page

The following "cheat sheet" shows syntax differences between Gekko 2.4 and 3.x, focusing on some of the most oft-used parts of Gekko 2.4. Regarding 3.x syntax, the short elevator pitch is a useful read, and besides there is the guide. Among other thinds, the syntax changes in 3.x have to do with (a) how the symbols % and # are interpreted, (b) databanks now contain all kinds of variables not just series, and (c) lists now contain all kinds of variables not just strings (more on this here). Beware that "2.4" covers all versions 2.x.x. A two-page printing-ready pdf version of the cheat sheet is available here.

 

Gekko 2.4 to 3.x cheat sheet

Series

Gekko 2.4

Gekko 3.x

definition
local period
blanks separation
dynamic series

element access
name-composition
name-composition

list of names
 
operators
operators
operators

 

frequency symbol

series x = 1, 2, m, 3;
series <2020 2021> y = x;
series x = 1 2 m 3;
series x = x[-1] + 1;
series y[2021] = x[2020];
series y{i}= x{i}b;
series y%i|= x%i|b;
series #= 100;
 
series y ^ 5; series y % 5;
series y + 5; series y +$ 5;
series y * 5; series y # 5;
 
collapse x.= x.q;

= 1, 2, m(), 3;
<2020 2021> = x;
= data('1 2 m 3');
<dyn> = x[-1] + 1;
y[2021] = x[2020];
y{%i}= x{%i}b;
y%i|= x%i|b;
{#m} = 100;
 
^= 5; y %= 5;
+= 5; y <keep=p> += 5;
*= 5; y #= 5;
 
collapse x!= x!q;

Lists

Gekko 2.4

Gekko 3.x

list of strings

singleton list

'funny' strings

mix strings and lists

 

listfile f.lst out

listfile f.lst in

 

union

intersection

difference

concatenate

 

prefix (and suffix)

remove element text

sort/trim

 

element access

print list elements

print series

list m1 = a, b, c;

list m1 = a;
list <direct> m2 = 007, 7z;
list m3 = x, #m1, y, #m2;
 
list listfile f = a, b, c;
list m = #(listfile f);
 
list m3 = #m1 &+ #m2;
list m3 = #m1 &* #m2;
list m3 = #m1 &- #m2;
list m3 = #m1, #m2;
 
list m = #m2 prefix = 'p'; 

list m = #m2 strip = 'z';
list m = #m2 sort trim;
 
string s = #m3[2];
list ? #m;
prt #m;

#m1 = a, b, c;

#m1 = a,;
#m2 = 007, 7z;
#m3 = x, {#m1}, y, {#m2};
 
#(listfile f) = a, b, c;
#= #(listfile f);
 
#m3 = #m1 || #m2;
#m3 = #m1 && #m2;
#m3 = #m1 - #m2;
#m3 = #m1 + #m2;
 
#= #m2.prefix('p');
#= #m2.replaceinside('z', '');
#= #m2.sort().unique();
 
%= #m3[2];
prt #m;
prt {#m};

Scalars

Gekko 2.4

Gekko 3.x

value definition

date definition

string definition

string concatenate

print string

print series

val v = 1.23;
date d = 2021q1;
string s = 'xy5';

string s2 = 'a' + %+ 'b';
string ? %s;
prt {%s};

%= 1.23;
%= 2021q1;
%= 'xy5';

%s2 = 'a{%s}b'; //or like 2.4
prt %s;
prt {%s};

Wildcards

Gekko 2.4

Gekko 3.x

index with wildcard

index with range

search inside databank

search inside list

print matching series

index x* m;
index a..d m;
list m2 = [x*], [a..d];
list m2 = #m1[x*], #m1[a..d];
prt [x*], [a..d];

index x* to #m;
index a..d to #m;
#m2 = ['x*'] + ['a'..'d'];
#m2 = #m1['x*'] + #m1['a'..'d'];
prt {'x*'}, {'a'..'d'};

Loops

Gekko 2.4

Gekko 3.x

date loop
value loop
string loop

for date d = %d1 to %d2; ...
for val i = %i1 to %i2; ... 
for s = #m; ... 

for date %= %d1 to %d2; ...
for val %= %i1 to %i2; ... 
for string %= #m; ... 

Matrix

Gekko 2.4

Gekko 3.x

matrix definition

element access

print matrix

print matrix 

matrix m = [1, 2 || 3, 4];
matrix m[1, 2] = #m[2, 1];
matrix ? #m;
show #* #m;

#= [1, 2; 3, 4];
#m[1, 2] = #m[2, 1];
prt #m;
prt #* #m;

Miscellaneous

Gekko 2.4

Gekko 3.x

import for all periods

export for all periods

use {} for path parts
use {} for sum

value to survive read

list to survive read

import <csv> data;
export <csv> data;
read c:\gekko\%path\data;
series y = sum(#m);
val v = 1.23;
list m1 = a, b, c;

import <csv all> data;
export <csv all> data;
read c:\gekko\{%path}\data;
= sum({#m});
global:%= 1.23;
global:#m1 = a, b, c;

Model/sim example

Gekko 2.4

Gekko 3.x

The model/sim syntax is very similar. In 3.x, lists and scalars that must survive read statements must be placed in the Global databank. Series operators include a "=" symbol. And you must use more {}-curlies when referring to scalars and lists.

reset; 
mode sim;
list fx = fxnx, fxqx;
string path = 'c:\models';
model %path\model2;
read bank2;
time 2021 2025;
sim;
clone;
series tg + 0.01;
sim;
mulprt #fx;
read bank2;
endo tg;
exo fy;
sim;
mulprt tg, fy, #fx;

reset; 
mode sim;
global:#fx = fxnx, fxqx;
global:%path = 'c:\models';
model {%path}\model2;
read bank2;
time 2021 2025;
sim;
clone;
tg += 0.01;
sim;
mulprt {#fx};
read bank2;
endo tg;
exo fy;
sim;
mulprt tg, fy, {#fx};

About {}-curlies in Gekko 3.x

In Gekko 3.x, it is more often required to enclose a string %s or a list of strings #m in curlies, that is, {%s} or {#m}. This applies to the following statements: assignments, analyze, checkoff, collapse, compare, copy, disp, doc, endo, exo, export, findmissingdata, import, interpolate, itershow, ols, prt/mulprt/plot/sheet, read, rebase, rename, smooth, splice, truncate, write, x12a, where assignments refer to series/scalar/list etc. statements. Consider this difference:

 

  delete {%s}, {#m}; 

  delete %s, #m;

 

If the string %s contains 'x1' and the list #m contains the strings 'x2', 'x3', 'x4', the first statement deletes the series x1, x2, x3, x4 (4 in all). In the next statement, it is the string and list objects %s and #m themselves that are deleted (2 in all). Understanding this conceptual difference is important!