[Uwgarp-commits] r110 - pkg/GARPFRM/sandbox

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sat Mar 8 15:46:11 CET 2014


Author: mllabovitz
Date: 2014-03-08 15:46:11 +0100 (Sat, 08 Mar 2014)
New Revision: 110

Modified:
   pkg/GARPFRM/sandbox/test_performance_measure.r
Log:
Performance measure R code with many of Ross Bennett's suggestions

Modified: pkg/GARPFRM/sandbox/test_performance_measure.r
===================================================================
--- pkg/GARPFRM/sandbox/test_performance_measure.r	2014-03-07 21:54:02 UTC (rev 109)
+++ pkg/GARPFRM/sandbox/test_performance_measure.r	2014-03-08 14:46:11 UTC (rev 110)
@@ -21,6 +21,9 @@
 # Number of securities to use is 
 numberOfSecurities = 3
 
+# Security Selection Method, randomSeq or serialSeq
+secSel = "serialSeq"
+
 # type of chaining in forming the aggregate return
 # If geometric is TRUE use geometric chaining if False use arithemetic chaining
 geometricB = TRUE
@@ -96,23 +99,32 @@
 if (numberOfSecurities>(nSec-2)) numberOfSecurities = nSec - 2
 cat('\n Number of Securities being used in portfolio = ',numberOfSecurities, '\n')
 
-# Random create a portfolio from the non-market non RF series
-# Get a normalized set of weights
-# Could set up the application to create a random portfolio from a subset or 
-# Input specific securities and weights
+# Security position numbers of securities in portfolio
+secNbrs = seq(1,numberOfSecurities)
+if(secSel=="randomSeq") secNbrs = sample.int(nSec, size = numberOfSecurities, replace = FALSE)
+
+cat('\n Selected Security position indicies')
+print(secNbrs)
+
 #
+# Created random wts from the non-market non RF series if selected
 if (randWts){
-  coefs = runif(nSec-2)
+  coefs = runif(numberOfSecurities)
   alphas = coefs/sum(coefs)
   sum(alphas)
 }  
 
+# Generate portfolio from selected securities and associated weigts
 if (equalWts) {
-  R.portfolio <- Return.portfolio(largecap.ts[, 1:numberOfSecurities],geometric=geometricB)  
+  R.portfolio <- Return.portfolio(largecap.ts[, secNbrs],geometric=geometricB)  
 } else {
-  R.portfolio = Return.portfolio(largecap.ts[, 1:numberOfSecurities],weights=alphas,geometric=geometricB) 
+  R.portfolio = Return.portfolio(largecap.ts[, secNbrs],weights=alphas,geometric=geometricB) 
 }
 
+# Print names of securities in portfolio
+cat('\n Securities in Portfolio')
+print(colnames(largecap.ts)[secNbrs]) 
+
 colnames(portfolio) ="PortRets"
 
 salient = matrix(data=c("Mean",mean(R.portfolio),mean(R.market),mean(rf),
@@ -218,7 +230,7 @@
 cat('\n Difference PA and hand computed Sharpe Ratio = ',as.numeric(shr) - as.numeric(shrHand),'\n')
 
 
-Measures = rbind(Measures,c("Sharpe Ratio",shr,"","","Sharpe Ratio Annualized",shrAnn,"",""))
+Measures = rbind(Measures,matrix(c("Sharpe Ratio",shr,"","","Sharpe Ratio Annualized",shrAnn,"",""),ncol=4,byrow=TRUE))
 
 # Compute Jensen's Alpha
 
@@ -279,11 +291,10 @@
 pValue = 2*(1-pt(tStat,nRow-2))
 cat('\n H0: alpha = 0, HA: alpha != 0  p-value: ',pValue,'\n')
 
-Measures = rbind(Measures,c("Jensen's Alpha",ja,"",""))
-Measures = rbind(Measures,c("Jensen's Alpha P Value",pValue,"",""))
+Measures = rbind(Measures,matrix(c("Jensen's Alpha",jaStatic,"","","Jensen's Alpha Annualized",jaHandA,"","",
+                                   "Jensen's Alpha P Value",pValue,"",""),ncol=4,byrow=TRUE))
 
 
-
 # Compute Tracking Error
 
    # PA computation of Tracking Error   
@@ -363,6 +374,9 @@
 Measures = rbind(Measures,c("Downside Deviation",dwn,"",""))
 Measures = rbind(Measures,c("Denominator DD",denomVal,"",""))
 Measures = rbind(Measures,c("Sortino Ratio",sr,"",""))
-Measures.df= as.data.frame(Measures,stringsAsFactors=FALSE)
+Measures.few = cbind(Measures[,1],substr(Measures[,2:4],1,8))
+Measures.few = rbind(Measures[1,],Measures.few[-1,])
 
+Measures.df= as.data.frame(Measures.few,stringsAsFactors=FALSE)
+
 print(Measures.df)



More information about the Uwgarp-commits mailing list