python - 使用 python 拟合经验分布

标签 python scipy statistics

我有 255 个金融 Assets 的月度(约 21 年)返回率,范围从 -22.25% 到 +18.09%。我正在使用 Fitting empirical distribution to theoretical ones with Scipy (Python)? 中的代码使数据符合分布并生成随机数。

enter image description here

这是数据的直方图。我相信上面的代码尝试使用 MLE(最大似然估计)将数据拟合到分布中,列表中大约有 88 种不同的分布。我的问题是,例如,burr 分布只是正随机变量( https://en.wikipedia.org/wiki/Burr_distributionhttps://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.burr.html )。

但是当我拟合分布、获取参数并制作 PDF 时,我得到以下结果: enter image description here

该分布既有正值又有负值。

说实话,我认为我没有完全理解代码和拟合分布的含义。为什么应该只适合正值的分布也适合负值?

最佳答案

尝试distfit图书馆。它适合基于您的经验数据的最佳理论分布。它返回 loc/scale 参数。您可以设置方向性来测试显着性(上限/下限)。拟合后的模型可用于生成新样本。

pip install distfit

# import library
from distfit import distfit

# Lets create some random data for demonstration purposes. Ssuppose that X is your data.
X = np.random.normal(0, 2, 10000)

# Initialize with default settings
model= distfit(bound='both')

# Fit to find the best theoretical distribution 
model.fit_transform(X)

dfit.plot(
          pdf_properties={'color': 'r', 'linewidth': 4},
          bar_properties={'color': '#1e3f5a', 'edgecolor': 'k'})

Pareto plot

免责声明:我也是此存储库的作者。

关于python - 使用 python 拟合经验分布,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63616897/

相关文章:

python - 为什么 scipy.norm.pdf 有时给出 PDF > 1?如何纠正?

python - 从pdf生成概率?

r - 按因子计算组的均值

python - 将 x,y 坐标转换为 getAffineTransform 的格式?

python - 模块未找到错误 : No module named 'pip.commands'

python - Django : using self. assertIn() 中的单元测试以查找键/值对中的文本

algorithm - 3D 渐进平面拟合算法

python - 如何用pandas-python递归地构造一列数据框?

python - 牛顿拉夫森法用户输入和数值输出问题

sql - 生成按订单总数分组的订单统计信息