[英]Fitting Tail Data to Generalized Pareto Distribution in R
我有16年的S&P500收益數據集。 當我繪制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)設置為使尾巴成為雀斑(如果尾巴確實很肥大)。
R中是否有方法可以對此進行測試並根據我的數據找到這些參數的值?
曾經有一個叫做POT的軟件包,它具有fitgpd函數,我相信它會給我我的比例和形狀參數。 但是該軟件包不再可用。 有誰知道其他軟件包中的類似功能可以為我提供合適的參數?
我認為這應該對我有用
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
請讓我知道這看起來還好嗎?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.