Finance-Quant

 view release on metacpan or  search on metacpan

lib/Finance/Quant.pm  view on Meta::CPAN

		$s = ts::nstdev_ma($s, $lines->[1]->{data}, 2);
		$lines->[2] = {	name => 'MA + 2 Std Dev', color => 'lred', data => $s->[0] };
		$lines->[3] = {	name => 'MA - 2 Std Dev', color => 'lred', data => $s->[1] };
		
		return plotlines($img, $stock, $q->{Date}, $lines, $y_format);

	}
	
	sub plotlines {
		my ($file, $stock, $x, $lines, $y_format) = @_;
		my @legend;
		my ($data, $colors) = ([], []);
		
		$data->[0] = $x;   # x-axis labels
	
		for (0..$#{$lines}) {
			$data->[(1+$_)] = $lines->[$_]->{data};
			$colors->[$_] = $lines->[$_]->{color};
			$legend[$_] = $lines->[$_]->{name};
		}
	
		my $graph = GD::Graph::lines->new(740,420);
		$graph->set (dclrs => $colors) or warn $graph->error;
		$graph->set_legend(@legend) or warn $graph->error;
		$graph->set (legend_placement => 'BC') or warn $graph->error;
		$graph->set(y_number_format => $y_format) if $y_format;
		$graph->set (
			title => "stock: $stock",
			boxclr => 'black',
			bgclr => 'dgray',
			axislabelclr => 'white',
			legendclr => 'white',
			textclr => 'white',
			r_margin => 20,
			tick_length => -4,
			y_long_ticks => 1,
			axis_space => 10,
			x_labels_vertical => 1,
			x_label_skip => int(0.2*scalar(@{$data->[0]}))
		) or warn $graph->error;	
		my $gd = $graph->plot($data) or warn $graph->error;



( run in 1.016 second using v1.01-cache-2.11-cpan-49f99fa48dc )