[Returnanalytics-commits] r2568 - in pkg/PerformanceAnalytics/sandbox/Shubhankit/Week1: . Code Tests Vignette

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sun Jul 14 14:57:39 CEST 2013


Author: shubhanm
Date: 2013-07-14 14:57:39 +0200 (Sun, 14 Jul 2013)
New Revision: 2568

Added:
   pkg/PerformanceAnalytics/sandbox/Shubhankit/Week1/Code/
   pkg/PerformanceAnalytics/sandbox/Shubhankit/Week1/Code/GLMSmoothIndex.R
   pkg/PerformanceAnalytics/sandbox/Shubhankit/Week1/Code/LoSharpe.R
   pkg/PerformanceAnalytics/sandbox/Shubhankit/Week1/Code/LoSharpeRatio.R
   pkg/PerformanceAnalytics/sandbox/Shubhankit/Week1/Code/table.Return.GLM.R
   pkg/PerformanceAnalytics/sandbox/Shubhankit/Week1/Tests/
   pkg/PerformanceAnalytics/sandbox/Shubhankit/Week1/Tests/test_LoSharpe.R
   pkg/PerformanceAnalytics/sandbox/Shubhankit/Week1/Vignette/
   pkg/PerformanceAnalytics/sandbox/Shubhankit/Week1/Vignette/LoSharpe.Rnw
   pkg/PerformanceAnalytics/sandbox/Shubhankit/Week1/Vignette/LoSharpe.tex
Log:
Modified Function ,Added Tests and Documentation for Lo Sharpe

Added: pkg/PerformanceAnalytics/sandbox/Shubhankit/Week1/Code/GLMSmoothIndex.R
===================================================================
--- pkg/PerformanceAnalytics/sandbox/Shubhankit/Week1/Code/GLMSmoothIndex.R	                        (rev 0)
+++ pkg/PerformanceAnalytics/sandbox/Shubhankit/Week1/Code/GLMSmoothIndex.R	2013-07-14 12:57:39 UTC (rev 2568)
@@ -0,0 +1,58 @@
+#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' '.
+GLMSmoothIndex<-
+  function(R = NULL, ...)
+  {
+    columns = 1
+    columnnames = NULL
+    #Error handling if R is not NULL
+    if(!is.null(R)){
+      x = checkData(R)
+      columns = ncol(x)
+      n = nrow(x)
+      count = q
+        x=edhec
+        columns = ncol(x)
+        columnnames = colnames(x)
+        
+        # Calculate AutoCorrelation Coefficient
+        for(column in 1:columns) { # for each asset passed in as R
+          y = checkData(x[,column], method="vector", na.rm = TRUE)
+          sum = sum(abs(acf(y,plot=FALSE,lag.max=6)[[1]][2:7]));
+          acflag6 = acf(y,plot=FALSE,lag.max=6)[[1]][2:7]/sum;
+          values = sum(acflag6*acflag6)
+          
+          if(column == 1) {
+            result.df = data.frame(Value = values)
+            colnames(result.df) = columnnames[column]
+          }
+          else {
+            nextcol = data.frame(Value = values)
+            colnames(nextcol) = columnnames[column]
+            result.df = cbind(result.df, nextcol)
+          }
+        }
+        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

Added: pkg/PerformanceAnalytics/sandbox/Shubhankit/Week1/Code/LoSharpe.R
===================================================================
--- pkg/PerformanceAnalytics/sandbox/Shubhankit/Week1/Code/LoSharpe.R	                        (rev 0)
+++ pkg/PerformanceAnalytics/sandbox/Shubhankit/Week1/Code/LoSharpe.R	2013-07-14 12:57:39 UTC (rev 2568)
@@ -0,0 +1,110 @@
+#' 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:
+#' 
+#' \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.
+#' 
+#' @param Ra an xts, vector, matrix, data frame, timeSeries or zoo object of
+#' asset returns
+#' @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
+LoSharpe <-
+  function (Ra,Rf = 0,q = 0, ...)
+  { # @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= 252*nyears(edhec)
+    clean.lo <- function(column.R,q) {
+      # compute the lagged return series
+      gamma.k =matrix(0,q)
+      mu = sum(column.R)/(Time)
+      for(i in 1:q){
+      lagR = lag(column.R, k=i)
+      # compute the Momentum Lagged Values
+            gamma.k[i]= (sum(((column.R-mu)*(lagR-mu)),na.rm=TRUE))
+      }
+      return(gamma.k)
+      }
+    neta.lo <- function(pho.k,q) {
+      # compute the lagged return series
+      sumq = 0
+      for(j in 1:q){
+        sumq = sumq+ (q-j)*pho.k[j]
+      }
+      return(q/(sqrt(q+2*sumq)))
+    }
+    for(column.a in 1:columns.a) { # for each asset passed in as R
+      # clean the data and get rid of NAs
+      mu = sum(R[,column.a])/(Time)
+      sig=sqrt(((R[,column.a]-mu)^2/(Time)))
+      pho.k = clean.lo(R[,column.a],q)/(as.numeric(sig[1]))
+      netaq=neta.lo(pho.k,q)
+      column.lo = (netaq*((mu-Rf)/as.numeric(sig[1])))
+      
+      if(column.a == 1)  { lo = column.lo }
+      else { lo = cbind (lo, column.lo) }
+      
+    }
+    colnames(lo) = columnnames.a
+    rownames(lo)= paste("Lo Sharpe Ratio")
+    return(lo)
+  
+    
+    # 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/LoSharpeRatio.R
===================================================================
--- pkg/PerformanceAnalytics/sandbox/Shubhankit/Week1/Code/LoSharpeRatio.R	                        (rev 0)
+++ pkg/PerformanceAnalytics/sandbox/Shubhankit/Week1/Code/LoSharpeRatio.R	2013-07-14 12:57:39 UTC (rev 2568)
@@ -0,0 +1,70 @@
+LoSharpeRatio<-
+  function(R = NULL,Rf=0.,q = 0., ...)
+  {
+columns = 1
+columnnames = NULL
+#Error handling if R is not NULL
+if(!is.null(R)){
+  x = checkData(R)
+  columns = ncol(x)
+  n = nrow(x)
+  
+  if(q==0){
+    stop("AutoCorrelation Coefficient Should be greater than 0")
+    
+  }
+  else{
+    # A potfolio is constructed by applying the weights
+    
+    count = q
+    columns = ncol(x)
+    columnnames = colnames(x)
+    
+    # Calculate AutoCorrelation Coefficient
+    for(column in 1:columns) { # for each asset passed in as R
+      y = checkData(edhec[,column], method="vector", na.rm = TRUE)
+      
+      acflag6 = acf(y,plot=FALSE,lag.max=6)[[1]][2:7]
+      LjungBox =  Box.test(y,type="Ljung-Box",lag=q)
+      values = c(acflag6, LjungBox$p.value)
+      # values = base::round(as.numeric(values),digits)
+      
+      if(column == 1) {
+        result.df = data.frame(Value = values)
+        colnames(result.df) = columnnames[column]
+      }
+      else {
+        nextcol = data.frame(Value = values)
+        colnames(nextcol) = columnnames[column]
+        result.df = cbind(result.df, nextcol)
+      }
+    }
+    # Calculate Neta's
+    for(column in 1:columns) {
+      sum = 0
+      z = checkData(edhec[,column], method="vector", na.rm = TRUE)
+    for(q in 1:(q-1) )
+    {
+      sum = sum + (count-q)*result.df[column,q]
+    
+    }
+      
+      netaq = count/(sqrt(count+2*sum))
+      if(column == 1) {
+        netacol = data.frame(Value = netaq)
+        colnames(netacol) = columnnames[column]
+      }
+      else {
+          nextcol = data.frame(Value = netaq)
+        colnames(nextcol) = columnnames[column]
+        netacol = cbind(netacol, nextcol)
+      }
+      
+    }
+    shrp = SharpeRatio(x, Rf, FUN="VaR" , method="gaussian")
+    results = Shrp*netacol
+    colnames(results) = colnames(x)
+    return(results)
+  }
+  }  
+}
\ No newline at end of file

Added: pkg/PerformanceAnalytics/sandbox/Shubhankit/Week1/Code/table.Return.GLM.R
===================================================================
--- pkg/PerformanceAnalytics/sandbox/Shubhankit/Week1/Code/table.Return.GLM.R	                        (rev 0)
+++ pkg/PerformanceAnalytics/sandbox/Shubhankit/Week1/Code/table.Return.GLM.R	2013-07-14 12:57:39 UTC (rev 2568)
@@ -0,0 +1 @@
+rff
\ No newline at end of file

Added: pkg/PerformanceAnalytics/sandbox/Shubhankit/Week1/Tests/test_LoSharpe.R
===================================================================
--- pkg/PerformanceAnalytics/sandbox/Shubhankit/Week1/Tests/test_LoSharpe.R	                        (rev 0)
+++ pkg/PerformanceAnalytics/sandbox/Shubhankit/Week1/Tests/test_LoSharpe.R	2013-07-14 12:57:39 UTC (rev 2568)
@@ -0,0 +1,9 @@
+library(RUnit)
+library(PerformanceAnalytics)
+data(edhec)
+
+test_LoSharpe<-function(){
+  
+  checkEqualsNumeric(LoSharpe(edhec,0,3)[1],0.1366338,tolerance = 1.0e-6)
+  
+}
\ No newline at end of file

Added: pkg/PerformanceAnalytics/sandbox/Shubhankit/Week1/Vignette/LoSharpe.Rnw
===================================================================
--- pkg/PerformanceAnalytics/sandbox/Shubhankit/Week1/Vignette/LoSharpe.Rnw	                        (rev 0)
+++ pkg/PerformanceAnalytics/sandbox/Shubhankit/Week1/Vignette/LoSharpe.Rnw	2013-07-14 12:57:39 UTC (rev 2568)
@@ -0,0 +1,46 @@
+\documentclass[12pt,letterpaper,english]{article}
+\usepackage{times}
+\usepackage[T1]{fontenc}
+\IfFileExists{url.sty}{\usepackage{url}}
+                      {\newcommand{\url}{\texttt}}
+
+\usepackage{babel}
+\usepackage{Rd}
+
+\usepackage{Sweave}
+\SweaveOpts{engine=R,eps = FALSE}
+\begin{document}
+\SweaveOpts{concordance=TRUE}
+
+\title{ Lo Sharpe Ratio }
+
+% \keywords{Lo Sharpe Ratio,GLM Smooth Index,GLM Return Table}
+
+\makeatletter
+\makeatother
+\maketitle
+
+\begin{abstract}
+
+    This vignette gives an overview of the Lo Sharpe Ratio which have addressed the issue of IID in financial time series data.
+\end{abstract}
+
+<<echo = FALSE >>=
+library(PerformanceAnalytics)
+data(edhec)
+
+\section{Lo Sharpe Ratio}
+ Given a predefined benchmark Sharpe ratio $SR^\ast$ , the observed Sharpe ratio $\hat{SR}$  can be expressed in terms of autocorrelated coefficients as
+ 
+ \deqn{ \hat{SR} (q) - SR(q)= Normal Distribution(0,V_{GMM}(q)) }
+ 
+The estimator for the Sharpe ratio then follows directly:
+\deqn{  \hat{SR} (q) =  \hat{ \eta } (q)  * Sharpe Ratio}
+\deqn{  \hat{ \eta } (q)= q/\sqrt{q +  \sum_k^n  \rho  } }
+
+<<>>=
+data(edhec)
+LoSharpe(edhec)
+@
+
+\end{document}

Added: pkg/PerformanceAnalytics/sandbox/Shubhankit/Week1/Vignette/LoSharpe.tex
===================================================================
--- pkg/PerformanceAnalytics/sandbox/Shubhankit/Week1/Vignette/LoSharpe.tex	                        (rev 0)
+++ pkg/PerformanceAnalytics/sandbox/Shubhankit/Week1/Vignette/LoSharpe.tex	2013-07-14 12:57:39 UTC (rev 2568)
@@ -0,0 +1,27 @@
+\documentclass[12pt,letterpaper,english]{article}
+\usepackage{times}
+\usepackage[T1]{fontenc}
+\IfFileExists{url.sty}{\usepackage{url}}
+                      {\newcommand{\url}{\texttt}}
+
+\usepackage{babel}
+\usepackage{Rd}
+
+\usepackage{Sweave}
+
+\begin{document}
+\input{LoSharpe-concordance}
+
+\title{ Lo Sharpe Ratio }
+
+% \keywords{Lo Sharpe Ratio,GLM Smooth Index,GLM Return Table}
+
+\makeatletter
+\makeatother
+\maketitle
+
+\begin{abstract}
+
+    This vignette gives an overview of the Lo Sharpe Ratio, GLM Smoothing Index and Returns, which have addressed the issue of IID in financial time series data.
+\end{abstract}
+



More information about the Returnanalytics-commits mailing list