[Returnanalytics-commits] r2454 - in pkg/PerformanceAnalytics/sandbox/pulkit/week2: code vignette
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Thu Jun 27 18:55:34 CEST 2013
Author: pulkit
Date: 2013-06-27 18:55:34 +0200 (Thu, 27 Jun 2013)
New Revision: 2454
Modified:
pkg/PerformanceAnalytics/sandbox/pulkit/week2/code/BenchmarkSR.R
pkg/PerformanceAnalytics/sandbox/pulkit/week2/code/SRIndifferenceCurve.R
pkg/PerformanceAnalytics/sandbox/pulkit/week2/vignette/SharepRatioEfficientFrontier.Rnw
Log:
updated the BenchmarkSR , SRIndifference and the vignette
Modified: pkg/PerformanceAnalytics/sandbox/pulkit/week2/code/BenchmarkSR.R
===================================================================
--- pkg/PerformanceAnalytics/sandbox/pulkit/week2/code/BenchmarkSR.R 2013-06-27 10:02:48 UTC (rev 2453)
+++ pkg/PerformanceAnalytics/sandbox/pulkit/week2/code/BenchmarkSR.R 2013-06-27 16:55:34 UTC (rev 2454)
@@ -28,6 +28,10 @@
BenchmanrkSR<-function(R){
x = checkData(R)
columns = ncol(x)
+ #TODO : What to do if the number of columns is only one ?
+ if(columns == 1){
+ stop("The number of return series should be greater than 1")
+ }
SR = SharpeRatio(x)
sr_avg = mean(SR)
corr = table.Correlation(edhec,edhec)
Modified: pkg/PerformanceAnalytics/sandbox/pulkit/week2/code/SRIndifferenceCurve.R
===================================================================
--- pkg/PerformanceAnalytics/sandbox/pulkit/week2/code/SRIndifferenceCurve.R 2013-06-27 10:02:48 UTC (rev 2453)
+++ pkg/PerformanceAnalytics/sandbox/pulkit/week2/code/SRIndifferenceCurve.R 2013-06-27 16:55:34 UTC (rev 2454)
@@ -10,12 +10,31 @@
#'
#'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,...){
+#'@param R an xts, vector, matrix, data frame, timeSeries or zoo object of
+#' asset returns
+#'@param ylab set the y-axis label, as in \code{\link{plot}}
+#'@param xlab set the x-axis label, as in \code{\link{plot}}
+#'@param lwd set the width of the line, as in \code{\link{plot}}
+#'@param pch set the pch value, as in \code{\link{plot}}
+#'@param cex set the cex value, as in \code{\link{plot}}
+#'
+#'@references
+#'Bailey, David H. and Lopez de Prado, Marcos, The Strategy Approval Decision:
+#'A Sharpe Ratio Indifference Curve Approach (January 2013). Algorithmic Finance,
+#'Vol. 2, No. 1 (2013).
+#'
+#'
+SRIndifference<-function(R, ylab = NULL,xlab = NULL,lwd = 2,pch = 1,cex = 1,...){
x = checkData(R)
columns = ncol(x)
+ #TODO: What to do when the number of columns is 1 ?
+ if(columns == 1){
+ stop("The number of return series should be greater 1 ")
+ }
SR = SharpeRatio(x)
sr_avg = mean(SR)
corr = table.Correlation(edhec,edhec)
@@ -39,7 +58,7 @@
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")
+ #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()
+ 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
Modified: pkg/PerformanceAnalytics/sandbox/pulkit/week2/vignette/SharepRatioEfficientFrontier.Rnw
===================================================================
--- pkg/PerformanceAnalytics/sandbox/pulkit/week2/vignette/SharepRatioEfficientFrontier.Rnw 2013-06-27 10:02:48 UTC (rev 2453)
+++ pkg/PerformanceAnalytics/sandbox/pulkit/week2/vignette/SharepRatioEfficientFrontier.Rnw 2013-06-27 16:55:34 UTC (rev 2454)
@@ -32,12 +32,17 @@
<<echo=FALSE>>=
library(PerformanceAnalytics)
+library(ggplot2)
data(edhec)
@
<<echo=FALSE>>=
source("/home/pulkit/workspace/GSOC/PerformanceAnalytics/sandbox/pulkit/week2/code/BenchmarkSR.R")
@
+
+<<echo=FALSE>>=
+source("/home/pulkit/workspace/GSOC/PerformanceAnalytics/sandbox/pulkit/week2/code/SRIndifferenceCurve.R")
+@
\section{Benchmark Sharpe Ratio}
@@ -57,4 +62,21 @@
BenchmanrkSR(edhec)
@
+\section{Sharpe Ratio Indifference Curve}
+
+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]}
+
+<<fig = TRUE>>=
+SRIndifference(edhec)
+@
+
\end{document}
\ No newline at end of file
More information about the Returnanalytics-commits
mailing list