in reply to Generating Stock Price Data

How about something like this?

#! perl -slw use strict; use GD::Graph::lines; use GD::Graph::colour qw(:colours :lists :files :convert); our $STOCKS ||= 5; our $CHANGE ||= 10; our $TREND ||= int rand 3; my $graph = GD::Graph::lines->new( 1024, 768 ); $graph->set( title => 'Price over day', 'bgclr' => 'white', 'transparent' => 0, 'interlaced' => 1, x_label => 'Time (hours)', x_max_value => 24, x_tick_number => 12, x_label_skip => 2, y_label => 'Price', y_tick_number => 10, y_label_skip => 2, ) or die $graph->error; my @tracks = map int( rand 100 ), 0 .. $STOCKS; my @data = map [], 1 .. $STOCKS; for my $interval ( 0 .. ( 24 * 6 - 1 ) ) { ## every 10 minutes push @{ $data[ 0 ] }, ( $interval * 10 ) / 60; ## time in hours for my $stock ( 1 .. $STOCKS ) { my $trend = rand() < .2 ? $TREND : int( rand 3 ); my $change = int( rand $CHANGE ) * ( -1 + $trend ); push @{ $data[ $stock ] }, $tracks[ $stock ] += $change; } }; my $gd = $graph->plot( \@data ) or die $graph->error; open(IMG, '>graph.png') or die $!; binmode IMG; print IMG $gd->png; close IMG; system 'graph.png';

A few settings that produce interesting examples:

c:\test>794374 -STOCKS=5 -CHANGE=20 -TREND=-2 c:\test>794374 -STOCKS=5 -CHANGE=20 -TREND=1 c:\test>794374 -STOCKS=5 -CHANGE=20 -TREND=0 c:\test>794374 -STOCKS=5 -CHANGE=20 -TREND=-1 c:\test>794374 -STOCKS=5 -CHANGE=10 -TREND=-1 c:\test>794374 -STOCKS=5 -CHANGE=10 -TREND=1 c:\test>794374 -STOCKS=5 -CHANGE=10 -TREND=2 c:\test>794374 -STOCKS=5 -CHANGE=10 -TREND=0

You can obviously get more sophisticated by having the trend alter trhough the day (week/month/year) etc.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
RIP PCW It is as I've been saying!(Audio until 20090817)

Replies are listed 'Best First'.
Re^2: Generating Stock Price Data
by TeraMarv (Beadle) on Sep 10, 2009 at 00:08 UTC
    Thank you for your input. I'll see what I can 'steal' that fits my purpose.