我有 255 个金融 Assets 的月度(约 21 年)返回率,范围从 -22.25% 到 +18.09%。我正在使用 Fitting empirical distribution to theoretical ones with Scipy (Python)? 中的代码使数据符合分布并生成随机数。
这是数据的直方图。我相信上面的代码尝试使用 MLE(最大似然估计)将数据拟合到分布中,列表中大约有 88 种不同的分布。我的问题是,例如,burr
分布只是正随机变量( https://en.wikipedia.org/wiki/Burr_distribution 、 https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.burr.html )。
但是当我拟合分布、获取参数并制作 PDF 时,我得到以下结果:
该分布既有正值又有负值。
说实话,我认为我没有完全理解代码和拟合分布的含义。为什么应该只适合正值的分布也适合负值?
最佳答案
尝试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'})
免责声明:我也是此存储库的作者。
关于python - 使用 python 拟合经验分布,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63616897/