/usr/bin/gnuplot symlinks packageing problems were fixed gor gnuplot-x11
[gnuplot] / demo / finance.dem
1 # 10 May 2005
2
3 # Though gnuplot is primarily a scientific plotting program, it can do a great
4 # job of plotting finance charts as well. The primary challenge is the irregular
5 # nature of financial time series. Stocks don't trade every day, so when you set
6 # the x-axis to time gaps appear for non-trading days. Investors and traders
7 # generally prefer that these gaps be omitted. Another challenge is that finance
8 # charts are best presented in semi-log form (log y-axis, linear x-axis),
9 # but gnuplot wants to span decades in its log scaling, something that stocks
10 # rarely do. These and other challenges are met in finance.dem, a short 
11 # demonstration script that proves that gnuplot can really shine in this area.
12
13 # gnuplot plays a central role in our work. Almost all the graphs in "Bollinger
14 # on Bollinger Bands" were plotted by gnuplot, many gnuplot visuals have
15 # appeared on CNBC, our in-house analytics use gnuplot for visual display and
16 # The Capital Growth Letter relies heavily on gnuplot for its charts.  
17
18 # Finally, gnuplot is yet another successful demonstration of a powerful idea,
19 # open source programming. Thanks to all who made gnuplot possible from the
20 # earliest days to the present and to all those who will contribute in the
21 # future. (Special thanks to Hans-Bernhard Broeker whose patience helped me to
22 # climb the grade and to Ethan Merritt whose recent contributions have been
23 # invaluable to our work.)
24
25 # John Bollinger
26 # www.BollingerBands.com 
27
28 # a demonstration of gnuplot finance plot styles
29 # by John Bollinger, CFA, CMT
30 # www.BollingerBands.com
31 # BBands@BollingerBands.com
32
33 # data and indicators in finance.dat
34 # data file layout: 
35 # date, open, high, low, close, volume,
36 # 50-day moving average volume, Intraday Intensity, 
37 # 20-day moving average close, 
38 # upper Bollinger Band, lower Bollinger Band 
39
40 # last update: 8 May 2005
41
42 pause -1 "Click OK to start the Finance Demo"
43
44 reset
45 # set label 1 "Demo of plotting financial data" at screen 0.5, screen 0.95 center
46 set title "Demo of plotting financial data"
47 set yrange [75:105]
48 set ytics (105, 100, 95, 90, 85, 80)
49 set xrange [50:253]
50 set lmargin 9
51 set rmargin 2
52 plot 'finance.dat' using 0:5 notitle with lines
53
54 pause -1 "Turn on the grid"
55
56 reset
57 set title "Turn on grid"
58 set yrange [75:105]
59 set ytics (105, 100, 95, 90, 85, 80)
60 set xrange [50:253]
61 set lmargin 9
62 set rmargin 2
63 set grid
64 plot 'finance.dat' using 0:5 notitle with lines
65
66 pause -1 "Semi-log scaling"
67
68 reset
69 set title "Semi-log scaling"
70 set yrange [75:105]
71 set ytics (105, 100, 95, 90, 85, 80)
72 set xrange [50:253]
73 set lmargin 9
74 set rmargin 2
75 set grid
76 set logscale y
77 plot 'finance.dat' using 0:5 notitle with lines
78
79 pause -1 "Finance bars"
80
81 reset
82 set title "Finance bars"
83 set yrange [75:105]
84 set ytics (105, 100, 95, 90, 85, 80)
85 set xrange [50:253]
86 set lmargin 9
87 set rmargin 2
88 set grid
89 set logscale y
90 plot 'finance.dat' using 0:2:3:4:5 notitle with financebars lt 8
91
92 pause -1 "Bollinger Bands"
93
94 reset
95 set title "Bollinger Bands"
96 set yrange [75:105]
97 set ytics (105, 100, 95, 90, 85, 80)
98 set xrange [50:253]
99 set lmargin 9
100 set rmargin 2
101 set grid
102 set logscale y
103 plot 'finance.dat' using 0:2:3:4:5 notitle with financebars lt 8, \
104 'finance.dat' using 0:9 notitle with lines lt 3, \
105 'finance.dat' using 0:10 notitle with lines lt 1, \
106 'finance.dat' using 0:11 notitle with lines lt 2
107
108
109 pause -1 "Overlay an indicator on a seperate scale"
110
111 reset
112 set title "Overlay an indicator on a separate scale"
113 set yrange [75:105]
114 set ytics (105, 100, 95, 90, 85, 80)
115 set xrange [50:253]
116 set lmargin 9
117 set rmargin 2
118 set grid
119 set logscale y
120 plot 'finance.dat' using 0:2:3:4:5 notitle with financebars lt 8, \
121 'finance.dat' using 0:9 notitle with lines lt 3, \
122 'finance.dat' using 0:10 notitle with lines lt 1, \
123 'finance.dat' using 0:11 notitle with lines lt 2, \
124 'finance.dat' using 0:8 axes x1y2 notitle with lines lt 4
125
126 pause -1 "Add some boiler plate"
127
128 reset
129 set title "Add some boiler plate"
130 set label "Courtesy of Bollinger Capital" at graph 0.01, 0.07
131 set label "  www.BollingerBands.com" at graph 0.01, 0.03
132 set yrange [75:105]
133 set ytics (105, 100, 95, 90, 85, 80)
134 set xrange [50:253]
135 set lmargin 9
136 set rmargin 2
137 set grid
138 set logscale y
139 plot 'finance.dat' using 0:2:3:4:5 notitle with financebars lt 8, \
140 'finance.dat' using 0:9 notitle with lines lt 3, \
141 'finance.dat' using 0:10 notitle with lines lt 1, \
142 'finance.dat' using 0:11 notitle with lines lt 2, \
143 'finance.dat' using 0:8 axes x1y2 notitle with lines lt 4
144
145 pause -1 "Add volume in a seperate clip"
146
147 reset
148 set label "Courtesy of Bollinger Capital" at graph 0.01, 0.07
149 set label "  www.BollingerBands.com" at graph 0.01, 0.03
150 set logscale y
151 set yrange [75:105]
152 set ytics (105, 100, 95, 90, 85, 80)
153 set xrange [50:253]
154 set grid
155 set lmargin 9
156 set rmargin 2
157 set format x ""
158 set xtics (66, 87, 109, 130, 151, 174, 193, 215, 235)
159 set multiplot
160 set size 1, 0.7
161 set origin 0, 0.3
162 set bmargin 0
163 set title "Add volume in a separate clip"
164 plot 'finance.dat' using 0:2:3:4:5 notitle with financebars lt 8, \
165 'finance.dat' using 0:9 notitle with lines lt 3, \
166 'finance.dat' using 0:10 notitle with lines lt 1, \
167 'finance.dat' using 0:11 notitle with lines lt 2, \
168 'finance.dat' using 0:8 axes x1y2 notitle with lines lt 4
169 unset label 1
170 unset label 2
171 unset title
172 set bmargin
173 set format x
174 set size 1.0, 0.3
175 set origin 0.0, 0.0
176 set tmargin 0
177 unset logscale y
178 set autoscale y
179 set format y "%1.0f"
180 set ytics 500
181 plot 'finance.dat' using 0:($6/10000) notitle with impulses lt 3
182 unset multiplot
183
184 pause -1 "Add average volume"
185
186 reset
187 set label "Courtesy of Bollinger Capital" at graph 0.01, 0.07
188 set label "  www.BollingerBands.com" at graph 0.01, 0.03
189 set logscale y
190 set yrange [75:105]
191 set ytics (105, 100, 95, 90, 85, 80)
192 set xrange [50:253]
193 set grid
194 set lmargin 9
195 set rmargin 2
196 set format x ""
197 set xtics (66, 87, 109, 130, 151, 174, 193, 215, 235)
198 set multiplot
199 set title "Add average volume"
200 set size 1, 0.7
201 set origin 0, 0.3
202 set bmargin 0
203 plot 'finance.dat' using 0:2:3:4:5 notitle with financebars lt 8, \
204 'finance.dat' using 0:9 notitle with lines lt 3, \
205 'finance.dat' using 0:10 notitle with lines lt 1, \
206 'finance.dat' using 0:11 notitle with lines lt 2, \
207 'finance.dat' using 0:8 axes x1y2 notitle with lines lt 4
208 unset label 1
209 unset label 2
210 unset title
211 set bmargin
212 set format x
213 set size 1.0, 0.3
214 set origin 0.0, 0.0
215 set tmargin 0
216 unset logscale y
217 set autoscale y
218 set format y "%1.0f"
219 set ytics 500
220 plot 'finance.dat' using 0:($6/10000) notitle with impulses lt 3, \
221 'finance.dat' using 0:($7/10000) notitle with lines lt 1
222 unset multiplot
223
224 pause -1 "Add date labels to the x axis"
225
226 reset
227 set label "Courtesy of Bollinger Capital" at graph 0.01, 0.07
228 set label "  www.BollingerBands.com" at graph 0.01, 0.03
229 set logscale y
230 set yrange [75:105]
231 set ytics (105, 100, 95, 90, 85, 80)
232 set xrange [50:253]
233 set grid
234 set lmargin 9
235 set rmargin 2
236 set format x ""
237 set xtics (66, 87, 109, 130, 151, 174, 193, 215, 235)
238 set multiplot
239 set title "Add date labels to the x axis"
240 set size 1, 0.7
241 set origin 0, 0.3
242 set bmargin 0
243 plot 'finance.dat' using 0:2:3:4:5 notitle with financebars lt 8, \
244 'finance.dat' using 0:9 notitle with lines lt 3, \
245 'finance.dat' using 0:10 notitle with lines lt 1, \
246 'finance.dat' using 0:11 notitle with lines lt 2, \
247 'finance.dat' using 0:8 axes x1y2 notitle with lines lt 4
248 unset label 1
249 unset label 2
250 unset title
251 set bmargin
252 set format x
253 set size 1.0, 0.3
254 set origin 0.0, 0.0
255 set tmargin 0
256 unset logscale y
257 set autoscale y
258 set format y "%1.0f"
259 set ytics 500
260 set xtics ("6/03" 66, "7/03" 87, "8/03" 109, "9/03" 130, "10/03" 151, "11/03" 174, "12/03" 193, "1/04" 215, "2/04" 235)
261 plot 'finance.dat' using 0:($6/10000) notitle with impulses lt 3, \
262 'finance.dat' using 0:($7/10000) notitle with lines lt 1
263 unset multiplot
264
265 pause -1 "Add labels for each clip"
266
267 reset
268 set label "Courtesy of Bollinger Capital" at graph 0.01, 0.07
269 set label "  www.BollingerBands.com" at graph 0.01, 0.03
270 set logscale y
271 set yrange [75:105]
272 set ytics (105, 100, 95, 90, 85, 80)
273 set xrange [50:253]
274 set grid
275 set lmargin 9
276 set rmargin 2
277 set format x ""
278 set xtics (66, 87, 109, 130, 151, 174, 193, 215, 235)
279 set multiplot
280 set title "Add labels for each clip"
281 set size 1, 0.7
282 set origin 0, 0.3
283 set bmargin 0
284 set ylabel "price" offset 1
285 plot 'finance.dat' using 0:2:3:4:5 notitle with financebars lt 8, \
286 'finance.dat' using 0:9 notitle with lines lt 3, \
287 'finance.dat' using 0:10 notitle with lines lt 1, \
288 'finance.dat' using 0:11 notitle with lines lt 2, \
289 'finance.dat' using 0:8 axes x1y2 notitle with lines lt 4
290 unset label 1
291 unset label 2
292 unset title
293 set bmargin
294 set format x
295 set size 1.0, 0.3
296 set origin 0.0, 0.0
297 set tmargin 0
298 unset logscale y
299 set autoscale y
300 set format y "%1.0f"
301 set ytics 500
302 set xtics ("6/03" 66, "7/03" 87, "8/03" 109, "9/03" 130, "10/03" 151, "11/03" 174, "12/03" 193, "1/04" 215, "2/04" 235)
303 set ylabel "volume (0000)" offset 1
304 plot 'finance.dat' using 0:($6/10000) notitle with impulses lt 3, \
305 'finance.dat' using 0:($7/10000) notitle with lines lt 1
306 unset multiplot
307
308 pause -1 "Add a title"
309
310 reset
311 set label 1 "Acme Widgets" at graph 0.5, graph 0.9 center front
312 set label 2 "Courtesy of Bollinger Capital" at graph 0.01, 0.07
313 set label 3 "  www.BollingerBands.com" at graph 0.01, 0.03
314 set logscale y
315 set yrange [75:105]
316 set ytics (105, 100, 95, 90, 85, 80)
317 set xrange [50:253]
318 set grid
319 set lmargin 9
320 set rmargin 2
321 set format x ""
322 set xtics (66, 87, 109, 130, 151, 174, 193, 215, 235)
323 set multiplot
324 set title "Add a title"
325 set size 1, 0.7
326 set origin 0, 0.3
327 set bmargin 0
328 set ylabel "price" offset 1
329 plot 'finance.dat' using 0:2:3:4:5 notitle with financebars lt 8, \
330 'finance.dat' using 0:9 notitle with lines lt 3, \
331 'finance.dat' using 0:10 notitle with lines lt 1, \
332 'finance.dat' using 0:11 notitle with lines lt 2, \
333 'finance.dat' using 0:8 axes x1y2 notitle with lines lt 4
334 unset label 1
335 unset label 2
336 unset label 3
337 unset title
338 set bmargin
339 set format x
340 set size 1.0, 0.3
341 set origin 0.0, 0.0
342 set tmargin 0
343 unset logscale y
344 set autoscale y
345 set format y "%1.0f"
346 set ytics 500
347 set xtics ("6/03" 66, "7/03" 87, "8/03" 109, "9/03" 130, "10/03" 151, "11/03" 174, "12/03" 193, "1/04" 215, "2/04" 235)
348 set ylabel "volume (0000)" offset 1
349 plot 'finance.dat' using 0:($6/10000) notitle with impulses lt 3, \
350 'finance.dat' using 0:($7/10000) notitle with lines lt 1
351 unset multiplot
352
353 pause -1 " Change to Candlesticks"
354
355 reset
356 set label 1 "Acme Widgets" at graph 0.5, graph 0.9 center front
357 set label 2 "Courtesy of Bollinger Capital" at graph 0.01, 0.07
358 set label 3 "  www.BollingerBands.com" at graph 0.01, 0.03
359 set logscale y
360 set yrange [75:105]
361 set ytics (105, 100, 95, 90, 85, 80)
362 set xrange [50:253]
363 set grid
364 set lmargin 9
365 set rmargin 2
366 set format x ""
367 set xtics (66, 87, 109, 130, 151, 174, 193, 215, 235)
368 set multiplot
369 set title "Change to candlesticks"
370 set size 1, 0.7
371 set origin 0, 0.3
372 set bmargin 0
373 set ylabel "price" offset 1
374 plot 'finance.dat' using 0:2:3:4:5 notitle with candlesticks lt 8, \
375 'finance.dat' using 0:9 notitle with lines lt 3, \
376 'finance.dat' using 0:10 notitle with lines lt 1, \
377 'finance.dat' using 0:11 notitle with lines lt 2, \
378 'finance.dat' using 0:8 axes x1y2 notitle with lines lt 4
379 unset label 1
380 unset label 2
381 unset label 3
382 unset title
383 set bmargin
384 set format x
385 set size 1.0, 0.3
386 set origin 0.0, 0.0
387 set tmargin 0
388 unset logscale y
389 set autoscale y
390 set format y "%1.0f"
391 set ytics 500
392 set xtics ("6/03" 66, "7/03" 87, "8/03" 109, "9/03" 130, "10/03" 151, "11/03" 174, "12/03" 193, "1/04" 215, "2/04" 235)
393 set ylabel "volume (0000)" offset 1
394 plot 'finance.dat' using 0:($6/10000) notitle with impulses lt 3, \
395 'finance.dat' using 0:($7/10000) notitle with lines lt 1
396 unset multiplot
397
398 pause -1 "Change to Bollinger Boxes"
399
400 reset
401 set label 1 "Acme Widgets" at graph 0.5, graph 0.9 center front
402 set label 2 "Courtesy of Bollinger Capital" at graph 0.01, 0.07
403 set label 3 "  www.BollingerBands.com" at graph 0.01, 0.03
404 set logscale y
405 set yrange [75:105]
406 set ytics (105, 100, 95, 90, 85, 80)
407 set xrange [50:253]
408 set grid
409 set lmargin 9
410 set rmargin 2
411 set format x ""
412 set xtics (66, 87, 109, 130, 151, 174, 193, 215, 235)
413 set multiplot
414 set title "Change to Bollinger Boxes"
415 set size 1, 0.7
416 set origin 0, 0.3
417 set bmargin 0
418 set ylabel "price" offset 1
419 plot 'finance.dat' using 0:3:3:($2>$5?$2:$5):($2>$5?$2:$5) notitle with candlesticks lt 3, \
420 'finance.dat' using 0:($2<$5?$5:1/0):($2<$5?$5:1/0):($2<$5?$2:1/0):($2<$5?$2:1/0) notitle with candlesticks lt 2, \
421 'finance.dat' using 0:($2>$5?$2:1/0):($2>$5?$2:1/0):($2>$5?$5:1/0):($2>$5?$5:1/0) notitle with candlesticks lt 1, \
422 'finance.dat' using 0:($2<$5?$2:$5):($2<$5?$2:$5):4:4 notitle with candlesticks lt 3, \
423 'finance.dat' using 0:9 notitle with lines lt 3, \
424 'finance.dat' using 0:10 notitle with lines lt 1, \
425 'finance.dat' using 0:11 notitle with lines lt 2, \
426 'finance.dat' using 0:8 axes x1y2 notitle with lines lt 4
427 unset label 1
428 unset label 2
429 unset label 3
430 unset title
431 set bmargin
432 set format x
433 set size 1.0, 0.3
434 set origin 0.0, 0.0
435 set tmargin 0
436 unset logscale y
437 set autoscale y
438 set format y "%1.0f"
439 set ytics 500
440 set xtics ("6/03" 66, "7/03" 87, "8/03" 109, "9/03" 130, "10/03" 151, "11/03" 174, "12/03" 193, "1/04" 215, "2/04" 235)
441 set ylabel "volume (0000)" offset 1
442 plot 'finance.dat' using 0:($6/10000) notitle with impulses lt 3, \
443 'finance.dat' using 0:($7/10000) notitle with lines lt 1
444 unset multiplot
445
446 pause -1 "all done!"
447 reset