如何开始在 Perl 中对财务数据进行蒙特卡罗模拟?

发布于 2024-09-25 09:32:02 字数 292 浏览 0 评论 0 原文

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

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

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

任何人都可以根据我正在使用的输入提供一些入门建议吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

枯叶蝶 2024-10-02 09:32:02

我假设有一个模型决定交易的盈利能力,并且给定交易的盈利能力有一个概率组成部分。

然后,您需要从该概率组件的适当分布中得出认识,并计算输入的所有交易的盈利能力。显然,人们还必须考虑将进行哪些交易:为什么要进行一项根据某种标准不能事前盈利的交易?但是,我的了解不够,无法对此发表评论。

注意不要使用内置 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);
    }
}

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);
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文