*** MOVED ***

NOTE: I have merged the contents of this blog with my web-site. I will not be updating this blog any more.

2007-06-23

Data Visualisation with Gnuplot

Visualisation of data using charts and other types of plots is immensely helpful in getting a feel for it without carrying out detailed analyses. Gnuplot is a freely-available tool for data visualisation that is also very simple to use. The article "Visualize your data with gnuplot" is a nice introduction to this tool. Gnuplot proved to be quite handy for me recently.

I wanted to find out whether the Unit Price of a particular fund varies in line with the popular equity market indices in India, the NSE S&P CNX Nifty and the BSE Sensex. The current values of these indices are always readily available in the newspapers and on television channels, while I have to use the web-site of the fund to get its current Unit Price. If the Unit Price of the fund varied in line with the values of the equity market indices, it would save me some effort in determining its current worth.

The portfolio of the fund in question is almost entirely based on equities. It holds the shares of some of the biggest and the most stable companies across a variety of industry sectors. It was therefore reasonable to suspect that its Unit Price would vary in line with the values of the indices. However, it is not as diversified as the indices and it might not have invested across sectors in the same proportion as that represented by either of the indices.

It was easy to obtain the historical closing prices of the two indices and the Unit Prices of the fund. To keep things simple, I only considered the current month for making this comparison. To simplify things further and to improve the visualisation, I normalised the first value in each series to "100" by scaling all the values appropriately. (This is a technique that I have often seen put to good use in The Economist.)

Using Gnuplot, I obtained the following chart:



This gave me the desired answer right away!

In case you're curious, here are the Gnuplot commands I used for creating the chart above:

# We want PNG output.
set terminal png
set output "plot.png"

# Specify how and where the key (legend) for the chart should
# appear.
set key bottom right
set key width 2 box

# Tweak the look of the chart.
set title "Fluctuations in Unit Prices Relative to Market Indices"
set xlabel "June 2007"
set ylabel "Normalised Value"
set grid

# The data on the X axis represent time values.
set format x "%d"
set xtics "01-Jun-2007", 3600*24
set xdata time
set timefmt "%d-%b-%y"
set xrange ["01-Jun-2007":"22-Jun-2007"]
set yrange [95:100]

# Plot the chart using data files normalising the values in
# each case.
plot \
'nifty.dat' using 1:($5)/42.9705 \
title 'NIFTY' with lines linewidth 2, \
'sensex.dat' using 1:($7)/145.7075 \
title 'SENSEX' with lines linewidth 2, \
'fund.dat' using 1:($2)*100.00/57.0337 \
title 'FUND' with lines linewidth 2


By the way "Junk Charts" seems to be a blog devoted to criticising charts that appear in various magazines and web-sites in general and in The Economist in particular.

3 comments:

  1. I saw your long posting regarding Gnuplot, and thought you might be interested to know that there is now a book on it: "Gnuplot in Action". You can pre-order it directly from the publisher: Manning: Gnuplot in Action.

    If you want to learn more about the book and the author, check out my book page at Principal Value - Gnuplot in Action.

    Let me know if you are interested in a review copy.

    ReplyDelete
  2. Philipp: Thanks for letting us know about your book. I don't use Gnuplot that much at the moment, but I think people who do (or plan to) use Gnuplot extensively would really be interested in checking out your book.

    I think you should at least let the maintainers of this page know about your book.

    ReplyDelete
  3. No problem. And yes, I am working with the Gnuplot maintainers to get the book listed on the gnuplot.info homepage. Thanks for the hint.

    ReplyDelete

Note: Only a member of this blog may post a comment.