[Returnanalytics-commits] r2586 - in pkg/PerformanceAnalytics/sandbox/Shubhankit: . Week5 Week5/Code
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Wed Jul 17 11:40:59 CEST 2013
Author: shubhanm
Date: 2013-07-17 11:40:59 +0200 (Wed, 17 Jul 2013)
New Revision: 2586
Added:
pkg/PerformanceAnalytics/sandbox/Shubhankit/Week5/
pkg/PerformanceAnalytics/sandbox/Shubhankit/Week5/Code/
pkg/PerformanceAnalytics/sandbox/Shubhankit/Week5/Code/CDrawdown.R
Log:
Alternative Conditional Drawdown at Risk (Chekhlov, Uryasev and Zabarankin (2003))
Added: pkg/PerformanceAnalytics/sandbox/Shubhankit/Week5/Code/CDrawdown.R
===================================================================
--- pkg/PerformanceAnalytics/sandbox/Shubhankit/Week5/Code/CDrawdown.R (rev 0)
+++ pkg/PerformanceAnalytics/sandbox/Shubhankit/Week5/Code/CDrawdown.R 2013-07-17 09:40:59 UTC (rev 2586)
@@ -0,0 +1,33 @@
+CDrawdown <-
+ function (R,p=0.95, ...)
+ {
+ y = checkData(R, method = "xts")
+ columns = ncol(y)
+ rows = nrow(y)
+ columnnames = colnames(y)
+ rownames = rownames(y)
+
+ for(column in 1:columns) {
+ x = y[,column]
+ drawdown = findDrawdowns(x)
+ threshold= ES(x,p)[1]
+ total = length(drawdown$return)
+ num = length(drawdown$return[drawdown$return>threshold])
+ cva1= (((num/total)-p)/(1-p))*threshold
+ cva2=sum(drawdown$return)/((1-p)*total)
+ z = c((cva1+cva2))
+ znames = c("Conditional Drawdown at Risk")
+ if(column == 1) {
+ resultingtable = data.frame(Value = z, row.names = znames)
+ }
+ else {
+ nextcolumn = data.frame(Value = z, row.names = znames)
+ resultingtable = cbind(resultingtable, nextcolumn)
+ }
+
+ }
+ colnames(resultingtable) = columnnames
+ #ans = base::round(resultingtable, digits)
+ #ans
+ resultingtable
+ }
\ No newline at end of file
More information about the Returnanalytics-commits
mailing list