官术网_书友最值得收藏!

Handling financial data

Although gnuplot was originally envisioned as a scientist's companion, it has proven to be a worthy and reliable friend to financial analysts. Financial plotting comes with its own set of complex problems, some of which we'll have to defer to later chapters; in the following figure, we illustrate the basic financial plotting style:

Handling financial data

This type of plot will be familiar to you if you follow the stock market.

Getting ready

Sample financial data is essential for illustrating financial plotting. Fortunately, the gnuplot distribution comes with an appropriate sample datafile. In case you don't have it, we have provided a copy called finance.dat. Make sure it's in your current directory so that gnuplot can find it. You are welcome, of course, to use your own data, but it must be in the correct format. Each line of the file represents a separate data point, and consists of (at least) five numbers, separated by spaces: date open low high close.

An example of a line from such a datafile would look similar to the following:

3/11/2011  76.15  76.63  75.2  75.35

How to do it…

Enter the following commands while you are in the directory containing the datafile:

set bars 2
plot [0:100] 'finance.dat' using 0:2:3:4:5 notitle with financebars

How it works…

This makes the conventional financial graph showing the high, low, open, and close prices for a stock. If you are reading this recipe, you no doubt already know why you want this type of plot.

The default size of the tics for the opening and closing prices is quite small; the first command makes it longer. The second command sets the range, chooses the file, and specifies the columns to use for the finance plot.

主站蜘蛛池模板: 玉树县| 泰顺县| 富锦市| 龙岩市| 滨州市| 温州市| 静乐县| 洛扎县| 大埔县| 鹰潭市| 松阳县| 体育| 曲水县| 鹤峰县| 清徐县| 文山县| 仪陇县| 焉耆| 新泰市| 麟游县| 丰镇市| 项城市| 乡城县| 宜良县| 镇巴县| 华阴市| 柏乡县| 保定市| 航空| 高雄市| 锦州市| 天峨县| 平果县| 内乡县| 镇江市| 肃宁县| 涞源县| 阿拉尔市| 金山区| 襄垣县| 阿鲁科尔沁旗|