[Returnanalytics-commits] r2791 - pkg/PerformanceAnalytics/sandbox/pulkit/week7
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Thu Aug 15 16:40:05 CEST 2013
Author: pulkit
Date: 2013-08-15 16:40:04 +0200 (Thu, 15 Aug 2013)
New Revision: 2791
Modified:
pkg/PerformanceAnalytics/sandbox/pulkit/week7/ExtremeDrawdown.R
Log:
editing GPD for drawdowns
Modified: pkg/PerformanceAnalytics/sandbox/pulkit/week7/ExtremeDrawdown.R
===================================================================
--- pkg/PerformanceAnalytics/sandbox/pulkit/week7/ExtremeDrawdown.R 2013-08-15 10:30:02 UTC (rev 2790)
+++ pkg/PerformanceAnalytics/sandbox/pulkit/week7/ExtremeDrawdown.R 2013-08-15 14:40:04 UTC (rev 2791)
@@ -8,7 +8,7 @@
#'
#' Modified Generalized Pareto Distribution is given by the following formula
#'
-#' \deqn{G_{\eta}(m) = \begin{array}{l} 1-(1+\eta\frac{m^\gamma}{\psi})^(-1/\eta), if \eta \neq 0 \\ 1- e^{-frac{m^\gamma}{\psi}}, if \eta = 0,\end{array}}
+#' \dqeqn{G_{\eta}(m) = \begin{array}{l} 1-(1+\eta\frac{m^\gamma}{\psi})^(-1/\eta), if \eta \neq 0 \\ 1- e^{-frac{m^\gamma}{\psi}}, if \eta = 0,\end{array}}
#'
#' Here \eqn{\gamma{\epsilon}R} is the modifying parameter. When \eqn{\gamma<1} the corresponding densities are
#' strictly decreasing with heavier tail; the GDP is recovered by setting \eqn{\gamma = 1} .\eqn{\gamma \textgreater 1}
@@ -27,7 +27,7 @@
#'
#'
#' @param R an xts, vector, matrix, data frame, timeSeries or zoo object of asset return
-#' @param type The type of distribution "gpd","pd","weibull","exponential"
+#' @param type The type of distribution "gpd","pd","weibull"
#' @param threshold The threshold beyond which the drawdowns have to be modelled
#'
#'@references
@@ -35,14 +35,28 @@
#'Available at SSRN: http://ssrn.com/abstract=477322 or http://dx.doi.org/10.2139/ssrn.477322.
#'
#'
-DrawdownGPD<-function(R,type=c("gpd","pd","weibull","exponential"),threshold=0.90){
+DrawdownGPD<-function(R,type=c("gpd","pd","weibull"),threshold=0.90){
x = checkData(R)
columns = ncol(R)
columnnames = colnames(R)
type = type[1]
dr = -Drawdowns(R)
dr_sorted = sort(as.vector(dr))
- data = dr_sorted[0.9*nrow(R):nrow(r)]
+ data = dr_sorted[(0.9*nrow(R)):nrow(R)]
+ if(type=="gpd"){
+ gpd = fitgpd(data)
+ return(gpd)
+ }
+ if(type=="wiebull"){
+ weibull = fitdistr(data,"weibull")
+ return(weibull)
+ }
+ if(type=="pd"){
+ scale = min(data)
+ shape = length(data)/(sum(log(data))-length(data)*log(a))
+ }
+
+
}
More information about the Returnanalytics-commits
mailing list