Hi Monks,

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.