如何在 MATLAB 中根据经验派生的分布模拟 returns(或 Python)?

How do I simulate returns from an empirically derived distribution in MATLAB (Or Python)?

我还必须牢记分布的偏度和峰度,这些必须反映在模拟值中。

我的经验值是过去的股票 returns(非标准正态分布)。

是否有可以为我执行此操作的现有软件包?我在网上看到的所有包都只有前两个时刻

您所描述的是使用 method of moments to define a distribution. Such methods have generally fallen out of favor in statistics. However, you can check out pearsonrnd,根据您的数据,它可能工作正常。

相反,我建议直接找到 empirical CDF for the data using ecdf and use that in conjunction with inverse sampling 来生成随机变量。这里有一个基本函数可以做到这一点:

function r=empiricalrnd(y,varargin)
%EMPIRICALRND  Random values from an empirical distribution
%   EMPIRICALRND(Y) returns a single random value from distribution described by the data
%   in the vector Y.
%   
%   EMPIRICALRND(Y,M), EMPIRICALRND(Y,M,N), EMPIRICALRND(Y,[M,N]), etc. return random arrays.

[f,x] = ecdf(y);
r = rand(varargin{:});
r = interp1(f,x,r,'linear','extrap');

如果您愿意,可以使用 interp1 的选项。这是一个快速测试:

% Generate demo data for 100 samples of log-normal distribution
mu = 1;
sig = 1;
m = 1e2;
rng(1); % Set seed to make repeatable
y = lognrnd(mu,sig,m,1);

% Generate 1000 random variates from data
n = 1e3;
r = empiricalrnd(y,n,1);

% Plot CDFs
ecdf(y);
hold on;
ecdf(r);
x = 0:0.1:50;
plot(x,logncdf(x,mu,sig),'g');
legend('Empirical CDF','CDF of sampled data','Actual CDF');