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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sun Feb 16 01:08:13 CET 2014


Author: mllabovitz
Date: 2014-02-16 01:08:13 +0100 (Sun, 16 Feb 2014)
New Revision: 85

Modified:
   pkg/GARPFRM/sandbox/test_performance_measure.r
Log:
Revision to form dataframe combining together the summary statistics for the time series and performance measures for the portfolio 

Modified: pkg/GARPFRM/sandbox/test_performance_measure.r
===================================================================
--- pkg/GARPFRM/sandbox/test_performance_measure.r	2014-02-15 00:07:22 UTC (rev 84)
+++ pkg/GARPFRM/sandbox/test_performance_measure.r	2014-02-16 00:08:13 UTC (rev 85)
@@ -3,6 +3,7 @@
 options(digits=3)
 data(crsp.short)
 stock_rets.df <- largecap.ts
+Measures = rep(NULL,4)
 
 # Definitioned/Constant variables
 relation = c("Less Than","Equal To","Greater Than")
@@ -28,12 +29,15 @@
 #Market Name in data set
 mrktDataName = "market"
 
-# Risk free rate name used in data set
+# Risk free rate name used in output
 RFName="Risk_Free_Rate"
 
 # Risk Free Name in data set
 rfDataName = "t90"
 
+Measures = rbind(Measures, c("Series Name",PortName,MrktName,RFName))
+colnames(Measures) = c("Measure","Portfolio","Market","RiskFree")
+
 # List column headers predominantly tickers/name of securities
 
 # Summarize the first and last data values corresponding to the first 5 dates for the first 5 returns.
@@ -84,6 +88,14 @@
 portfolio = returns.mat[,1:(nSec-2)]%*%as.vector(alphas)
 colnames(portfolio) ="PortRets"
 
+salient = matrix(data=c("Mean",mean(portfolio),mean(returns.mat[,ptrMkt]),mean(returns.mat[,ptrRF]),
+                   "Stdev",sd(portfolio),sd(returns.mat[,ptrMkt]),sd(returns.mat[,ptrRF]),
+                   "AnnuallyFrequency",rep(freQ,3),
+                   "Number of Samples",rep(nRow,3)),nrow=4,ncol=4,byrow=TRUE)
+
+Measures = rbind(Measures, salient)
+
+
 # Start to compute performance measures using performance analytic and as a check
 # compute from underlying formula
 
@@ -94,6 +106,8 @@
 beta = cov(portfolio[,1],returns.mat[,ptrMkt])/var(returns.mat[,ptrMkt])
 cat('\n Beta =',beta,', between the portfolio represented by ',PortName,' and the market represented by ',MrktName,' \n')
 
+Measures = rbind(Measures,c("Beta",beta,"",""))
+
 # Compute Treynor
 
    # Performance Analytics (PA) computation of Treynor for portfolio and market
@@ -111,8 +125,11 @@
 cat('\n PA computed for ',MrktName,' Treynor Ratio = ',trMarket,'\n')
 cat('\n Hand computed for ',MrktName,' Treynor Ratio = ',trHandM,'\n')
 
+Measures = rbind(Measures,c("Treynor Ratio",tr,trMarket,""))
+
    # Compare Treynor Ratio for market returns against Treynor Ratio for portfolio returns
 cat('\n Treynor Ratio of ',MrktName,' is ',relation[sign(trMarket - tr) + 2],' Treynor Ratio of ',PortName,'\n' )
+TR_Mrkt2Port = relation[sign(trMarket - tr) + 2]
 
 # Compute Sharpe
 
@@ -129,6 +146,8 @@
 cat('\n PA computed ',PortName,' Sharpe Ratio = ',shr,'\n')
 cat('\n Hand computed ',PortName,' Sharpe Ratio = ',shrHand,'\n')
 
+Measures = rbind(Measures,c("Sharpe Ratio",shr,"",""))
+
 # Compute Jensen's Alpha
 
    # Mean of risk free rate over sampling time series
@@ -164,9 +183,12 @@
 
    # t stat and pvalue under H0: alpha = 0 against HA: alpha != 0 
 tStat = jaHand/(analT1[1,2]*deltaCoef^0.5)
-pValue = pt(tStat,nRow-2)
-cat('\n H0: alpha = 0, HA: alpha != 0  p-value: ',2*(1-pValue),'\n')
+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,"",""))
+
 # Compute Tracking Error
 
    # PA computation of Tracking Error   
@@ -183,6 +205,8 @@
 cat('\n PA computed ',PortName,' Tracking Error = ',te,'\n')
 cat('\n Hand computed ', PortName,' Tracking Error = ',teHand,'\n')
 
+Measures = rbind(Measures,c("Tracking Error",te,"",""))
+
 # Compute Information Ratio
 
    # PA computation of Information Ratio
@@ -195,6 +219,8 @@
 cat('\n PA computed ',PortName,' Information Ratio = ',ir,'\n')
 cat('\n Hand computed ',PortName,' Information Ratio = ',irHand,'\n')
 
+Measures = rbind(Measures,c("Information Ratio",ir,"",""))
+
 # Compute Sortino Ratio (including Downside Deviation)
 
    # PA computation of Sortino Ratio
@@ -224,3 +250,10 @@
    # Output computation of Sortino Ratio
 cat('\n PA computed ',PortName,' Sortino Ratio = ',sr,'\n')
 cat('\n Hand computed ',PortName,' Sortino Ratio = ',srHand,'\n')
+
+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)
+
+print(Measures.df)



More information about the Uwgarp-commits mailing list