[Returnanalytics-commits] r2618 - in pkg/PerformanceAnalytics/sandbox/Shubhankit: Week1/Code Week4/Code

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Jul 22 12:38:54 CEST 2013


Author: shubhanm
Date: 2013-07-22 12:38:54 +0200 (Mon, 22 Jul 2013)
New Revision: 2618

Added:
   pkg/PerformanceAnalytics/sandbox/Shubhankit/Week1/Code/Return.ModGeltner.R
   pkg/PerformanceAnalytics/sandbox/Shubhankit/Week1/Code/Rplots.pdf
Modified:
   pkg/PerformanceAnalytics/sandbox/Shubhankit/Week1/Code/GLMSmoothIndex.R
   pkg/PerformanceAnalytics/sandbox/Shubhankit/Week1/Code/LoSharpe.R
   pkg/PerformanceAnalytics/sandbox/Shubhankit/Week4/Code/AcarSim.R.R
Log:
Added  Geltner Return Function ( Test and Implement + Literature)

Modified : Week 4 Acar Sim, GLM Smooth + Lo Sharpe (Added Literature, improved code readability and minor modification for speeding up computation)

Vignette for Week 1: Status : Complemeting for all the now completed Functions 
 

Modified: pkg/PerformanceAnalytics/sandbox/Shubhankit/Week1/Code/GLMSmoothIndex.R
===================================================================
--- pkg/PerformanceAnalytics/sandbox/Shubhankit/Week1/Code/GLMSmoothIndex.R	2013-07-22 01:18:35 UTC (rev 2617)
+++ pkg/PerformanceAnalytics/sandbox/Shubhankit/Week1/Code/GLMSmoothIndex.R	2013-07-22 10:38:54 UTC (rev 2618)
@@ -1,11 +1,26 @@
-#This measure is well known in the
-#industrial organization literature as the Herfindahl index, a measure of the
-#concentration of firms in a given industry where yj represents the market share of
-#firm j: Because yjA½0; 1  ; x is also confined to the unit interval, and is minimized when
-#all the yj's are identical, which implies a value of 1=ðk þ 1Þ for x; and is maximized
-#when one coefficient is 1 and the rest are 0, in which case x ¼ 1: In the context of
-##smoothed returns, a lower value of x implies more smoothing, and the upper bound
-#of 1 implies no smoothing, hence we shall refer to x as a ''smoothingindex' '.
+#'@title Getmansky Lo Markov Smoothing Index Parameter
+#'@description
+#A useful summary statistic for measuring the concentration of weights is
+# a sum of square of Moving Average lag coefficient.
+# This measure is well known in the industrial organization literature as the 
+# Herfindahl index, a measure of the concentration of firms in a given industry. 
+# The index is maximized when one coefficient is 1 and the rest are 0, in which case x ¼ 1: In the context of
+#smoothed returns, a lower value of x implies more smoothing, and the upper bound
+#of 1 implies no smoothing,  hence x is reffered as a ''smoothingindex' '.
+#' 
+#' @param R an xts, vector, matrix, data frame, timeSeries or zoo object of
+#' asset returns
+#' @author R
+#' @references "An econometric model of serial correlation and illiquidity in 
+#' hedge fund returns" Mila Getmansky1, Andrew W. Lo*, Igor Makarov
+#' 
+#' @keywords ts multivariate distribution models non-iid 
+#' @examples
+#' 
+#' data(edhec)
+#' head(GLMSmoothIndex(edhec)
+#' 
+#' @export
 GLMSmoothIndex<-
   function(R = NULL, ...)
   {
@@ -38,21 +53,21 @@
             result.df = cbind(result.df, nextcol)
           }
         }
+      rownames(result.df)= paste("GLM Smooth Index")
+      
         return(result.df)
       
     }  
-    
-    
-    ###############################################################################
-    # R (http://r-project.org/) Econometrics for Performance and Risk Analysis
-    #
-    # Copyright (c) 2004-2012 Peter Carl and Brian G. Peterson
-    #
-    # This R package is distributed under the terms of the GNU Public License (GPL)
-    # for full details see the file COPYING
-    #
-    # $Id: Return.Geltner.R 2163 2012-07-16 00:30:19Z braverock $
-    #
-    ###############################################################################
-    
-  }
\ No newline at end of file
+  }
+
+###############################################################################
+# R (http://r-project.org/) Econometrics for Performance and Risk Analysis
+#
+# Copyright (c) 2004-2012 Peter Carl and Brian G. Peterson
+#
+# This R package is distributed under the terms of the GNU Public License (GPL)
+# for full details see the file COPYING
+#
+# $Id: GLMSmoothIndex.R 2163 2012-07-16 00:30:19Z braverock $
+#
+###############################################################################

Modified: pkg/PerformanceAnalytics/sandbox/Shubhankit/Week1/Code/LoSharpe.R
===================================================================
--- pkg/PerformanceAnalytics/sandbox/Shubhankit/Week1/Code/LoSharpe.R	2013-07-22 01:18:35 UTC (rev 2617)
+++ pkg/PerformanceAnalytics/sandbox/Shubhankit/Week1/Code/LoSharpe.R	2013-07-22 10:38:54 UTC (rev 2618)
@@ -1,65 +1,48 @@
-#' calculate Geltner liquidity-adjusted return series
+#'@title Andrew Lo Sharpe Ratio
+#'@description
+#' Although the Sharpe ratio has become part of the canon of modern financial 
+#' analysis, its applications typically do not account for the fact that it is an
+#' estimated quantity, subject to estimation errors that can be substantial in 
+#' some cases.
 #' 
-#' David Geltner developed a method to remove estimating or liquidity bias in
-#' real estate index returns.  It has since been applied with success to other
-#' return series that show autocorrelation or illiquidity effects.
+#' Many studies have documented various violations of the assumption of 
+#' IID returns for financial securities.
 #' 
-#' The theory is that by correcting for autocorrelation, you are uncovering a
-#' "true" return from a series of observed returns that contain illiquidity or
-#' manual pricing effects.
-#' 
-#' The Geltner autocorrelation adjusted return series may be calculated via:
-#' 
-#' \deqn{ }{Geltner.returns = [R(t) - R(t-1)*acf(R(t-1))]/1-acf(R(t-1)) }\deqn{
-#' R_{G}=\frac{R_{t}-(R_{t-1}\cdot\rho_{1})}{1-\rho_{1}} }{Geltner.returns =
-#' [R(t) - R(t-1)*acf(R(t-1))]/1-acf(R(t-1)) }
-#' 
-#' where \eqn{\rho_{1}}{acf(R(t-1))} is the first-order autocorrelation of the
-#' return series \eqn{R_{a}}{Ra} and \eqn{R_{t}}{R(t)} is the return of
-#' \eqn{R_{a}}{Ra} at time \eqn{t} and \eqn{R_{t-1}}{R(t-1)} is the one-period
-#' lagged return.
-#' 
+#' Under the assumption of stationarity,a version of the Central Limit Theorem can 
+#' still be  applied to the estimator .
 #' @param Ra an xts, vector, matrix, data frame, timeSeries or zoo object of
-#' asset returns
+#' daily asset returns
+#' @param Rf an xts, vector, matrix, data frame, timeSeries or zoo object of
+#' annualized Risk Free Rate
+#' @param q Number of autocorrelated lag periods. Taken as 3 (Default)
 #' @param \dots any other passthru parameters
-#' @author Brian Peterson
-#' @references "Edhec Funds of Hedge Funds Reporting Survey : A Return-Based
-#' Approach to Funds of Hedge Funds Reporting",Edhec Risk and Asset Management
-#' Research Centre, January 2005,p. 27
+#' @author R
+#' @references "The Statistics of Sharpe Ratios" Andrew. W. Lo
 #' 
-#' Geltner, David, 1991, Smoothing in Appraisal-Based Returns, Journal of Real
-#' Estate Finance and Economics, Vol.4, p.327-345.
-#' 
-#' Geltner, David, 1993, Estimating Market Values from Appraised Values without
-#' Assuming an Efficient Market, Journal of Real Estate Research, Vol.8,
-#' p.325-345.
-#' @keywords ts multivariate distribution models
+#' @keywords ts multivariate distribution models non-iid 
 #' @examples
 #' 
-#' data(managers)
-#' head(Return.Geltner(managers[,1:3]),n=20)
+#' data(edhec)
+#' head(LoSharpe(edhec,0,3)
 #' 
 #' @export
 LoSharpe <-
-  function (Ra,Rf = 0,q = 0, ...)
+  function (Ra,Rf = 0,q = 3, ...)
   { # @author Brian G. Peterson, Peter Carl
+   
     
-    # Description:
-    # Geltner Returns came from real estate where they are used to uncover a
-    # liquidity-adjusted return series.
-    
-    # Ra    return vector
-    
     # Function:
     R = checkData(Ra, method="xts")
     # Get dimensions and labels
     columns.a = ncol(R)
     columnnames.a = colnames(R)
+    # Time used for daily Return manipulations
     Time= 252*nyears(edhec)
     clean.lo <- function(column.R,q) {
       # compute the lagged return series
       gamma.k =matrix(0,q)
       mu = sum(column.R)/(Time)
+      Rf= Rf/(Time)
       for(i in 1:q){
       lagR = lag(column.R, k=i)
       # compute the Momentum Lagged Values
@@ -93,7 +76,6 @@
   
     
     # RESULTS:
- #   return(reclass(geltner,match.to=Ra))
     
   }
 
@@ -105,6 +87,6 @@
 # This R package is distributed under the terms of the GNU Public License (GPL)
 # for full details see the file COPYING
 #
-# $Id: Return.Geltner.R 2163 2012-07-16 00:30:19Z braverock $
+# $Id: LoSharpe.R 
 #
 ###############################################################################

Added: pkg/PerformanceAnalytics/sandbox/Shubhankit/Week1/Code/Return.ModGeltner.R
===================================================================
--- pkg/PerformanceAnalytics/sandbox/Shubhankit/Week1/Code/Return.ModGeltner.R	                        (rev 0)
+++ pkg/PerformanceAnalytics/sandbox/Shubhankit/Week1/Code/Return.ModGeltner.R	2013-07-22 10:38:54 UTC (rev 2618)
@@ -0,0 +1,90 @@
+#'@title The Noiseless Stationary Transfer Function Model of Appriasal Smoothing
+#' @description calculate Geltner liquidity-adjusted return series
+#' David Geltner developed a method to remove estimating or liquidity bias in
+#' real estate index returns.  It has since been applied with success to other
+#' return series that show autocorrelation or illiquidity effects.
+#' 
+#' The theory is that by correcting for autocorrelation, you are uncovering a
+#' "true" return from a series of observed returns that contain illiquidity or
+#' manual pricing effects.
+#' 
+#' The Geltner autocorrelation adjusted return series may be calculated via:
+#' 
+#' @param Ra an xts, vector, matrix, data frame, timeSeries or zoo object of
+#' asset returns
+#' @param q number of lag factors
+#' @param \dots any other passthru parameters
+#' @author Brian Peterson
+#' @references "Edhec Funds of Hedge Funds Reporting Survey : A Return-Based
+#' Approach to Funds of Hedge Funds Reporting",Edhec Risk and Asset Management
+#' Research Centre, January 2005,p. 27
+#' 
+#' Geltner, David, 1991, Smoothing in Appraisal-Based Returns, Journal of Real
+#' Estate Finance and Economics, Vol.4, p.327-345.
+#' 
+#' Geltner, David, 1993, Estimating Market Values from Appraised Values without
+#' Assuming an Efficient Market, Journal of Real Estate Research, Vol.8,
+#' p.325-345.
+#' @keywords ts multivariate distribution models
+#' @examples
+#' 
+#' data(managers)
+#' head(Return.Geltner(managers[,1:3]),n=20)
+#' 
+#' @export
+Return.ModGeltner <-
+  function (Ra,q=3, ...)
+  { # @author Brian G. Peterson, Peter Carl
+    
+    # Description:
+    # Geltner Returns came from real estate where they are used to uncover a
+    # liquidity-adjusted return series.
+    
+    # Ra    return vector
+    
+    # Function:
+    R = checkData(Ra, method="xts")
+    # Get dimensions and labels
+    columns.a = ncol(R)
+    columnnames.a = colnames(R)
+    
+    clean.modgeltner <- function(column.R,q=3) {
+      # compute the lagged return series
+      #lagR = lag(column.R, k=1)
+      # compute the first order autocorrelation
+      f_acf = as.numeric(acf(as.numeric(column.R), plot = FALSE)[1:q][[1]])
+      # now calculate and return the Geltner series
+      column.geltner = column.R
+      for(i in 1:q){
+      column.geltner = (column.geltner- lag(column.R, k=i)*f_acf[q])
+      }
+      column.geltner= column.geltner/sum(f_acf)
+      }
+    
+    for(column.a in 1:columns.a) { # for each asset passed in as R
+      # clean the data and get rid of NAs
+      column.geltner = na.skip(R[,column.a], clean.modgeltner)
+      
+      if(column.a == 1)  { geltner = column.geltner }
+      else { geltner = cbind (geltner, column.geltner) }
+      
+    }
+    
+    colnames(geltner) = columnnames.a
+    
+    # RESULTS:
+    return(reclass(geltner,match.to=Ra))
+    
+  }
+
+###############################################################################
+# R (http://r-project.org/) Econometrics for Performance and Risk Analysis
+#
+# Copyright (c) 2004-2012 Peter Carl and Brian G. Peterson
+#
+# This R package is distributed under the terms of the GNU Public License (GPL)
+# for full details see the file COPYING
+#
+# $Id: Return.Geltner.R 2163 2012-07-16 00:30:19Z braverock $
+#
+###############################################################################

Added: pkg/PerformanceAnalytics/sandbox/Shubhankit/Week1/Code/Rplots.pdf
===================================================================
(Binary files differ)


Property changes on: pkg/PerformanceAnalytics/sandbox/Shubhankit/Week1/Code/Rplots.pdf
___________________________________________________________________
Added: svn:mime-type
   + application/octet-stream

Modified: pkg/PerformanceAnalytics/sandbox/Shubhankit/Week4/Code/AcarSim.R.R
===================================================================
--- pkg/PerformanceAnalytics/sandbox/Shubhankit/Week4/Code/AcarSim.R.R	2013-07-22 01:18:35 UTC (rev 2617)
+++ pkg/PerformanceAnalytics/sandbox/Shubhankit/Week4/Code/AcarSim.R.R	2013-07-22 10:38:54 UTC (rev 2618)
@@ -3,9 +3,7 @@
 # We have simulated cash flows over a period of 36 monthly returns and measured maximum 
 #drawdown for varied levels of annualised return divided by volatility varying from minus
 # two to two by step of 0.1. The process has been repeated six thousand times.
-AcarSim <-
-  function ()
-{
+
 mu=mean(Return.annualized(edhec))
 monthly=(1+mu)^(1/12)-1
 sig=StdDev.annualized(edhec[,1])[1];
@@ -32,9 +30,8 @@
     
       r[j,2:37]=monthly+sig*dz
     
-    ddown[j,i]= ES((r[j,]))/monthly
+    ddown[j,i]= ES((r[j,]))
 }
 }
 plot(ddown[1,])
 
-}
\ No newline at end of file



More information about the Returnanalytics-commits mailing list