4

我需要为一些金融交易创建一个蒙特卡洛模拟器。输入将是:

  • 最终盈利的交易的平均百分比
  • 每笔交易的平均利润
  • 每个时间段的交易数量

我查看了Math::Random::MT::Auto Perl 模块,但不确定如何制定模拟器的输入。

鉴于我正在使用的输入,任何人都可以提供一些关于入门的建议吗?

4

1 回答 1

5

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);
    }
}
于 2010-09-29T15:44:08.497 回答