[Returnanalytics-commits] r2211 - pkg/PerformanceAnalytics/R

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Fri Jul 27 17:24:37 CEST 2012


Author: peter_carl
Date: 2012-07-27 17:24:37 +0200 (Fri, 27 Jul 2012)
New Revision: 2211

Modified:
   pkg/PerformanceAnalytics/R/PortfolioRisk.R
Log:
- fixed the last fix by changing sign on VaR value


Modified: pkg/PerformanceAnalytics/R/PortfolioRisk.R
===================================================================
--- pkg/PerformanceAnalytics/R/PortfolioRisk.R	2012-07-27 15:13:25 UTC (rev 2210)
+++ pkg/PerformanceAnalytics/R/PortfolioRisk.R	2012-07-27 15:24:37 UTC (rev 2211)
@@ -509,23 +509,23 @@
 ES.historical = function(R,p) {
     alpha = .setalphaprob(p)
     for(column in 1:ncol(R)) {
-	r = na.omit(as.vector(R[,column]))
-	q = quantile(r,probs=alpha)
-	exceedr = r[r<q]
-	hES = (-mean(exceedr))
-        if(is.nan(hES)){
-          warning(paste(colnames(R[,column]),"No values less than VaR observed.  Setting ES equal to VaR."))
-          hES=q
-        }
-          
-        hES=array(hES)
-        if (column==1) {
-            #create data.frame
-            result=data.frame(hES=hES)
-        } else {
-            hES=data.frame(hES=hES)
-            result=cbind(result,hES)
-        }
+      r = na.omit(as.vector(R[,column]))
+      q = quantile(r,probs=alpha)
+      exceedr = r[r<q]
+      hES = (-mean(exceedr))
+      if(is.nan(hES)){
+        warning(paste(colnames(R[,column]),"No values less than VaR observed.  Setting ES equal to VaR."))
+        hES=-q
+      }
+      
+      hES=array(hES)
+      if (column==1) {
+        #create data.frame
+        result=data.frame(hES=hES)
+      } else {
+        hES=data.frame(hES=hES)
+        result=cbind(result,hES)
+      }
     }	
     colnames(result)<-colnames(R)
     return(result)



More information about the Returnanalytics-commits mailing list