[Returnanalytics-commits] r3090 - pkg/PortfolioAnalytics/sandbox/symposium2013/R
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Fri Sep 13 18:18:30 CEST 2013
Author: peter_carl
Date: 2013-09-13 18:18:30 +0200 (Fri, 13 Sep 2013)
New Revision: 3090
Added:
pkg/PortfolioAnalytics/sandbox/symposium2013/R/page.Distributions.R
Log:
- needs to be added to PerfA
Added: pkg/PortfolioAnalytics/sandbox/symposium2013/R/page.Distributions.R
===================================================================
--- pkg/PortfolioAnalytics/sandbox/symposium2013/R/page.Distributions.R (rev 0)
+++ pkg/PortfolioAnalytics/sandbox/symposium2013/R/page.Distributions.R 2013-09-13 16:18:30 UTC (rev 3090)
@@ -0,0 +1,44 @@
+
+# Histogram, QQPlot and ECDF plots aligned by scale for comparison
+page.Distributions <- function (R, ...) {
+ require(PerformanceAnalytics)
+ op <- par(no.readonly = TRUE)
+ # c(bottom, left, top, right)
+ par(oma = c(5,0,2,1), mar=c(0,0,0,3))
+ layout(matrix(1:(4*NCOL(R)), ncol=4, byrow=TRUE), widths=rep(c(.6,1,1,1),NCOL(R)))
+ # layout.show(n=21)
+ chart.mins=min(R, na.rm=TRUE)
+ chart.maxs=max(R, na.rm=TRUE)
+ means=colMeans(R, na.rm=TRUE)
+ row.names = sapply(colnames(R), function(x) paste(strwrap(x,10), collapse = "\n"), USE.NAMES=FALSE)
+ for(i in 1:NCOL(R)){
+ if(i==NCOL(R)){
+ plot.new()
+ text(x=1, y=0.5, adj=c(1,0.5), labels=row.names[i], cex=1.1)
+ chart.Histogram(R[,i], main="", xlim=c(chart.mins, chart.maxs),
+ breaks=seq(round(chart.mins, digits=2)-0.01, round(chart.maxs, digits=2)+0.01, by=0.01), note.lines=boxplot.stats(as.vector(R[,i]))$stats, note.color="#005AFF",
+ show.outliers=TRUE, methods=c("add.normal"), colorset =
+ c("black", "#00008F", "#005AFF", "#23FFDC", "#ECFF13", "#FF4A00", "#800000"))
+ abline(v=0, col="darkgray", lty=2)
+ chart.QQPlot(R[,i], main="", pch=20, envelope=0.95, col=c(1,"#005AFF"), ylim=c(chart.mins, chart.maxs))
+ abline(v=0, col="darkgray", lty=2)
+ chart.ECDF(R[,i], main="", xlim=c(chart.mins, chart.maxs), lwd=2)
+ abline(v=0, col="darkgray", lty=2)
+ }
+ else{
+ plot.new()
+ text(x=1, y=0.5, adj=c(1,0.5), labels=row.names[i], cex=1.1)
+ chart.Histogram(R[,i], main="", xlim=c(chart.mins, chart.maxs),
+ breaks=seq(round(chart.mins, digits=2)-0.01, round(chart.maxs, digits=2)+0.01, by=0.01), note.lines=boxplot.stats(as.vector(R[,i]))$stats, note.color="#005AFF",
+ xaxis=FALSE, yaxis=FALSE, show.outliers=TRUE, methods=c("add.normal"), colorset =
+ c("black", "#00008F", "#005AFF", "#23FFDC", "#ECFF13", "#FF4A00", "#800000"))
+ abline(v=0, col="darkgray", lty=2)
+ chart.QQPlot(R[,i], main="", xaxis=FALSE, yaxis=FALSE, pch=20, envelope=0.95, col=c(1,"#005AFF"), ylim=c(chart.mins, chart.maxs))
+ abline(v=0, col="darkgray", lty=2)
+ chart.ECDF(R[,i], main="", xlim=c(chart.mins, chart.maxs), xaxis=FALSE, yaxis=FALSE, lwd=2)
+ abline(v=0, col="darkgray", lty=2)
+ }
+ }
+ par(op)
+}
+
More information about the Returnanalytics-commits
mailing list