将尾部数据拟合到R中的广义Pareto分布

时间:2016-09-05 14:51:57

标签: r

我有一个S& P500数据集返回16年。当我绘制S& P500的ECDF并将其与等效正态分布的CDF进行比较时,我可以看到S& P 500数据中存在Fat Tails。代码如下: -

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))

现在我想在GPD的帮助下为我的数据尾部建模。现在,如果我是正确的,形状参数(ξ> 0)和比例参数(β> 0),以使Tail成为Frechet(如果它真的很胖)。

R中是否有办法测试这个,并根据我的数据找到这些参数的值?

曾经有一个名为 POT 的软件包,它有一个函数 fitgpd ,我相信它会给我带来我的比例和形状参数。但是这个包已经不再可用了。是否有人知道其他包装中的类似功能,它给出了适合的参数?

1 个答案:

答案 0 :(得分:0)

我认为这对我有用

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

如果这看起来不错,请告诉我?