views:

79

answers:

1

I need to create a Monte Carlo simulator for some financial transactions. The inputs would be:

  • the average percent of transactions that end up profitable
  • the average profit per transaction
  • the number of transactions per time period

I've looked at the Math::Random::MT::Auto Perl module but am unsure how to formulate the inputs to the simulator.

Can anyone offer some advice on getting started given the inputs I'm working with?

+1  A: 

I would assume there would be a model determining profitability of transactions and that there would be a probabilistic component of the profitability of a given transaction.

Then, you need to draw realizations from the appropriate distribution for that probabilistic component and calculate profitability for all transactions entered. Obviously, one also has to think about which transactions would be entered into: Why enter a transaction which is not ex ante profitable according to some criterion? But, I do not know enough to comment on that.

Be careful not to use the built-in RNG: On Windows, that will basically give you only 32768 possible values.

Here is a silly example:

#!/usr/bin/perl

use strict; use warnings;
use List::Util qw( sum );

my @projects = map { mk_project() } 1 .. 1_000;

for my $i (1 .. 10) {
    my $r = rand;
    my @profits = map { $_->($r) } @projects;
    my $avg_profits = sum( @profits ) / @profits;
    my $n_profitable = grep { $_ >= 0 } @profits;
    print "Profits: $avg_profits\tProfitable: $n_profitable\n";
}

sub mk_project {
    my $m = rand;
    return sub {
        my ($r) = @_;
        return 10*($r - $m);
    }
}
Sinan Ünür