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:

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:

 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