[Returnanalytics-commits] r3066 - in pkg/PerformanceAnalytics/sandbox/pulkit: . R man src

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Sep 12 03:05:37 CEST 2013


Author: pulkit
Date: 2013-09-12 03:05:36 +0200 (Thu, 12 Sep 2013)
New Revision: 3066

Added:
   pkg/PerformanceAnalytics/sandbox/pulkit/R/ExtremeDrawdown.R
   pkg/PerformanceAnalytics/sandbox/pulkit/R/gpdmle.R
   pkg/PerformanceAnalytics/sandbox/pulkit/man/DrawdownGPD.Rd
   pkg/PerformanceAnalytics/sandbox/pulkit/src/gpd.c
Modified:
   pkg/PerformanceAnalytics/sandbox/pulkit/DESCRIPTION
   pkg/PerformanceAnalytics/sandbox/pulkit/NAMESPACE
   pkg/PerformanceAnalytics/sandbox/pulkit/R/chart.Penance.R
   pkg/PerformanceAnalytics/sandbox/pulkit/R/chart.REDD.R
   pkg/PerformanceAnalytics/sandbox/pulkit/R/redd.R
   pkg/PerformanceAnalytics/sandbox/pulkit/man/chart.Penance.Rd
   pkg/PerformanceAnalytics/sandbox/pulkit/man/rollDrawdown.Rd
   pkg/PerformanceAnalytics/sandbox/pulkit/src/moment.c
Log:
GPD files added

Modified: pkg/PerformanceAnalytics/sandbox/pulkit/DESCRIPTION
===================================================================
--- pkg/PerformanceAnalytics/sandbox/pulkit/DESCRIPTION	2013-09-11 22:05:46 UTC (rev 3065)
+++ pkg/PerformanceAnalytics/sandbox/pulkit/DESCRIPTION	2013-09-12 01:05:36 UTC (rev 3066)
@@ -49,3 +49,5 @@
     'psr_python.R'
     'ret.R'
     'Penance.R'
+    'ExtremeDrawdown.R'
+    'gpdmle.R'

Modified: pkg/PerformanceAnalytics/sandbox/pulkit/NAMESPACE
===================================================================
--- pkg/PerformanceAnalytics/sandbox/pulkit/NAMESPACE	2013-09-11 22:05:46 UTC (rev 3065)
+++ pkg/PerformanceAnalytics/sandbox/pulkit/NAMESPACE	2013-09-12 01:05:36 UTC (rev 3066)
@@ -7,6 +7,7 @@
 export(chart.Penance)
 export(chart.REDD)
 export(chart.SRIndifference)
+export(DrawdownGPD)
 export(EconomicDrawdown)
 export(EDDCOPS)
 export(golden_section)

Added: pkg/PerformanceAnalytics/sandbox/pulkit/R/ExtremeDrawdown.R
===================================================================
--- pkg/PerformanceAnalytics/sandbox/pulkit/R/ExtremeDrawdown.R	                        (rev 0)
+++ pkg/PerformanceAnalytics/sandbox/pulkit/R/ExtremeDrawdown.R	2013-09-12 01:05:36 UTC (rev 3066)
@@ -0,0 +1,80 @@
+#'@title
+#'Modelling Drawdown using Extreme Value Theory
+#'
+#"@description
+#'It has been shown empirically that Drawdowns can be modelled using Modified Generalized Pareto 
+#'distribution(MGPD), Generalized Pareto Distribution(GPD) and other particular cases of MGPD such 
+#'as weibull distribution \eqn{MGPD(\gamma,0,\psi)} and unit exponential distribution\eqn{MGPD(1,0,\psi)}
+#'
+#' 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}}
+#'
+#' 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}
+#' 
+#' The GDP is given by the following equation. \eqn{MGPD(1,\eta,\psi)}
+#'
+#'\deqn{G_{\eta}(m) = \begin{array}{l} 1-(1+\eta\frac{m}{\psi})^(-1/\eta), if \eta \neq 0 \\ 1- e^{-frac{m}{\psi}}, if \eta = 0,\end{array}}
+#'
+#' The weibull distribution is given by the following equation \eqn{MGPD(\gamma,0,\psi)}
+#'
+#'\deqn{G(m) =  1- e^{-frac{m^\gamma}{\psi}}}
+#'
+#'In this function generalized Pareto distribution has been covered. This function can be 
+#'expanded in the future to include more Extreme Value distributions as the literature on such distribution
+#'matures in the future. 
+#'
+#' @param R an xts, vector, matrix, data frame, timeSeries or zoo object of asset return 
+#' @param threshold The threshold beyond which the drawdowns have to be modelled
+#'
+#'
+#'@references
+#'Mendes, Beatriz V.M. and Leal, Ricardo P.C., Maximum Drawdown: Models and Applications (November 2003). 
+#'Coppead Working Paper Series No. 359.Available at SSRN: http://ssrn.com/abstract=477322 or http://dx.doi.org/10.2139/ssrn.477322.
+#'
+#'@examples
+#'data(edhec)
+#'DrawdownGPD(edhec)
+#'data(managers)
+#'DrawdownGPD(managers[,1:9],0.95)
+#'
+#'@export
+DrawdownGPD<-function(R,threshold=0.90){
+    x = checkData(R)
+    columns = ncol(R)
+    columnnames = colnames(R)
+    gpdfit<-function(data,threshold){
+            gpd_fit = gpd(as.vector(data),as.vector(threshold))
+            result = list(shape = gpd_fit$param[2],scale = gpd_fit$param[1])
+            return(result)
+    }
+    for(column in 1:columns){
+        dr = -Drawdowns(R[,column])
+        thresh = quantile(na.omit(dr),threshold)
+        column.parameters = gpdfit(dr,thresh)
+            if(column == 1){
+                shape = column.parameters$shape
+                scale = column.parameters$scale
+            }
+            else {
+                scale = c(scale, column.parameters$scale) 
+                shape = c(shape, column.parameters$shape)
+            }
+    }
+    parameters = rbind(scale,shape)
+    colnames(parameters) = columnnames
+    parameters = reclass(parameters, x)
+    rownames(parameters)=c("scale","shape")
+    return(parameters)
+}
+
+
+
+
+
+
+
+
+

Modified: pkg/PerformanceAnalytics/sandbox/pulkit/R/chart.Penance.R
===================================================================
--- pkg/PerformanceAnalytics/sandbox/pulkit/R/chart.Penance.R	2013-09-11 22:05:46 UTC (rev 3065)
+++ pkg/PerformanceAnalytics/sandbox/pulkit/R/chart.Penance.R	2013-09-12 01:05:36 UTC (rev 3066)
@@ -42,7 +42,7 @@
 #'
 #'@export
 
-chart.Penance<-function(R,confidence,type=c("ar","normal"),reference.grid = TRUE,main=NULL,ylab = NULL,xlab = NULL,element.color="darkgrey",lwd = 2,pch = 1,cex = 1,cex.axis=0.8,cex.lab = 1,cex.main = 1,xlim = NULL,ylim = NULL,...){
+chart.Penance<-function(R,confidence=0.95,type=c("ar","normal"),reference.grid = TRUE,main=NULL,ylab = NULL,xlab = NULL,element.color="darkgrey",lwd = 2,pch = 1,cex = 1,cex.axis=0.8,cex.lab = 1,cex.main = 1,xlim = NULL,ylim = NULL,...){
 
   # DESCRIPTION:
   # Draws the scatter plot of Phi vs Penance.

Modified: pkg/PerformanceAnalytics/sandbox/pulkit/R/chart.REDD.R
===================================================================
--- pkg/PerformanceAnalytics/sandbox/pulkit/R/chart.REDD.R	2013-09-11 22:05:46 UTC (rev 3065)
+++ pkg/PerformanceAnalytics/sandbox/pulkit/R/chart.REDD.R	2013-09-12 01:05:36 UTC (rev 3066)
@@ -9,7 +9,9 @@
 #'@param rf risk free rate can be vector such as government security rate of return
 #'@param h lookback period 
 #'@param geometric utilize geometric chaining (TRUE) or simple/arithmetic chaining(FALSE) to aggregate returns, default is TRUE.
-#'@param legend.loc set the legend.loc, as in \code{\link{plot}}
+#' @param legend.loc places a legend into one of nine locations on the chart:
+#' bottomright, bottom, bottomleft, left, topleft, top, topright, right, or
+#' center.
 #'@param colorset set the colorset label, as in \code{\link{plot}}
 #'@param \dots any other  variable
 #'@author Pulkit Mehrotra
@@ -19,8 +21,9 @@
 #'Control Maximum Drawdown - The Case of Risk Based Dynamic Asset Allocation (February 25, 2012)
 #'@examples
 #'data(edhec)
-#'chart.REDD(edhec,0.08,20)
-#'
+#'chart.REDD(edhec,0.08,20,legend.loc = "topleft")
+#'data(managers)
+#'chart.REDD(managers,0.08,20,legend.loc = "topleft")
 #'@export
 
 chart.REDD<-function(R,rf,h, geometric = TRUE,legend.loc = NULL, colorset = (1:12),...)
@@ -34,7 +37,7 @@
   # free return(rf) and the lookback period(h) is taken as the input.
  
 
-    rolldrawdown = rollDrawdown(R,geometric = TRUE,weights = NULL,rf,h)
+    rolldrawdown = rollDrawdown(R,geometric = TRUE,rf,h)
     chart.TimeSeries(rolldrawdown, colorset = colorset, legend.loc = legend.loc, ...)
 }
 

Added: pkg/PerformanceAnalytics/sandbox/pulkit/R/gpdmle.R
===================================================================
--- pkg/PerformanceAnalytics/sandbox/pulkit/R/gpdmle.R	                        (rev 0)
+++ pkg/PerformanceAnalytics/sandbox/pulkit/R/gpdmle.R	2013-09-12 01:05:36 UTC (rev 3066)
@@ -0,0 +1,172 @@
+## This function comes from the  package "POT" . The gpd function
+## corresponds to the gpdmle function. So, I'm very gratefull to Mathieu Ribatet.
+#'@useDynLib noniid.pm
+gpd <- function(x, threshold, start, ...,
+                   std.err.type = "observed", corr = FALSE,
+                   method = "BFGS", warn.inf = TRUE){
+
+  if (all(c("observed", "expected", "none") != std.err.type))
+    stop("``std.err.type'' must be one of 'observed', 'expected' or 'none'")
+  
+  nlpot <- function(scale, shape) { 
+    -.C("gpdlik", exceed, nat, threshold, scale,
+        shape, dns = double(1))$dns
+  }
+  
+  nn <- length(x)
+  
+  threshold <- rep(threshold, length.out = nn)
+  
+  high <- (x > threshold) & !is.na(x)
+  threshold <- as.double(threshold[high])
+  exceed <- as.double(x[high])
+  nat <- length(exceed)
+  
+  if(!nat) stop("no data above threshold")
+  
+  pat <- nat/nn
+  param <- c("scale", "shape")
+  
+  if(missing(start)) {
+    
+    start <- list(scale = 0, shape = 0)
+    start$scale <- mean(exceed) - min(threshold)
+    
+    start <- start[!(param %in% names(list(...)))]
+    
+  }
+  
+  if(!is.list(start)) 
+    stop("`start' must be a named list")
+  
+  if(!length(start))
+    stop("there are no parameters left to maximize over")
+  
+  nm <- names(start)
+  l <- length(nm)
+  f <- formals(nlpot)
+  names(f) <- param
+  m <- match(nm, param)
+  
+  if(any(is.na(m))) 
+    stop("`start' specifies unknown arguments")
+  
+  formals(nlpot) <- c(f[m], f[-m])
+  nllh <- function(p, ...) nlpot(p, ...)
+  
+  if(l > 1)
+    body(nllh) <- parse(text = paste("nlpot(", paste("p[",1:l,
+                          "]", collapse = ", "), ", ...)"))
+  
+  fixed.param <- list(...)[names(list(...)) %in% param]
+  
+  if(any(!(param %in% c(nm,names(fixed.param)))))
+    stop("unspecified parameters")
+  
+  start.arg <- c(list(p = unlist(start)), fixed.param)
+  if( warn.inf && do.call("nllh", start.arg) == 1e6 )
+    warning("negative log-likelihood is infinite at starting values")
+  
+  opt <- optim(start, nllh, hessian = TRUE, ..., method = method)
+    
+  if ((opt$convergence != 0) || (opt$value == 1e6)) {
+    warning("optimization may not have succeeded")
+    if(opt$convergence == 1) opt$convergence <- "iteration limit reached"
+  }
+  
+  else opt$convergence <- "successful"
+
+  if (std.err.type != "none"){
+    
+    tol <- .Machine$double.eps^0.5
+    
+    if(std.err.type == "observed") {
+      
+      var.cov <- qr(opt$hessian, tol = tol)
+      if(var.cov$rank != ncol(var.cov$qr)){
+        warning("observed information matrix is singular; passing std.err.type to ``expected''")
+        obs.fish <- FALSE
+        return
+      }
+      
+      if (std.err.type == "observed"){
+        var.cov <- try(solve(var.cov, tol = tol), silent = TRUE)
+
+        if(!is.matrix(var.cov)){
+          warning("observed information matrix is singular; passing std.err.type to ''none''")
+          std.err.type <- "expected"
+          return
+        }
+
+        else{
+          std.err <- diag(var.cov)
+          if(any(std.err <= 0)){
+            warning("observed information matrix is singular; passing std.err.type to ``expected''")
+            std.err.type <- "expected"
+            return
+          }
+          
+          std.err <- sqrt(std.err)
+        
+          if(corr) {
+            .mat <- diag(1/std.err, nrow = length(std.err))
+            corr.mat <- structure(.mat %*% var.cov %*% .mat, dimnames = list(nm,nm))
+            diag(corr.mat) <- rep(1, length(std.err))
+          }
+          else {
+            corr.mat <- NULL
+          }
+        }
+      }
+    }
+    
+    if (std.err.type == "expected"){
+      
+      shape <- opt$par[2]
+      scale <- opt$par[1]
+      a22 <- 2/((1+shape)*(1+2*shape))
+      a12 <- 1/(scale*(1+shape)*(1+2*shape))
+      a11 <- 1/((scale^2)*(1+2*shape))
+      ##Expected Matix of Information of Fisher
+      expFisher <- nat * matrix(c(a11,a12,a12,a22),nrow=2)
+
+      expFisher <- qr(expFisher, tol = tol)
+      var.cov <- solve(expFisher, tol = tol)
+      std.err <- sqrt(diag(var.cov))
+      
+      if(corr) {
+        .mat <- diag(1/std.err, nrow = length(std.err))
+        corr.mat <- structure(.mat %*% var.cov %*% .mat, dimnames = list(nm,nm))
+        diag(corr.mat) <- rep(1, length(std.err))
+      }
+      else
+        corr.mat <- NULL
+    }
+
+    colnames(var.cov) <- nm
+    rownames(var.cov) <- nm
+    names(std.err) <- nm
+  }
+
+  else{
+    std.err <- std.err.type <- corr.mat <- NULL
+    var.cov <- NULL
+  }
+  
+  
+  param <- c(opt$par, unlist(fixed.param))
+  scale <- param["scale"]
+  
+  var.thresh <- !all(threshold == threshold[1])
+
+  if (!var.thresh)
+    threshold <- threshold[1]
+  
+  list(fitted.values = opt$par, std.err = std.err, std.err.type = std.err.type,
+       var.cov = var.cov, fixed = unlist(fixed.param), param = param,
+       deviance = 2*opt$value, corr = corr.mat, convergence = opt$convergence,
+       counts = opt$counts, message = opt$message, threshold = threshold,
+       nat = nat, pat = pat, data = x, exceed = exceed, scale = scale,
+       var.thresh = var.thresh, est = "MLE", logLik = -opt$value,
+       opt.value = opt$value, hessian = opt$hessian)
+}

Modified: pkg/PerformanceAnalytics/sandbox/pulkit/R/redd.R
===================================================================
--- pkg/PerformanceAnalytics/sandbox/pulkit/R/redd.R	2013-09-11 22:05:46 UTC (rev 3065)
+++ pkg/PerformanceAnalytics/sandbox/pulkit/R/redd.R	2013-09-12 01:05:36 UTC (rev 3066)
@@ -27,7 +27,8 @@
 #'@examples
 #'data(edhec)
 #'rollDrawdown(edhec,0.08,100)
-#'
+#'data(managers)
+#'rollDrawdown(managers[,1:9],managers[,10],10)
 #' @export
 rollDrawdown<-function(R,Rf,h, geometric = TRUE,...)
 {

Added: pkg/PerformanceAnalytics/sandbox/pulkit/man/DrawdownGPD.Rd
===================================================================
--- pkg/PerformanceAnalytics/sandbox/pulkit/man/DrawdownGPD.Rd	                        (rev 0)
+++ pkg/PerformanceAnalytics/sandbox/pulkit/man/DrawdownGPD.Rd	2013-09-12 01:05:36 UTC (rev 3066)
@@ -0,0 +1,91 @@
+\name{DrawdownGPD}
+\alias{DrawdownGPD}
+\title{Modelling Drawdown using Extreme Value Theory
+
+It has been shown empirically that Drawdowns can be modelled using Modified Generalized Pareto
+distribution(MGPD), Generalized Pareto Distribution(GPD) and other particular cases of MGPD such
+as weibull distribution \eqn{MGPD(\gamma,0,\psi)} and unit exponential distribution\eqn{MGPD(1,0,\psi)}
+
+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}}
+
+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}
+
+The GDP is given by the following equation. \eqn{MGPD(1,\eta,\psi)}
+
+\deqn{G_{\eta}(m) = \begin{array}{l} 1-(1+\eta\frac{m}{\psi})^(-1/\eta), if \eta \neq 0 \\ 1- e^{-frac{m}{\psi}}, if \eta = 0,\end{array}}
+
+The weibull distribution is given by the following equation \eqn{MGPD(\gamma,0,\psi)}
+
+\deqn{G(m) =  1- e^{-frac{m^\gamma}{\psi}}}
+
+In this function generalized Pareto distribution has been covered. This function can be
+expanded in the future to include more Extreme Value distributions as the literature on such distribution
+matures in the future.}
+\usage{
+  DrawdownGPD(R, threshold = 0.9)
+}
+\arguments{
+  \item{R}{an xts, vector, matrix, data frame, timeSeries
+  or zoo object of asset return}
+
+  \item{threshold}{The threshold beyond which the drawdowns
+  have to be modelled}
+}
+\description{
+  Modelling Drawdown using Extreme Value Theory
+
+  It has been shown empirically that Drawdowns can be
+  modelled using Modified Generalized Pareto
+  distribution(MGPD), Generalized Pareto Distribution(GPD)
+  and other particular cases of MGPD such as weibull
+  distribution \eqn{MGPD(\gamma,0,\psi)} and unit
+  exponential distribution\eqn{MGPD(1,0,\psi)}
+
+  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}}
+
+  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}
+
+  The GDP is given by the following equation.
+  \eqn{MGPD(1,\eta,\psi)}
+
+  \deqn{G_{\eta}(m) = \begin{array}{l}
+  1-(1+\eta\frac{m}{\psi})^(-1/\eta), if \eta \neq 0 \\ 1-
+  e^{-frac{m}{\psi}}, if \eta = 0,\end{array}}
+
+  The weibull distribution is given by the following
+  equation \eqn{MGPD(\gamma,0,\psi)}
+
+  \deqn{G(m) = 1- e^{-frac{m^\gamma}{\psi}}}
+
+  In this function generalized Pareto distribution has been
+  covered. This function can be expanded in the future to
+  include more Extreme Value distributions as the
+  literature on such distribution matures in the future.
+}
+\examples{
+data(edhec)
+DrawdownGPD(edhec)
+data(managers)
+DrawdownGPD(managers[,1:9],0.95)
+}
+\references{
+  Mendes, Beatriz V.M. and Leal, Ricardo P.C., Maximum
+  Drawdown: Models and Applications (November 2003).
+  Coppead Working Paper Series No. 359.Available at SSRN:
+  http://ssrn.com/abstract=477322 or
+  http://dx.doi.org/10.2139/ssrn.477322.
+}
+

Modified: pkg/PerformanceAnalytics/sandbox/pulkit/man/chart.Penance.Rd
===================================================================
--- pkg/PerformanceAnalytics/sandbox/pulkit/man/chart.Penance.Rd	2013-09-11 22:05:46 UTC (rev 3065)
+++ pkg/PerformanceAnalytics/sandbox/pulkit/man/chart.Penance.Rd	2013-09-12 01:05:36 UTC (rev 3066)
@@ -2,11 +2,12 @@
 \alias{chart.Penance}
 \title{Penance vs phi plot}
 \usage{
-  chart.Penance(R, confidence, type = c("ar", "normal"),
-    reference.grid = TRUE, main = NULL, ylab = NULL,
-    xlab = NULL, element.color = "darkgrey", lwd = 2,
-    pch = 1, cex = 1, cex.axis = 0.8, cex.lab = 1,
-    cex.main = 1, xlim = NULL, ylim = NULL, ...)
+  chart.Penance(R, confidence = 0.95,
+    type = c("ar", "normal"), reference.grid = TRUE,
+    main = NULL, ylab = NULL, xlab = NULL,
+    element.color = "darkgrey", lwd = 2, pch = 1, cex = 1,
+    cex.axis = 0.8, cex.lab = 1, cex.main = 1, xlim = NULL,
+    ylim = NULL, ...)
 }
 \arguments{
   \item{R}{an xts, vector, matrix, data frame, timeSeries

Modified: pkg/PerformanceAnalytics/sandbox/pulkit/man/rollDrawdown.Rd
===================================================================
--- pkg/PerformanceAnalytics/sandbox/pulkit/man/rollDrawdown.Rd	2013-09-11 22:05:46 UTC (rev 3065)
+++ pkg/PerformanceAnalytics/sandbox/pulkit/man/rollDrawdown.Rd	2013-09-12 01:05:36 UTC (rev 3066)
@@ -37,6 +37,8 @@
 \examples{
 data(edhec)
 rollDrawdown(edhec,0.08,100)
+data(managers)
+rollDrawdown(managers[,1:9],managers[,10],10)
 }
 \author{
   Pulkit Mehrotra

Added: pkg/PerformanceAnalytics/sandbox/pulkit/src/gpd.c
===================================================================
--- pkg/PerformanceAnalytics/sandbox/pulkit/src/gpd.c	                        (rev 0)
+++ pkg/PerformanceAnalytics/sandbox/pulkit/src/gpd.c	2013-09-12 01:05:36 UTC (rev 3066)
@@ -0,0 +1,41 @@
+#include<R.h>
+#include<Rinternals.h>
+#include<Rmath.h>
+
+
+void gpdlik(double *data, int *n, double *loc, double *scale,
+	    double *shape, double *dns)
+{
+  int i;
+  double *dvec;
+  
+  dvec = (double *)R_alloc(*n, sizeof(double));
+
+  if(*scale <= 0) {
+     *dns = -1e6;
+     return;
+  }
+
+  for(i=0;i<*n;i++)  {
+    data[i] = (data[i] - loc[i]) / *scale;
+    if (data[i] <= 0) {
+      *dns = -1e6;
+      return;
+    }
+    if(fabs(*shape) <= 1e-6){
+      *shape = 0;
+      dvec[i] = -log(*scale) - data[i];
+    }
+    else {
+      data[i] = 1 + *shape * data[i];
+      if(data[i] <= 0) {
+	*dns = -1e6;
+	return;
+      }
+      dvec[i] = -log(*scale) - (1 / *shape + 1) * log(data[i]);
+    }
+  }
+  
+  for(i=0;i<*n;i++) 
+    *dns = *dns + dvec[i];
+}

Modified: pkg/PerformanceAnalytics/sandbox/pulkit/src/moment.c
===================================================================
--- pkg/PerformanceAnalytics/sandbox/pulkit/src/moment.c	2013-09-11 22:05:46 UTC (rev 3065)
+++ pkg/PerformanceAnalytics/sandbox/pulkit/src/moment.c	2013-09-12 01:05:36 UTC (rev 3066)
@@ -56,5 +56,4 @@
     return Rsum;
 }
 
- 
 



More information about the Returnanalytics-commits mailing list