Types and operators

Basic types

fdm defines the following basic types

Character

A character e.g. 'a' or s[ 1 ] where s is a string. Characters are inside single quotes

c = '1';

When adding a number to a character, it will format the number as a string and treat the character as a string and concatenate the two. When combined with a number or matrix for example, a character’s numerical value is used in stead. So

print( 10 + 'a' );

will print

+10.0000a

and

print( 10 * 'a' );

will print

+970.0000

String

A string is defined using double quotes

s = "abc";

A character or substring can be extracted as follows

s = "abc";
c = s[ 1 ];          # Now c = 'a'
t = s[ 1:2 ];        # Now t = "ab"

Note that strings are indexed from 1.

There are a number of string functions listed in the function manual.

Number

fdm does not distinguish between integers and floating point values. Numbers are stored as is up to arbitrary precision. Numbers can be entered in the usual way or using scientific notation. As with programming languages such as C or C++, numbers must be entered using a decimal point, not comma, separator.

a = 10;
a = 0.123;
a = 123e456;
a = 123.456e789;

There are lots of mathematical and other functions documented in the function manual.

Data series

A data series is an array with numbered observations or values inside. The indexing depends on the frequency, but for all frequencies, series can be treated using numerical indices.

series = observe( dateIndex( 2020, 1, 1 ), 1, 2, 3, 4 );

This will create a series with 4 observations 1, 2, 3, 4 and with the index of the first one equal to the calculation’s frequency’s index for 1 January 2020. To extract values, use

series[ dateIndex( 2020, 2, 1 ) ]

for example.

Series are the staple of fdm. They can be combined and operator on in many ways e.g.

realGDP = GDP / CPI;
lGDP = ln( GDP );
GAP = GDP / POT - 1;

Functions work on series as well and will typically operate on each element, so

sin( A )

will return a new series where each observation is the sin of the observation of the original series. There are also a number of functions specifically for series, such as corr for correlation or average as documented in the function manual.

Matrix

fdm also supports matrices. To enter one, do it as follows

A = matrix( 3, 2, 1, 1, 2, 2, 3, 3 );

This will create a matrix with 3 rows and 2 columns. The first row will contain 1, the second row 2 and the last row 3.

A = matrix( 10, 10 );

will create a 10x10 matrix containing zeroes everywhere, while

A = matrix( 10, 10, 1, 2, 3 );

will create a 10x10 matrix with 1, 2 and 3 in the first row’s first, second and third column and zeroes everywhere else.

To extract a specific element, do

aij = A[ i; j ];
a23 = A[ 2; 3 ];

and to extract a range use a colon

col = A[ 1:4; 2 ];        # Column matrix
sub = A[ 1:4; 2:3 ];      # 4x2 matrix

Note that matrices are indexed from 1.

There are numerous matrix functions documented in the function manual.