[Returnanalytics-commits] r2460 - in pkg/PerformanceAnalytics/sandbox/pulkit/week2: code vignette
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Fri Jun 28 16:33:44 CEST 2013
Author: pulkit
Date: 2013-06-28 16:33:44 +0200 (Fri, 28 Jun 2013)
New Revision: 2460
Added:
pkg/PerformanceAnalytics/sandbox/pulkit/week2/code/BenchmarkPlots.R
Modified:
pkg/PerformanceAnalytics/sandbox/pulkit/week2/vignette/SharepRatioEfficientFrontier.Rnw
Log:
Added B\enchmarkPlots
Added: pkg/PerformanceAnalytics/sandbox/pulkit/week2/code/BenchmarkPlots.R
===================================================================
--- pkg/PerformanceAnalytics/sandbox/pulkit/week2/code/BenchmarkPlots.R (rev 0)
+++ pkg/PerformanceAnalytics/sandbox/pulkit/week2/code/BenchmarkPlots.R 2013-06-28 14:33:44 UTC (rev 2460)
@@ -0,0 +1,32 @@
+BenchmarkSRPlots<-function(R=NULL,ylab = NULL,xlab = NULL,lwd = 2,pch = 1,cex = 1,avgSR = NULL,columns = NULL,...){
+
+
+ if(!is.null(R)){
+ x = checkData(R)
+ columns = ncol(x)
+ avgSR = mean(SharpeRatio(R))
+ }
+ else{
+ if(is.null(avgSR) | is.null(S)){
+ stop("The average SR and the number of strategies should not be NULL")
+ }
+
+ }
+ 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))
+
+ rho = seq(0,1,length.out=30)
+ SR_B = avgSR*sqrt(columns/(1+(columns-1)*rho))
+ df1<-data.frame(x=rho,y=SR_B)
+ df1$model<-"A"
+ df2<-data.frame(x=corr_avg[1,1],y=BenchmanrkSR(R))
+ df2$model<-"B"
+ dfc<-rbind(df1,df2)
+ ggplot(dfc,aes(x,y,group=model)) +geom_point()+geom_line()+xlab("Correlation")+ylab("Benchmark Sharpe Ratio")+ggtitle("Benchmark SR vs Correlation")
+}
Modified: pkg/PerformanceAnalytics/sandbox/pulkit/week2/vignette/SharepRatioEfficientFrontier.Rnw
===================================================================
--- pkg/PerformanceAnalytics/sandbox/pulkit/week2/vignette/SharepRatioEfficientFrontier.Rnw 2013-06-28 03:56:06 UTC (rev 2459)
+++ pkg/PerformanceAnalytics/sandbox/pulkit/week2/vignette/SharepRatioEfficientFrontier.Rnw 2013-06-28 14:33:44 UTC (rev 2460)
@@ -73,7 +73,7 @@
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]}
+\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)
More information about the Returnanalytics-commits
mailing list