All pastes #1071498 Raw Edit

stocksim.pl

public text v1 · immutable
#1071498 ·published 2008-07-14 05:38 UTC
rendered paste body
#!/usr/bin/perl

$OCTAVE="stocksim.m";
$INPUT="buysell.dat";
$OUTPUT="buysell-gnuplot.png";

system("octave $OCTAVE");

print "Using gnuplot to plot graphs. Results are saved to $OUTPUT.\n";
open(GNUPLOT, "|gnuplot -persist");
print GNUPLOT <<PLOT;

set title "Tsang's 2-day-19-day moving average strategy (Source: 0005.HK from 20030101 to 20071231)"
#set title "Buy and hold strategy (Source: 0005.HK from 20030101 to 20071231)"
set xlabel "Days"
set ylabel "Amount relative to initial value"

set terminal png small
set output "$OUTPUT"

set key left top

plot \\
  "$INPUT" using 1:2 with points title "Value: cash",\\
  "$INPUT" using 1:3 with points title "Value: stock",\\
  "$INPUT" using 1:4 with lines title "Value: total",\\
  "$INPUT" using 1:5 with lines title "Stock price"

PLOT
close(GNUPLOT)