[Returnanalytics-commits] r2453 - pkg/PerformanceAnalytics/sandbox/pulkit/week2/code

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Jun 27 12:02:49 CEST 2013


Author: pulkit
Date: 2013-06-27 12:02:48 +0200 (Thu, 27 Jun 2013)
New Revision: 2453

Added:
   pkg/PerformanceAnalytics/sandbox/pulkit/week2/code/SRIndifferenceCurve.R
Log:
SR Indifference curve plot

Added: pkg/PerformanceAnalytics/sandbox/pulkit/week2/code/SRIndifferenceCurve.R
===================================================================
--- pkg/PerformanceAnalytics/sandbox/pulkit/week2/code/SRIndifferenceCurve.R	                        (rev 0)
+++ pkg/PerformanceAnalytics/sandbox/pulkit/week2/code/SRIndifferenceCurve.R	2013-06-27 10:02:48 UTC (rev 2453)
@@ -0,0 +1,45 @@
+#'@title
+#'Sharpe Ratio Indifference Curve
+#'
+#'@description
+#'The trade-off between a candidate’s SR and its correlation
+#' to the existing set of strategies, is given by the Sharpe 
+#' ratio indifference curve. It is a plot between the candidate's 
+#' Sharpe Ratio and candidate's average correlation for a given 
+#' portfolio Sharpe Ratio.
+#' 
+#'The equation for the candidate's average autocorrelation for a given 
+#'sharpe Ratio is given by
+#'\deqn{\bar{\rho{_s+1}}=\frac{1}{2}\biggl[\frac{\bar{SR}.S+SR_{s+1}^2}{S.SR_B^2}-\frac{S+1}{S}-\bar{rho}{S-1}\biggr]}
+#'
+SRIndifference<-function(R, ylab = NULL,xlab = NULL,col=c(1,4),lwd = 2,pch = 1,cex = 1,...){
+  
+  x = checkData(R)
+  columns = ncol(x)
+  SR = SharpeRatio(x)
+  sr_avg = mean(SR)
+  corr = table.Correlation(edhec,edhec)
+  corr_avg = 0
+  for(i in 1:(columns-1)){
+    for(j in (i+1):columns){
+      corr_avg = corr_avg + corr[(i-1)*columns+j,]
+    }
+  }
+  corr_avg = corr_avg*2/(columns*(columns-1))
+  SR_B = BenchmanrkSR(R)
+  corr_range = seq(-1,1,length.out = 30)
+  SR_i = NULL
+  for(i in corr_range){
+    
+    SR_i  = c(SR_i,sqrt((i*2+((columns+1)/columns)+corr_avg[1,1]*(columns-1))*columns*SR_B^2)-sr_avg*columns)
+  }
+  if(is.null(ylab)){
+    ylab = "Candidate Strategy's average correlation"
+  }
+  if(is.null(xlab)){
+    xlab = "Candidate's Strategy's Sharpe Ratio"
+  }
+  plot(SR_i,corr_range,type="l",xlab = xlab,ylab = ylab,main="Sharpe Ratio Indifference Curve")
+  #OR we can use ggplot2 for much better plots
+  #qplot(SR_i,corr_range,geom="line",xlab=xlab,ylab=ylab,main="Sharpe Ratio IndifferenceCurve",margins=TRUE,facet="grid")+stat_summary()
+}
\ No newline at end of file



More information about the Returnanalytics-commits mailing list