I am looking for some advice on how to generate a realistic stock price series. I have hacked together the following but it relies on hardcoded ceiling values for daily changes and price ranges. Obviously I will need some kind of controls to limit the movement of prices but I would also like my market simulation to have the potential to 'crash'.
Currently my price series looks too random when plotted, I need to inject a little bit of human irrationality into the series.
Any pointers on how this may be done would be gratefully received.
use strict; use warnings; my $start = sprintf("%.2f",(1 + rand(100))); my $direction = sub { return rand(1) > 0.5 ? 1 : -1; }; my $varience = sub { return rand(0.05); }; my $range = sub { return rand(0.08); }; my $high; my $low; my $close; my @prices; for(1..1012){ if(!defined $high){ $high = sprintf("%.2f",( $direction->() * $varience->() * $sta +rt ) + $start); $low = sprintf("%.2f",( $high - ($high * $range->()))); $close = sprintf("%.2f",(rand($high - $low) + $low)); } else { $high = sprintf("%.2f",( $direction->() * $varience->() * $hig +h ) + $high); $low = sprintf("%.2f",( $high - ($high * $range->()))); $close = sprintf("%.2f",(rand($high - $low) + $low)); } print "$high,$low,$close\n"; } exit;
Many Thanks, TeraMarv
In reply to Generating Stock Price Data by TeraMarv
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |