Python:将copula拟合到时间序列Data并将新数据放入分布中

syqv5f0l  于 2023-02-06  发布在  Python
关注(0)|答案(2)|浏览(189)

我正在导入价格数据,并希望将这些数据拟合到一个由历史数据创建的copula中,我最初使用copulalib包(也可以使用copula)来创建一个copula(在本例中是Gumbel),但我无法将新的价格数据放置在该分布上。当从这些包中生成u,v时,它使用了从均匀分布中提取的随机数。

7fyelxc5

7fyelxc51#

在问题中没有提供任何数据的情况下,我建议从θ = 2的Gumbel copula创建样本,然后尝试将Gumbel copula拟合到所获得的样本以猜测θ

import openturns as ot

theta = 2
Original_copula = ot.GumbelCopula(theta)
sample = Original_copula.getSample(500)

# Fitting of a Gumbel copula
Fitted_distribution = ot.GumbelCopulaFactory().build(sample)
print("Guessed theta =", Fitted_distribution.getParameter()[0])
>>> Guessed theta = 2.1805628386645686

对于样本量为5000的情况,我得出猜测θ = 2.0099533501045226
More available OpenTURNS Copulas here

jk9hmnmh

jk9hmnmh2#

使用distfit函数库,您可以拟合定价历史数据的分布,然后使用predict函数对新的未知样本进行预测。请参阅此处的更多文档。predict函数返回经过多重检验校正的P值。

# Example data
X = np.random.normal(10, 3, 2000)
y = [3,4,5,6,10,11,12,18,20]

# From the distfit library import the class distfit
from distfit import distfit

# Initialize
dfit = distfit(todf=True)

# Search for best theoretical fit on your empirical data
dfit.fit_transform(X)

# Make prediction on new datapoints based on the fit
results = dfit.predict(y)

# The plot function will now also include the predictions of y
dfit.plot()

结果如下:

results['df']

      y   y_proba y_pred         P
0   3.0  0.023792   down  0.007931
1   4.0  0.044730   down  0.019880
2   5.0  0.079661   down  0.044256
3   6.0  0.131986   none  0.087990
4  10.0  0.492335   none  0.492335
5  11.0  0.406206   none  0.361072
6  12.0  0.315383   none  0.245298
7  18.0  0.018689     up  0.004153
8  20.0  0.004836     up  0.000537

相关问题