简体   繁体   English

将尾部数据拟合到R中的广义帕累托分布

[英]Fitting Tail Data to Generalized Pareto Distribution in R

I have a dataset of S&P500 returns for 16 yrs. 我有16年的S&P500收益数据集。 When I plot the ECDF of the S&P500 and compare it against the CDF of an equivalent Normal distribution, I can see the existence of Fat Tails in the S&P 500 data. 当我绘制S&P500的ECDF并将其与等效正态分布的CDF进行比较时,我可以看到S&P 500数据中存在Fat Tails。 The code is as below:- 代码如下:

library(quantmod) # Loading quantmod library
getSymbols("^GSPC", from = as.character(Sys.Date()-365*16)) # SPX price date for 16 yrs

SPX <- dailyReturn(GSPC)
SPX_ecdf <- ecdf(as.numeric(SPX)) # dropping xts class

plot(SPX_ecdf,lwd=2,col="red")# Plotting the empirical CDF of S&P500
SPX_mean <- mean(as.numeric(SPX))
SPX_sd <- sd(as.numeric(SPX))

xseq<-seq(-4,4,.01)
cumulative<-pnorm(xseq, mean=SPX_mean, sd=SPX_sd)
lines(xseq,cumulative,col="blue",lwd=2) #Plotting the CDF of a Normal Distribution
legend(x="topleft",c("Empirical CDF of S&P 500 Daily returns","CDF of the Normal Distribution"),col=c("red","blue"),lwd=c(2,2))

Now I would like to model the Tail of my data with the help of GPD. 现在,我想借助GPD对数据的尾巴进行建模。 Now if I am correct, the shape parameter(ξ > 0) and scale parameter (β > 0) in order for the Tail to be a Frechet(If it has really fat tails). 现在,如果我是对的,则将形状参数(ξ> 0)和比例参数(β> 0)设置为使尾巴成为雀斑(如果尾巴确实很肥大)。

Is there a way in R, to test this out and also find the value of these parameters based on my data? R中是否有方法可以对此进行测试并根据我的数据找到这些参数的值?

There used to be a package called POT which had a function fitgpd which I believe would have given me my scale and shape parameters. 曾经有一个叫做POT的软件包,它具有fitgpd函数,我相信它会给我我的比例和形状参数。 But this package is no longer available. 但是该软件包不再可用。 Is anybody aware of a similar function in some other package which gives me the fitted parameters? 有谁知道其他软件包中的类似功能可以为我提供合适的参数?

I think this should work for me 我认为这应该对我有用

library(ismev)
SPX <- SPX*(-1) # Converting the lower tail to the upper tail
fit<-gpd.fit(as.numeric(SPX),0.04) # This will fit my data of the upper tail beyond threshold of 0.04 to a GPD
fit$mle    # This should give me the Maximum Likelihood estimates for the scale and shape parameter

Please let me know if this looks fine? 请让我知道这看起来还好吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM