How can I start with Monte Carlo simulations for financial data in Perl?

I need to create a Monte Carlo simulator for some financial transactions. Inputs will be:

  • average percentage of transactions that become profitable
  • average profit per transaction
  • number of transactions over a period of time

I looked at the Math :: Random :: MT :: Auto Perl module , but I don’t know how to formulate the input for the simulator.

Can anyone offer some tips on getting started with the data I'm working with?

+3
source share
1 answer

, , , .

. , , : , ex ante ? , , .

, RNG: Windows 32768 .

:

#!/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);
    }
}
+4

Source: https://habr.com/ru/post/1767186/


All Articles