Site Overlay

Financial time series in gnuplot

Ever tried to produce this with Excel?
Ever tried to produce this with Excel?

If financial companies talk about “research”, this should be taken with a grain of salt: “Research” sounds like science – but the truth normally is that research bulletins are some kind of marketing hodge podge, where charts on spreads, z-scores, risk reversals are churned out so that the slick sales guys have something at hand to talk their clients into new transactions.

As in most other industries, these charts are generated using Microsoft Excel. What I regularly ask myself is: If we already know that most of these charts are pointless – can we at least produce them with a software which offers a better result than Excel? The good news is we can. Have a look at gnuplot. It is open source, free of charge and the most versatile tool to visualize data I have ever seen.

General

For any kind of chart, gnuplot needs two input files with plain text:

  • The first file holds the data of the time series itself. By convention, it has the extension .dat (e.g. USDEUR.dat).
  • The second file holds the settings for the chart (e.g. input data, chart type, line color, axis labels etc.). By convention, it has the extension .plt (e.g. USDEUR.plt).

The data file

Imagine we want to plot the 6M EUR EURIBOR fixings from 2009-2011. A typical data file might look like this:

2Jan09	2.945
5Jan09	2.913
6Jan09	2.882
7Jan09	2.845
8Jan09	2.811
9Jan09	2.765
12Jan09	2.716
13Jan09	2.671
14Jan09	2.631
15Jan09	2.572
16Jan09	2.531
19Jan09	2.487
20Jan09	2.447
21Jan09	2.39
22Jan09	2.341
23Jan09	2.294
26Jan09	2.252
27Jan09	2.239
28Jan09	2.214
29Jan09	2.194
30Jan09	2.176
2Feb09	2.162
3Feb09	2.153
4Feb09	2.143
5Feb09	2.127
6Feb09	2.108
9Feb09	2.086
10Feb09	2.069
11Feb09	2.054
12Feb09	2.036
13Feb09	2.025
16Feb09	2.013
17Feb09	1.997
18Feb09	1.986
19Feb09	1.982
20Feb09	1.976
23Feb09	1.975
24Feb09	1.963
25Feb09	1.951
26Feb09	1.942
27Feb09	1.933
2Mar09	1.919
3Mar09	1.899
4Mar09	1.884
5Mar09	1.869
6Mar09	1.842
9Mar09	1.825
10Mar09	1.817
11Mar09	1.8
12Mar09	1.79
13Mar09	1.78
16Mar09	1.774
17Mar09	1.763
18Mar09	1.752
19Mar09	1.734
20Mar09	1.723
23Mar09	1.712
24Mar09	1.709
25Mar09	1.705
26Mar09	1.7
27Mar09	1.693
30Mar09	1.68
31Mar09	1.67
1Apr09	1.656
2Apr09	1.646
3Apr09	1.653
6Apr09	1.644
7Apr09	1.632
8Apr09	1.624
9Apr09	1.618
14Apr09	1.609
15Apr09	1.602
16Apr09	1.597
17Apr09	1.595
20Apr09	1.599
21Apr09	1.6
22Apr09	1.6
23Apr09	1.6
24Apr09	1.593
27Apr09	1.588
28Apr09	1.579
29Apr09	1.569
30Apr09	1.562
4May09	1.553
5May09	1.543
6May09	1.534
7May09	1.527
8May09	1.507
11May09	1.491
12May09	1.486
13May09	1.479
14May09	1.465
15May09	1.453
18May09	1.442
19May09	1.434
20May09	1.443
21May09	1.451
22May09	1.457
25May09	1.464
26May09	1.467
27May09	1.471
28May09	1.473
29May09	1.465
1Jun09	1.464
2Jun09	1.461
3Jun09	1.455
4Jun09	1.457
5Jun09	1.468
8Jun09	1.487
9Jun09	1.49
10Jun09	1.488
11Jun09	1.484
12Jun09	1.478
15Jun09	1.472
16Jun09	1.465
17Jun09	1.457
18Jun09	1.449
19Jun09	1.438
22Jun09	1.428
23Jun09	1.416
24Jun09	1.404
25Jun09	1.354
26Jun09	1.334
29Jun09	1.322
30Jun09	1.313
1Jul09	1.303
2Jul09	1.291
3Jul09	1.277
6Jul09	1.268
7Jul09	1.261
8Jul09	1.249
9Jul09	1.241
10Jul09	1.236
13Jul09	1.229
14Jul09	1.225
15Jul09	1.22
16Jul09	1.214
17Jul09	1.202
20Jul09	1.194
21Jul09	1.188
22Jul09	1.182
23Jul09	1.175
24Jul09	1.17
27Jul09	1.168
28Jul09	1.159
29Jul09	1.153
30Jul09	1.149
31Jul09	1.142
3Aug09	1.137
4Aug09	1.134
5Aug09	1.133
6Aug09	1.132
7Aug09	1.131
10Aug09	1.133
11Aug09	1.13
12Aug09	1.128
13Aug09	1.121
14Aug09	1.12
17Aug09	1.114
18Aug09	1.113
19Aug09	1.111
20Aug09	1.111
21Aug09	1.107
24Aug09	1.106
25Aug09	1.101
26Aug09	1.099
27Aug09	1.093
28Aug09	1.088
31Aug09	1.082
1Sep09	1.08
2Sep09	1.078
3Sep09	1.076
4Sep09	1.069
7Sep09	1.065
8Sep09	1.055
9Sep09	1.05
10Sep09	1.046
11Sep09	1.04
14Sep09	1.04
15Sep09	1.04
16Sep09	1.038
17Sep09	1.039
18Sep09	1.035
21Sep09	1.031
22Sep09	1.029
23Sep09	1.026
24Sep09	1.021
25Sep09	1.02
28Sep09	1.018
29Sep09	1.018
30Sep09	1.016
1Oct09	1.017
2Oct09	1.016
5Oct09	1.013
6Oct09	1.01
7Oct09	1.01
8Oct09	1.016
9Oct09	1.021
12Oct09	1.023
13Oct09	1.024
14Oct09	1.022
15Oct09	1.022
16Oct09	1.022
19Oct09	1.022
20Oct09	1.021
21Oct09	1.022
22Oct09	1.021
23Oct09	1.019
26Oct09	1.017
27Oct09	1.013
28Oct09	1.008
29Oct09	1.004
30Oct09	1.004
2Nov09	1.004
3Nov09	1.001
4Nov09	1.002
5Nov09	1
6Nov09	0.997
9Nov09	0.994
10Nov09	0.992
11Nov09	0.992
12Nov09	0.991
13Nov09	0.989
16Nov09	0.988
17Nov09	0.988
18Nov09	0.987
19Nov09	0.987
20Nov09	0.987
23Nov09	0.991
24Nov09	0.991
25Nov09	0.993
26Nov09	0.994
27Nov09	0.993
30Nov09	0.995
1Dec09	0.997
2Dec09	0.998
3Dec09	0.999
4Dec09	0.996
7Dec09	0.998
8Dec09	0.996
9Dec09	0.996
10Dec09	0.997
11Dec09	0.996
14Dec09	0.999
15Dec09	0.998
16Dec09	0.998
17Dec09	0.997
18Dec09	0.995
21Dec09	0.995
22Dec09	0.993
23Dec09	0.992
24Dec09	0.991
28Dec09	0.992
29Dec09	0.993
30Dec09	0.993
31Dec09	0.994
4Jan10	0.996
5Jan10	0.995
6Jan10	0.992
7Jan10	0.989
8Jan10	0.986
11Jan10	0.985
12Jan10	0.983
13Jan10	0.981
14Jan10	0.981
15Jan10	0.977
18Jan10	0.975
19Jan10	0.974
20Jan10	0.972
21Jan10	0.968
22Jan10	0.966
25Jan10	0.965
26Jan10	0.964
27Jan10	0.964
28Jan10	0.966
29Jan10	0.966
1Feb10	0.966
2Feb10	0.967
3Feb10	0.967
4Feb10	0.967
5Feb10	0.965
8Feb10	0.965
9Feb10	0.966
10Feb10	0.966
11Feb10	0.966
12Feb10	0.967
15Feb10	0.963
16Feb10	0.964
17Feb10	0.965
18Feb10	0.963
19Feb10	0.965
22Feb10	0.965
23Feb10	0.964
24Feb10	0.963
25Feb10	0.959
26Feb10	0.958
1Mar10	0.959
2Mar10	0.958
3Mar10	0.957
4Mar10	0.957
5Mar10	0.956
8Mar10	0.957
9Mar10	0.956
10Mar10	0.956
11Mar10	0.957
12Mar10	0.958
15Mar10	0.956
16Mar10	0.955
17Mar10	0.951
18Mar10	0.951
19Mar10	0.951
22Mar10	0.95
23Mar10	0.948
24Mar10	0.947
25Mar10	0.946
26Mar10	0.947
29Mar10	0.945
30Mar10	0.944
31Mar10	0.944
1Apr10	0.945
6Apr10	0.949
7Apr10	0.95
8Apr10	0.952
9Apr10	0.952
12Apr10	0.953
13Apr10	0.953
14Apr10	0.954
15Apr10	0.954
16Apr10	0.954
19Apr10	0.953
20Apr10	0.953
21Apr10	0.954
22Apr10	0.955
23Apr10	0.957
26Apr10	0.959
27Apr10	0.958
28Apr10	0.964
29Apr10	0.967
30Apr10	0.968
3May10	0.971
4May10	0.974
5May10	0.976
6May10	0.978
7May10	0.984
10May10	0.981
11May10	0.979
12May10	0.978
13May10	0.976
14May10	0.979
17May10	0.981
18May10	0.982
19May10	0.984
20May10	0.986
21May10	0.987
24May10	0.987
25May10	0.99
26May10	0.989
27May10	0.988
28May10	0.988
31May10	0.989
1Jun10	0.991
2Jun10	0.994
3Jun10	0.996
4Jun10	0.997
7Jun10	0.998
8Jun10	0.999
9Jun10	0.999
10Jun10	1.001
11Jun10	1.003
14Jun10	1.005
15Jun10	1.006
16Jun10	1.008
17Jun10	1.011
18Jun10	1.015
21Jun10	1.019
22Jun10	1.021
23Jun10	1.024
24Jun10	1.027
25Jun10	1.03
28Jun10	1.035
29Jun10	1.039
30Jun10	1.041
1Jul10	1.056
2Jul10	1.06
5Jul10	1.06
6Jul10	1.061
7Jul10	1.065
8Jul10	1.07
9Jul10	1.081
12Jul10	1.086
13Jul10	1.09
14Jul10	1.095
15Jul10	1.101
16Jul10	1.114
19Jul10	1.122
20Jul10	1.127
21Jul10	1.13
22Jul10	1.131
23Jul10	1.133
26Jul10	1.137
27Jul10	1.141
28Jul10	1.143
29Jul10	1.145
30Jul10	1.145
2Aug10	1.145
3Aug10	1.146
4Aug10	1.149
5Aug10	1.152
6Aug10	1.154
9Aug10	1.155
10Aug10	1.156
11Aug10	1.158
12Aug10	1.154
13Aug10	1.153
16Aug10	1.15
17Aug10	1.149
18Aug10	1.149
19Aug10	1.148
20Aug10	1.145
23Aug10	1.143
24Aug10	1.141
25Aug10	1.139
26Aug10	1.139
27Aug10	1.139
30Aug10	1.137
31Aug10	1.137
1Sep10	1.134
2Sep10	1.134
3Sep10	1.134
6Sep10	1.133
7Sep10	1.133
8Sep10	1.134
9Sep10	1.134
10Sep10	1.135
13Sep10	1.138
14Sep10	1.137
15Sep10	1.139
16Sep10	1.139
17Sep10	1.141
20Sep10	1.139
21Sep10	1.139
22Sep10	1.138
23Sep10	1.136
24Sep10	1.137
27Sep10	1.138
28Sep10	1.141
29Sep10	1.141
30Sep10	1.146
1Oct10	1.184
4Oct10	1.191
5Oct10	1.191
6Oct10	1.19
7Oct10	1.197
8Oct10	1.201
11Oct10	1.204
12Oct10	1.206
13Oct10	1.209
14Oct10	1.211
15Oct10	1.216
18Oct10	1.223
19Oct10	1.231
20Oct10	1.239
21Oct10	1.246
22Oct10	1.25
25Oct10	1.253
26Oct10	1.259
27Oct10	1.265
28Oct10	1.267
29Oct10	1.269
1Nov10	1.269
2Nov10	1.27
3Nov10	1.272
4Nov10	1.274
5Nov10	1.273
8Nov10	1.274
9Nov10	1.274
10Nov10	1.274
11Nov10	1.275
12Nov10	1.276
15Nov10	1.276
16Nov10	1.275
17Nov10	1.272
18Nov10	1.269
19Nov10	1.266
22Nov10	1.265
23Nov10	1.263
24Nov10	1.26
25Nov10	1.262
26Nov10	1.26
29Nov10	1.26
30Nov10	1.26
1Dec10	1.258
2Dec10	1.258
3Dec10	1.256
6Dec10	1.256
7Dec10	1.258
8Dec10	1.259
9Dec10	1.259
10Dec10	1.257
13Dec10	1.257
14Dec10	1.254
15Dec10	1.254
16Dec10	1.254
17Dec10	1.254
20Dec10	1.254
21Dec10	1.253
22Dec10	1.253
23Dec10	1.248
24Dec10	1.243
27Dec10	1.241
28Dec10	1.24
29Dec10	1.238
30Dec10	1.234
31Dec10	1.227
3Jan11	1.224
4Jan11	1.224
5Jan11	1.223
6Jan11	1.223
7Jan11	1.223
10Jan11	1.222
11Jan11	1.222
12Jan11	1.225
13Jan11	1.229
14Jan11	1.244
17Jan11	1.249
18Jan11	1.254
19Jan11	1.256
20Jan11	1.26
21Jan11	1.27
24Jan11	1.277
25Jan11	1.279
26Jan11	1.294
27Jan11	1.301
28Jan11	1.307
31Jan11	1.319
1Feb11	1.331
2Feb11	1.333
3Feb11	1.34
4Feb11	1.341
7Feb11	1.339
8Feb11	1.336
9Feb11	1.35
10Feb11	1.354
11Feb11	1.355
14Feb11	1.354
15Feb11	1.353
16Feb11	1.352
17Feb11	1.352
18Feb11	1.348
21Feb11	1.353
22Feb11	1.36
23Feb11	1.367
24Feb11	1.371
25Feb11	1.377
28Feb11	1.379
1Mar11	1.382
2Mar11	1.381
3Mar11	1.385
4Mar11	1.475
7Mar11	1.487
8Mar11	1.493
9Mar11	1.494
10Mar11	1.491
11Mar11	1.489
14Mar11	1.487
15Mar11	1.474
16Mar11	1.477
17Mar11	1.478
18Mar11	1.479
21Mar11	1.488
22Mar11	1.496
23Mar11	1.501
24Mar11	1.506
25Mar11	1.513
28Mar11	1.521
29Mar11	1.531
30Mar11	1.541
31Mar11	1.546
1Apr11	1.556
4Apr11	1.563
5Apr11	1.568
6Apr11	1.576
7Apr11	1.585
8Apr11	1.599
11Apr11	1.612
12Apr11	1.621
13Apr11	1.626
14Apr11	1.629
15Apr11	1.631
18Apr11	1.635
19Apr11	1.639
20Apr11	1.649
21Apr11	1.655
26Apr11	1.657
27Apr11	1.661
28Apr11	1.669
29Apr11	1.675
2May11	1.682
3May11	1.688
4May11	1.7
5May11	1.713
6May11	1.703
9May11	1.705
10May11	1.706
11May11	1.701
12May11	1.699
13May11	1.703
16May11	1.707
17May11	1.71
18May11	1.713
19May11	1.717
20May11	1.72
23May11	1.716
24May11	1.716
25May11	1.714
26May11	1.712
27May11	1.708
30May11	1.705
31May11	1.712
1Jun11	1.714
2Jun11	1.714
3Jun11	1.716
6Jun11	1.719
7Jun11	1.724
8Jun11	1.733
9Jun11	1.741
10Jun11	1.739
13Jun11	1.739
14Jun11	1.741
15Jun11	1.748
16Jun11	1.752
17Jun11	1.759
20Jun11	1.764
21Jun11	1.77
22Jun11	1.772
23Jun11	1.771
24Jun11	1.769
27Jun11	1.764
28Jun11	1.77
29Jun11	1.777
30Jun11	1.788
1Jul11	1.797
4Jul11	1.803
5Jul11	1.81
6Jul11	1.814
7Jul11	1.823
8Jul11	1.831
11Jul11	1.831
12Jul11	1.818
13Jul11	1.818
14Jul11	1.817
15Jul11	1.814
18Jul11	1.812
19Jul11	1.813
20Jul11	1.81
21Jul11	1.817
22Jul11	1.824
25Jul11	1.827
26Jul11	1.831
27Jul11	1.828
28Jul11	1.824
29Jul11	1.821
1Aug11	1.82
2Aug11	1.816
3Aug11	1.812
4Aug11	1.812
5Aug11	1.764
8Aug11	1.76
9Aug11	1.745
10Aug11	1.741
11Aug11	1.726
12Aug11	1.73
15Aug11	1.74
16Aug11	1.741
17Aug11	1.74
18Aug11	1.737
19Aug11	1.73
22Aug11	1.734
23Aug11	1.739
24Aug11	1.743
25Aug11	1.745
26Aug11	1.744
29Aug11	1.745
30Aug11	1.747
31Aug11	1.749
1Sep11	1.748
2Sep11	1.744
5Sep11	1.734
6Sep11	1.732
7Sep11	1.731
8Sep11	1.732
9Sep11	1.728
12Sep11	1.723
13Sep11	1.724
14Sep11	1.729
15Sep11	1.734
16Sep11	1.736
19Sep11	1.735
20Sep11	1.737
21Sep11	1.736
22Sep11	1.734
23Sep11	1.735
26Sep11	1.732
27Sep11	1.738
28Sep11	1.746
29Sep11	1.75
30Sep11	1.753
3Oct11	1.757
4Oct11	1.756
5Oct11	1.758
6Oct11	1.755
7Oct11	1.765
10Oct11	1.768
11Oct11	1.771
12Oct11	1.774
13Oct11	1.775
14Oct11	1.777
17Oct11	1.782
18Oct11	1.78
19Oct11	1.783
20Oct11	1.785
21Oct11	1.785
24Oct11	1.785
25Oct11	1.788
26Oct11	1.785
27Oct11	1.788
28Oct11	1.793
31Oct11	1.788
1Nov11	1.782
2Nov11	1.78
3Nov11	1.776
4Nov11	1.701
7Nov11	1.695
8Nov11	1.692
9Nov11	1.691
10Nov11	1.689
11Nov11	1.688
14Nov11	1.685
15Nov11	1.685
16Nov11	1.686
17Nov11	1.69
18Nov11	1.694
21Nov11	1.694
22Nov11	1.695
23Nov11	1.698
24Nov11	1.702
25Nov11	1.705
28Nov11	1.707
29Nov11	1.706
30Nov11	1.701
1Dec11	1.697
2Dec11	1.699
5Dec11	1.703
6Dec11	1.705
7Dec11	1.703
8Dec11	1.701
9Dec11	1.675
12Dec11	1.675
13Dec11	1.673
14Dec11	1.669
15Dec11	1.667
16Dec11	1.667
19Dec11	1.668
20Dec11	1.667
21Dec11	1.666
22Dec11	1.662
23Dec11	1.658
27Dec11	1.648
28Dec11	1.64
29Dec11	1.625
30Dec11	1.617

Note that the data file

  • has two columns: the first one (in this case) is the date column, the second is the 6M EUR EURIBOR applied to the date
  • the decimal separator is a dot, not a comma
  • there are no headers, if you want these headers for internal description of the file you can add them as a comment on the top line – comments always start with a hash sign (#).
  • columns are space-separated (not comma or semi-colon!)

The settings file

The settings file controls the whole appearance of the chart: What data file is used (or even which parts of a data file), what kind of chart should be produced. A typical settings file for the above example looks like this:

set term pngcairo font "sans,9" size 500,250
set xdata time
set timefmt "%d%b%y"
set xrange ["30Sep08":"30Mar12"]
set format x "%b%y"
set format y "%3.1f"
set ytics nomirror axis
set xtics nomirror axis
set mxtics 6
set mytics 10
set grid ytics lt 0 lw 1 lc rgb "#696969"
set grid xtics lt 0 lw 1 lc rgb "#696969"
unset key
set border 3 lt 1 lc "white"
set object 1 rectangle from screen 0,0 to screen 1,1 fillcolor rgb"#1d1d1d" behind
set tics textcolor rgb "white"
set ylabel '6M EURIBOR Fixing [%]' tc rgb "white"
set style line 1 lc rgb '#ef5a00' lt 1 lw 2 pt 7 pi -1 ps 1.5
set output 'EUR_EURIBOR_6M_SAMPLE.png'
plot 'EUR_EURIBOR_6M_SAMPLE.dat' using 1:2 with lines ls 1

 Producing the plot

All we have to do to generate the plot is to start gnuPlot from the folder containing the data file and the plot file and issue the command load ‘EUR_EURIBOR_6M_SAMPLE.plt’ at the gnuplot command prompt.

Note that gnuplot will then silently create the chart as a PNG file in the background. Just pick the file up and put it on your website or document.

Final chart generated by gnuPlot
Final chart generated by gnuPlot