[Returnanalytics-commits] r2796 - in pkg/PerformanceAnalytics/sandbox/Shubhankit: . R Shubhankit Week1/Code man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Fri Aug 16 13:08:27 CEST 2013
Author: shubhanm
Date: 2013-08-16 13:08:26 +0200 (Fri, 16 Aug 2013)
New Revision: 2796
Added:
pkg/PerformanceAnalytics/sandbox/Shubhankit/DESCRIPTION
pkg/PerformanceAnalytics/sandbox/Shubhankit/NAMESPACE
pkg/PerformanceAnalytics/sandbox/Shubhankit/R/ACStdDev.annualized.R
pkg/PerformanceAnalytics/sandbox/Shubhankit/R/CDDopt.R
pkg/PerformanceAnalytics/sandbox/Shubhankit/R/CDrawdown.R
pkg/PerformanceAnalytics/sandbox/Shubhankit/R/CalmarRatio.Normalized.R
pkg/PerformanceAnalytics/sandbox/Shubhankit/R/EmaxDDGBM.R
pkg/PerformanceAnalytics/sandbox/Shubhankit/R/GLMSmoothIndex.R
pkg/PerformanceAnalytics/sandbox/Shubhankit/R/Return.GLM.R
pkg/PerformanceAnalytics/sandbox/Shubhankit/R/UnsmoothReturn.R
pkg/PerformanceAnalytics/sandbox/Shubhankit/R/chart.Autocorrelation.R
pkg/PerformanceAnalytics/sandbox/Shubhankit/R/maxDDGBM.R
pkg/PerformanceAnalytics/sandbox/Shubhankit/R/na.skip.R
pkg/PerformanceAnalytics/sandbox/Shubhankit/R/table.ComparitiveReturn.GLM.R
pkg/PerformanceAnalytics/sandbox/Shubhankit/R/table.UnsmoothReturn.R
pkg/PerformanceAnalytics/sandbox/Shubhankit/R/table.normDD.R
pkg/PerformanceAnalytics/sandbox/Shubhankit/Shubhankit.Rproj
pkg/PerformanceAnalytics/sandbox/Shubhankit/Shubhankit/
pkg/PerformanceAnalytics/sandbox/Shubhankit/Shubhankit/inst/
pkg/PerformanceAnalytics/sandbox/Shubhankit/Shubhankit/man/
pkg/PerformanceAnalytics/sandbox/Shubhankit/man/ACStdDev.annualized.Rd
pkg/PerformanceAnalytics/sandbox/Shubhankit/man/CalmarRatio.Rd
pkg/PerformanceAnalytics/sandbox/Shubhankit/man/Cdrawdown.Rd
pkg/PerformanceAnalytics/sandbox/Shubhankit/man/EmaxDDGBM.Rd
pkg/PerformanceAnalytics/sandbox/Shubhankit/man/GLMSmoothIndex.Rd
pkg/PerformanceAnalytics/sandbox/Shubhankit/man/Return.GLM.Rd
pkg/PerformanceAnalytics/sandbox/Shubhankit/man/chart.Autocorrelation.Rd
pkg/PerformanceAnalytics/sandbox/Shubhankit/man/table.ComparitiveReturn.GLM.Rd
pkg/PerformanceAnalytics/sandbox/Shubhankit/man/table.NormDD.Rd
pkg/PerformanceAnalytics/sandbox/Shubhankit/man/table.UnsmoothReturn.Rd
Modified:
pkg/PerformanceAnalytics/sandbox/Shubhankit/Week1/Code/GLMSmoothIndex.R
Log:
/man .Rd files
Added: pkg/PerformanceAnalytics/sandbox/Shubhankit/DESCRIPTION
===================================================================
--- pkg/PerformanceAnalytics/sandbox/Shubhankit/DESCRIPTION (rev 0)
+++ pkg/PerformanceAnalytics/sandbox/Shubhankit/DESCRIPTION 2013-08-16 11:08:26 UTC (rev 2796)
@@ -0,0 +1,53 @@
+Package: Shubhankit
+Type: Package
+Title: Econometric tools for performance and risk analysis.
+Version: 1.1.0
+Date: $Date: 2013-01-29 21:04:00 +0800 (Tue, 29 Jan 2013) $
+Author: Peter Carl, Brian G. Peterson
+Maintainer: Brian G. Peterson <brian at braverock.com>
+Description: Collection of econometric functions for
+ performance and risk analysis. This package aims to aid
+ practitioners and researchers in utilizing the latest
+ research in analysis of non-normal return streams. In
+ general, it is most tested on return (rather than
+ price) data on a regular scale, but most functions will
+ work with irregular return data as well, and increasing
+ numbers of functions will work with P&L or price data
+ where possible.
+Depends:
+ R (>= 2.14.0),
+ zoo,
+ xts (>= 0.8-9)
+Suggests:
+ Hmisc,
+ MASS,
+ tseries,
+ quadprog,
+ sn,
+ robustbase,
+ quantreg,
+ gplots,
+ ff
+License: GPL
+URL: http://r-forge.r-project.org/projects/returnanalytics/
+Copyright: (c) 2004-2012
+Contributors: Kris Boudt, Diethelm Wuertz, Eric Zivot, Matthieu Lestel
+Thanks: A special thanks for additional contributions from
+ Stefan Albrecht, Khahn Nygyen, Jeff Ryan,
+ Josh Ulrich, Sankalp Upadhyay, Tobias Verbeke,
+ H. Felix Wittmann, Ram Ahluwalia
+Collate:
+ 'GLMSmoothIndex.R'
+ 'chart.Autocorrelation.R'
+ 'ACStdDev.annualized.R'
+ 'CalmarRatio.Normalized.R'
+ 'na.skip.R'
+ 'Return.GLM.R'
+ 'table.ComparitiveReturn.GLM.R'
+ 'table.UnsmoothReturn.R'
+ 'UnsmoothReturn.R'
+ 'EmaxDDGBM.R'
+ 'maxDDGBM.R'
+ 'table.normDD.R'
+ 'CDDopt.R'
+ 'CDrawdown.R'
Added: pkg/PerformanceAnalytics/sandbox/Shubhankit/NAMESPACE
===================================================================
--- pkg/PerformanceAnalytics/sandbox/Shubhankit/NAMESPACE (rev 0)
+++ pkg/PerformanceAnalytics/sandbox/Shubhankit/NAMESPACE 2013-08-16 11:08:26 UTC (rev 2796)
@@ -0,0 +1,12 @@
+export(ACStdDev.annualized)
+export(CDrawdown)
+export(chart.Autocorrelation)
+export(EMaxDDGBM)
+export(GLMSmoothIndex)
+export(QP.Norm)
+export(Return.GLM)
+export(SterlingRatio.Normalized)
+export(table.ComparitiveReturn.GLM)
+export(table.EMaxDDGBM)
+export(table.NormDD)
+export(table.UnsmoothReturn)
Added: pkg/PerformanceAnalytics/sandbox/Shubhankit/R/ACStdDev.annualized.R
===================================================================
--- pkg/PerformanceAnalytics/sandbox/Shubhankit/R/ACStdDev.annualized.R (rev 0)
+++ pkg/PerformanceAnalytics/sandbox/Shubhankit/R/ACStdDev.annualized.R 2013-08-16 11:08:26 UTC (rev 2796)
@@ -0,0 +1,77 @@
+#' calculate a multiperiod or annualized Autocorrleation adjusted Standard Deviation
+#'
+#' @aliases sd.multiperiod sd.annualized StdDev.annualized
+#' @param x an xts, vector, matrix, data frame, timeSeries or zoo object of
+#' asset returns
+#' @param lag : number of autocorrelated lag factors inputted by user
+#' @param scale number of periods in a year (daily scale = 252, monthly scale =
+#' 12, quarterly scale = 4)
+#' @param \dots any other passthru parameters
+#' @author R
+#' @seealso \code{\link[stats]{sd}} \cr
+#' \url{http://wikipedia.org/wiki/inverse-square_law}
+#' @references Burghardt, G., and L. Liu, \emph{ It's the Autocorrelation, Stupid (November 2012) Newedge
+#' working paper.http://www.amfmblog.com/assets/Newedge-Autocorrelation.pdf \cr
+#' @keywords ts multivariate distribution models
+#' @examples
+#'
+#' data(edhec)
+#' ACsd.annualized(edhec,3)
+
+#'
+#' @export
+#' @rdname ACStdDev.annualized
+ACStdDev.annualized <- ACsd.annualized <- ACsd.multiperiod <-
+ function (R,lag=6, scale = NA, ...)
+ {
+ columns.a = ncol(R)
+ columnnames.a = colnames(R)
+ if(is.na(scale) && !xtsible(R))
+ stop("'x' needs to be timeBased or xtsible, or scale must be specified." )
+
+ if(is.na(scale)) {
+ freq = periodicity(R)
+ switch(freq$scale,
+ #kChec
+ minute = {stop("Data periodicity too high")},
+ hourly = {stop("Data periodicity too high")},
+ daily = {scale = 252},
+ weekly = {scale = 52},
+ monthly = {scale = 12},
+ quarterly = {scale = 4},
+ yearly = {scale = 1}
+ )
+ }
+
+ for(column.a in 1:columns.a) { # for each asset passed in as R
+ # clean the data and get rid of NAs
+ column.return = R[,column.a]
+ acf = as.numeric(acf(as.numeric(column.return), plot = FALSE)[1:lag][[1]])
+ coef= sum(acf*acf)
+ if(!xtsible(R) & is.na(scale))
+ {
+ stop("'x' needs to be timeBased or xtsible, or scale must be specified." )
+ }
+ else
+ {
+ if(column.a == 1) { result = as.numeric(StdDev.annualized(column.return))*(1+2*coef) }
+ else { result = cbind (result, as.numeric(StdDev.annualized(column.return))*(1+2*coef)) }
+ }
+ }
+ dim(result) = c(1,NCOL(R))
+ colnames(result) = colnames(R)
+ rownames(result) = "Autocorrelated Annualized Standard Deviation"
+ return(result)
+ }
+
+###############################################################################
+# R (http://r-project.org/) Econometrics for Performance and Risk Analysis
+#
+# Copyright (c) 2004-2013 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: ACStdDev.annualized.R
+#
+###############################################################################
Added: pkg/PerformanceAnalytics/sandbox/Shubhankit/R/CDDopt.R
===================================================================
--- pkg/PerformanceAnalytics/sandbox/Shubhankit/R/CDDopt.R (rev 0)
+++ pkg/PerformanceAnalytics/sandbox/Shubhankit/R/CDDopt.R 2013-08-16 11:08:26 UTC (rev 2796)
@@ -0,0 +1,24 @@
+cDDOpt = function(rmat, alpha=0.05, rmin=0, wmin=0, wmax=1, weight.sum=1)
+{
+ require(Rglpk)
+ n = ncol(rmat) # number of assets
+ s = nrow(rmat) # number of scenarios i.e. periods
+ averet = colMeans(rmat)
+ # creat objective vector, constraint matrix, constraint rhs
+ Amat = rbind(cbind(rbind(1,averet),matrix(data=0,nrow=2,ncol=s+1)),
+ cbind(rmat,diag(s),1))
+ objL = c(rep(0,n), as.numeric(Cdrawdown(rmat,.9)), -1)
+ bvec = c(weight.sum,rmin,rep(0,s))
+ # direction vector
+ dir.vec = c("==",">=",rep(">=",s))
+ # bounds on weights
+ bounds = list(lower = list(ind = 1:n, val = rep(wmin,n)),
+ upper = list(ind = 1:n, val = rep(wmax,n)))
+ res = Rglpk_solve_LP(obj=objL, mat=Amat, dir=dir.vec, rhs=bvec,
+ types=rep("C",length(objL)), max=T, bounds=bounds)
+ w = as.numeric(res$solution[1:n])
+ return(list(w=w,status=res$status))
+}
+#' Guy Yollin work
+#'
+#'
Added: pkg/PerformanceAnalytics/sandbox/Shubhankit/R/CDrawdown.R
===================================================================
--- pkg/PerformanceAnalytics/sandbox/Shubhankit/R/CDrawdown.R (rev 0)
+++ pkg/PerformanceAnalytics/sandbox/Shubhankit/R/CDrawdown.R 2013-08-16 11:08:26 UTC (rev 2796)
@@ -0,0 +1,73 @@
+#' Chekhlov Conditional Drawdown at Risk
+#'
+#' A new one-parameter family of risk measures called Conditional Drawdown (CDD) has
+#'been proposed. These measures of risk are functionals of the portfolio drawdown (underwater) curve considered in active portfolio management. For some value of the tolerance
+#' parameter, in the case of a single sample path, drawdown functional is de???ned as
+#'the mean of the worst 100% drawdowns. The CDD measure generalizes the
+#'notion of the drawdown functional to a multi-scenario case and can be considered as a
+#'generalization of deviation measure to a dynamic case. The CDD measure includes the
+#'Maximal Drawdown and Average Drawdown as its limiting cases.
+#'
+#' The model is focused on concept of drawdown measure which is in possession of all properties of a deviation measure,generalization of deviation measures to a dynamic case.Concept of risk profiling - Mixed Conditional Drawdown (generalization of CDD).Optimization techniques for CDD computation - reduction to linear programming (LP) problem. Portfolio optimization with constraint on Mixed CDD
+#' The model develops concept of drawdown measure by generalizing the notion
+#' of the CDD to the case of several sample paths for portfolio uncompounded rate
+#' of return.
+#' @param Ra return vector of the portfolio
+#' @param p confidence interval
+#' @author R Project
+#' @references DRAWDOWN MEASURE IN PORTFOLIO OPTIMIZATION,\emph{International Journal of Theoretical and Applied Finance}
+#' ,Fall 1994, 49-58.Vol. 8, No. 1 (2005) 13-58
+#' @keywords Conditional Drawdown models
+#' @examples
+#'
+#' library(PerformanceAnalytics)
+#' data(edhec)
+#' CDrawdown(edhec)
+#' @rdname Cdrawdown
+#' @export
+
+CDrawdown <-
+ function (R,p=0.90, ...)
+ {
+ y = checkData(R, method = "xts")
+ columns = ncol(y)
+ rows = nrow(y)
+ columnnames = colnames(y)
+ rownames = rownames(y)
+
+ for(column in 1:columns) {
+ x = y[,column]
+ drawdown = findDrawdowns(x)
+ threshold= ES(x,p)[1]
+ total = length(drawdown$return)
+ num = length(drawdown$return[drawdown$return>threshold])
+ cva1= (((num/total)-p)/(1-p))*threshold
+ cva2=sum(drawdown$return)/((1-p)*total)
+ z = c((cva1+cva2))
+ znames = c("Conditional Drawdown at Risk")
+ if(column == 1) {
+ resultingtable = data.frame(Value = z, row.names = znames)
+ }
+ else {
+ nextcolumn = data.frame(Value = z, row.names = znames)
+ resultingtable = cbind(resultingtable, nextcolumn)
+ }
+
+ }
+ colnames(resultingtable) = columnnames
+ #ans = base::round(resultingtable, digits)
+ #ans
+ resultingtable
+ }
+
+###############################################################################
+# 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: CDrawdown.R 2271 2012-09-02 01:56:23Z braverock $
+#
+###############################################################################
Added: pkg/PerformanceAnalytics/sandbox/Shubhankit/R/CalmarRatio.Normalized.R
===================================================================
--- pkg/PerformanceAnalytics/sandbox/Shubhankit/R/CalmarRatio.Normalized.R (rev 0)
+++ pkg/PerformanceAnalytics/sandbox/Shubhankit/R/CalmarRatio.Normalized.R 2013-08-16 11:08:26 UTC (rev 2796)
@@ -0,0 +1,137 @@
+#' calculate a Normalized Calmar or Sterling reward/risk ratio
+#'
+#' Normalized Calmar and Sterling Ratios are yet another method of creating a
+#' risk-adjusted measure for ranking investments similar to the
+#' \code{\link{SharpeRatio}}.
+#'
+#' Both the Normalized Calmar and the Sterling ratio are the ratio of annualized return
+#' over the absolute value of the maximum drawdown of an investment. The
+#' Sterling ratio adds an excess risk measure to the maximum drawdown,
+#' traditionally and defaulting to 10\%.
+#'
+#' It is also traditional to use a three year return series for these
+#' calculations, although the functions included here make no effort to
+#' determine the length of your series. If you want to use a subset of your
+#' series, you'll need to truncate or subset the input data to the desired
+#' length.
+#'
+#' Many other measures have been proposed to do similar reward to risk ranking.
+#' It is the opinion of this author that newer measures such as Sortino's
+#' \code{\link{UpsidePotentialRatio}} or Favre's modified
+#' \code{\link{SharpeRatio}} are both \dQuote{better} measures, and
+#' should be preferred to the Calmar or Sterling Ratio.
+#'
+#' @aliases Normalized.CalmarRatio Normalized.SterlingRatio
+#' @param R an xts, vector, matrix, data frame, timeSeries or zoo object of
+#' asset returns
+#' @param scale number of periods in a year (daily scale = 252, monthly scale =
+#' 12, quarterly scale = 4)
+#' @param excess for Sterling Ratio, excess amount to add to the max drawdown,
+#' traditionally and default .1 (10\%)
+#' @author Brian G. Peterson
+#' @seealso
+#' \code{\link{Return.annualized}}, \cr
+#' \code{\link{maxDrawdown}}, \cr
+#' \code{\link{SharpeRatio.modified}}, \cr
+#' \code{\link{UpsidePotentialRatio}}
+#' @references Bacon, Carl. \emph{Magdon-Ismail, M. and Amir Atiya, Maximum drawdown. Risk Magazine, 01 Oct 2004.
+#' @keywords ts multivariate distribution models
+#' @examples
+#'
+#' data(managers)
+#' Normalized.CalmarRatio(managers[,1,drop=FALSE])
+#' Normalized.CalmarRatio(managers[,1:6])
+#' Normalized.SterlingRatio(managers[,1,drop=FALSE])
+#' Normalized.SterlingRatio(managers[,1:6])
+#'
+#' @export
+#' @rdname CalmarRatio
+#' QP function fo calculation of Sharpe Ratio
+QP.Norm <- function (R, tau,scale = NA)
+{
+ Sharpe= as.numeric(SharpeRatio.annualized(edhec))
+return(.63519+(.5*log(tau))+log(Sharpe))
+}
+
+CalmarRatio.Normalized <- function (R, tau = 1,scale = NA)
+{ # @author Brian G. Peterson
+
+ # DESCRIPTION:
+ # Inputs:
+ # Ra: in this case, the function anticipates having a return stream as input,
+ # rather than prices.
+ # tau : scaled Time in Years
+ # scale: number of periods per year
+ # Outputs:
+ # This function returns a Calmar Ratio
+
+ # FUNCTION:
+
+ R = checkData(R)
+ if(is.na(scale)) {
+ freq = periodicity(R)
+ switch(freq$scale,
+ minute = {stop("Data periodicity too high")},
+ hourly = {stop("Data periodicity too high")},
+ daily = {scale = 252},
+ weekly = {scale = 52},
+ monthly = {scale = 12},
+ quarterly = {scale = 4},
+ yearly = {scale = 1}
+ )
+ }
+ Time = nyears(R)
+ annualized_return = Return.annualized(R, scale=scale)
+ drawdown = abs(maxDrawdown(R))
+ result = (annualized_return/drawdown)*(QP.Norm(R,Time)/QP.Norm(R,tau))*(tau/Time)
+ rownames(result) = "Normalized Calmar Ratio"
+ return(result)
+}
+
+#' @export
+#' @rdname CalmarRatio
+SterlingRatio.Normalized <-
+ function (R, tau=1,scale=NA, excess=.1)
+ { # @author Brian G. Peterson
+
+ # DESCRIPTION:
+ # Inputs:
+ # Ra: in this case, the function anticipates having a return stream as input,
+ # rather than prices.
+ # scale: number of periods per year
+ # Outputs:
+ # This function returns a Sterling Ratio
+
+ # FUNCTION:
+ Time = nyears(R)
+ R = checkData(R)
+ if(is.na(scale)) {
+ freq = periodicity(R)
+ switch(freq$scale,
+ minute = {stop("Data periodicity too high")},
+ hourly = {stop("Data periodicity too high")},
+ daily = {scale = 252},
+ weekly = {scale = 52},
+ monthly = {scale = 12},
+ quarterly = {scale = 4},
+ yearly = {scale = 1}
+ )
+ }
+ annualized_return = Return.annualized(R, scale=scale)
+ drawdown = abs(maxDrawdown(R)+excess)
+ result = annualized_return/drawdown*(QP.Norm(R,Time)/QP.Norm(R,tau))*(tau/Time)
+ rownames(result) = paste("Normalized Sterling Ratio (Excess = ", round(excess*100,0), "%)", sep="")
+ return(result)
+ }
+
+###############################################################################
+# R (http://r-project.org/) Econometrics for Performance and Risk Analysis
+#
+# Copyright (c) 2004-2013 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: CalmarRatioNormalized.R 1955 2012-05-23 16:38:16Z braverock $
+#
+###############################################################################
Added: pkg/PerformanceAnalytics/sandbox/Shubhankit/R/EmaxDDGBM.R
===================================================================
--- pkg/PerformanceAnalytics/sandbox/Shubhankit/R/EmaxDDGBM.R (rev 0)
+++ pkg/PerformanceAnalytics/sandbox/Shubhankit/R/EmaxDDGBM.R 2013-08-16 11:08:26 UTC (rev 2796)
@@ -0,0 +1,195 @@
+#' Expected Drawdown using Brownian Motion Assumptions
+#'
+#' Works on the model specified by Maddon-Ismail
+#'
+#'
+#'
+#' @param R an xts, vector, matrix, data frame, timeSeries or zoo object of
+#' asset returns
+
+#' @author R
+#' @keywords Expected Drawdown Using Brownian Motion Assumptions
+#' @rdname EmaxDDGBM
+#' @export
+table.EMaxDDGBM <-
+ function (R,digits =4)
+ {# @author
+
+ # DESCRIPTION:
+ # Downside Risk Summary: Statistics and Stylized Facts
+
+ # Inputs:
+ # R: a regular timeseries of returns (rather than prices)
+ # Output: Table of Estimated Drawdowns
+
+ y = checkData(R, method = "xts")
+ columns = ncol(y)
+ rows = nrow(y)
+ columnnames = colnames(y)
+ rownames = rownames(y)
+ T= nyears(y);
+
+ # for each column, do the following:
+ for(column in 1:columns) {
+ x = y[,column]
+ mu = Return.annualized(x, scale = NA, geometric = TRUE)
+ sig=StdDev(x)
+ gamma<-sqrt(pi/8)
+
+ if(mu==0){
+
+ Ed<-2*gamma*sig*sqrt(T)
+
+ }
+
+ else{
+
+ alpha<-mu*sqrt(T/(2*sig^2))
+
+ x<-alpha^2
+
+ if(mu>0){
+
+ mQp<-matrix(c(
+
+ 0.0005, 0.0010, 0.0015, 0.0020, 0.0025, 0.0050, 0.0075, 0.0100, 0.0125,
+
+ 0.0150, 0.0175, 0.0200, 0.0225, 0.0250, 0.0275, 0.0300, 0.0325, 0.0350,
+
+ 0.0375, 0.0400, 0.0425, 0.0450, 0.0500, 0.0600, 0.0700, 0.0800, 0.0900,
+
+ 0.1000, 0.2000, 0.3000, 0.4000, 0.5000, 1.5000, 2.5000, 3.5000, 4.5000,
+
+ 10, 20, 30, 40, 50, 150, 250, 350, 450, 1000, 2000, 3000, 4000, 5000, 0.019690,
+
+ 0.027694, 0.033789, 0.038896, 0.043372, 0.060721, 0.073808, 0.084693, 0.094171,
+
+ 0.102651, 0.110375, 0.117503, 0.124142, 0.130374, 0.136259, 0.141842, 0.147162,
+
+ 0.152249, 0.157127, 0.161817, 0.166337, 0.170702, 0.179015, 0.194248, 0.207999,
+
+ 0.220581, 0.232212, 0.243050, 0.325071, 0.382016, 0.426452, 0.463159, 0.668992,
+
+ 0.775976, 0.849298, 0.905305, 1.088998, 1.253794, 1.351794, 1.421860, 1.476457,
+
+ 1.747485, 1.874323, 1.958037, 2.020630, 2.219765, 2.392826, 2.494109, 2.565985,
+
+ 2.621743),ncol=2)
+
+
+
+ if(x<0.0005){
+
+ Qp<-gamma*sqrt(2*x)
+
+ }
+
+ if(x>0.0005 & x<5000){
+
+ Qp<-spline(log(mQp[,1]),mQp[,2],n=1,xmin=log(x),xmax=log(x))$y
+
+ }
+
+ if(x>5000){
+
+ Qp<-0.25*log(x)+0.49088
+
+ }
+
+ Ed<-(2*sig^2/mu)*Qp
+
+ }
+
+ if(mu<0){
+
+ mQn<-matrix(c(
+
+ 0.0005, 0.0010, 0.0015, 0.0020, 0.0025, 0.0050, 0.0075, 0.0100, 0.0125, 0.0150,
+
+ 0.0175, 0.0200, 0.0225, 0.0250, 0.0275, 0.0300, 0.0325, 0.0350, 0.0375, 0.0400,
+
+ 0.0425, 0.0450, 0.0475, 0.0500, 0.0550, 0.0600, 0.0650, 0.0700, 0.0750, 0.0800,
+
+ 0.0850, 0.0900, 0.0950, 0.1000, 0.1500, 0.2000, 0.2500, 0.3000, 0.3500, 0.4000,
+
+ 0.5000, 1.0000, 1.5000, 2.0000, 2.5000, 3.0000, 3.5000, 4.0000, 4.5000, 5.0000,
+
+ 0.019965, 0.028394, 0.034874, 0.040369, 0.045256, 0.064633, 0.079746, 0.092708,
+
+ 0.104259, 0.114814, 0.124608, 0.133772, 0.142429, 0.150739, 0.158565, 0.166229,
+
+ 0.173756, 0.180793, 0.187739, 0.194489, 0.201094, 0.207572, 0.213877, 0.220056,
+
+ 0.231797, 0.243374, 0.254585, 0.265472, 0.276070, 0.286406, 0.296507, 0.306393,
+
+ 0.316066, 0.325586, 0.413136, 0.491599, 0.564333, 0.633007, 0.698849, 0.762455,
+
+ 0.884593, 1.445520, 1.970740, 2.483960, 2.990940, 3.492520, 3.995190, 4.492380,
+
+ 4.990430, 5.498820),ncol=2)
+
+
+
+
+
+ if(x<0.0005){
+
+ Qn<-gamma*sqrt(2*x)
+
+ }
+
+ if(x>0.0005 & x<5000){
+
+ Qn<-spline(mQn[,1],mQn[,2],n=1,xmin=x,xmax=x)$y
+
+ }
+
+ if(x>5000){
+
+ Qn<-x+0.50
+
+ }
+
+ Ed<-(2*sig^2/mu)*(-Qn)
+
+ }
+
+ }
+
+ # return(Ed)
+
+ z = c((mu*100),
+ (sig*100),
+ (Ed*100))
+ znames = c(
+ "Annual Returns in %",
+ "Std Devetions in %",
+ "Expected Drawdown in %"
+ )
+ if(column == 1) {
+ resultingtable = data.frame(Value = z, row.names = znames)
+ }
+ else {
+ nextcolumn = data.frame(Value = z, row.names = znames)
+ resultingtable = cbind(resultingtable, nextcolumn)
+ }
+ }
+ colnames(resultingtable) = columnnames
+ ans = base::round(resultingtable, digits)
+ ans
+
+
+ }
+
+###############################################################################
+################################################################################
+# 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: EmaxDDGBM.R 2271 2012-09-02 01:56:23Z braverock $
+#
+###############################################################################
Added: pkg/PerformanceAnalytics/sandbox/Shubhankit/R/GLMSmoothIndex.R
===================================================================
--- pkg/PerformanceAnalytics/sandbox/Shubhankit/R/GLMSmoothIndex.R (rev 0)
+++ pkg/PerformanceAnalytics/sandbox/Shubhankit/R/GLMSmoothIndex.R 2013-08-16 11:08:26 UTC (rev 2796)
@@ -0,0 +1,75 @@
+#'@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' '.
+#'
+#' \deqn{ R_t = {\mu} + {\beta}{{\delta}}_t+ \xi_t}
+#' @param R an xts, vector, matrix, data frame, timeSeries or zoo object of
+#' asset returns
+#' @author R
+#' @aliases Return.Geltner
+#' @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, ...)
+ {
+ 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)
+ }
+ }
+ 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: GLMSmoothIndex.R 2163 2012-07-16 00:30:19Z braverock $
+#
+###############################################################################
Added: pkg/PerformanceAnalytics/sandbox/Shubhankit/R/Return.GLM.R
===================================================================
--- pkg/PerformanceAnalytics/sandbox/Shubhankit/R/Return.GLM.R (rev 0)
+++ pkg/PerformanceAnalytics/sandbox/Shubhankit/R/Return.GLM.R 2013-08-16 11:08:26 UTC (rev 2796)
@@ -0,0 +1,87 @@
+#' Getmansky Lo Markov Unsmooth Return Model
+#'
+#'
+#' True returns represent the flow of information that would determine the equilibrium
+#' value of the fund's securities in a frictionless market. However, true economic
+#' returns are not observed. Instead, Rot
+#' denotes the reported or observed return in
+#' period t, which is a weighted average of the fund's true returns over the most recent k þ 1
+#' periods, includingthe current period.
+#' This averaging process captures the essence of smoothed returns in several
+#' respects. From the perspective of illiquidity-driven smoothing, is consistent
+#' with several models in the nonsynchronous tradingliterat ure. For example, Cohen
+#' et al. (1 986, Chapter 6.1) propose a similar weighted-average model for observed
+#' returns.
+#'
+#' 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 order of autocorrelation coefficient
+#' @author R
+#' @references "An econometric model of serial correlation and
+#' illiquidity in hedge fund returns
+#' Mila Getmansky1, Andrew W. Lo*, Igor Makarov
+#' MIT Sloan School of Management, 50 Memorial Drive, E52-432, Cambridge, MA 02142-1347, USA
+#' Received 16 October 2002; received in revised form 7 March 2003; accepted 15 May 2003
+#' Available online 10 July 2004
+#'
+#'
+#' @keywords ts multivariate distribution models
+#' @examples
+#'
+#' data(edhec)
+#' Return.GLM(edhec,4)
+#'
+#' @export
+Return.GLM <-
+ function (Ra,q=3)
+ { # @author Brian G. Peterson, Peter Carl
+
+ # Description:
+
+ # Ra return vector
+ # q Lag Factors
+ # Function:
+ library(tseries)
+ library(PerformanceAnalytics)
+ R = checkData(Ra, method="xts")
+ # Get dimensions and labels
+ columns.a = ncol(R)
+ columnnames.a = colnames(R)
+
+ clean.GLM <- function(column.R,q=3) {
+ ma.coeff = as.numeric((arma(edhec[,1],order=c(0,q)))$coef[1:q])
+ column.glm = ma.coeff[q]*lag(column.R,q)
+
+ return(column.glm)
+ }
+
+ for(column.a in 1:columns.a) { # for each asset passed in as R
+ # clean the data and get rid of NAs
+ column.glma = na.skip(R[,column.a],clean.GLM)
+
+ if(column.a == 1) { glm = column.glma }
+ else { glm = cbind (glm, column.glma) }
+
+ }
+
+ colnames(glm) = columnnames.a
+
+ # RESULTS:
+ return(reclass(glm,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.GLM.R 2163 2012-07-16 00:30:19Z braverock $
+#
+###############################################################################
Added: pkg/PerformanceAnalytics/sandbox/Shubhankit/R/UnsmoothReturn.R
===================================================================
--- pkg/PerformanceAnalytics/sandbox/Shubhankit/R/UnsmoothReturn.R (rev 0)
+++ pkg/PerformanceAnalytics/sandbox/Shubhankit/R/UnsmoothReturn.R 2013-08-16 11:08:26 UTC (rev 2796)
@@ -0,0 +1,36 @@
+UnSmoothReturn<-
+ function(R = NULL,q, ...)
+ {
+ 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(edhec[,column], method="vector", na.rm = TRUE)
+
+ acflag6 = acf(y,plot=FALSE,lag.max=6)[[1]][2:7]
+ values = sum(acflag6*acflag6)/(sum(acflag6)*sum(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[1:q,]*R) # Unsmooth Return
+
+ }
+ }
\ No newline at end of file
Added: pkg/PerformanceAnalytics/sandbox/Shubhankit/R/chart.Autocorrelation.R
===================================================================
--- pkg/PerformanceAnalytics/sandbox/Shubhankit/R/chart.Autocorrelation.R (rev 0)
+++ pkg/PerformanceAnalytics/sandbox/Shubhankit/R/chart.Autocorrelation.R 2013-08-16 11:08:26 UTC (rev 2796)
@@ -0,0 +1,58 @@
+#' Stacked Bar Plot of Autocorrelation Lag Coefficients
+#'
+#' A wrapper to create box and whiskers plot of comparitive inputs
+#'
+#' We have also provided controls for all the symbols and lines in the chart.
+#' One default, set by \code{as.Tufte=TRUE}, will strip chartjunk and draw a
+#' Boxplot per recommendations by Burghardt, Duncan and Liu(2013)
+#'
+#' @param R an xts, vector, matrix, data frame, timeSeries or zoo object of
+#' an asset return
+#' @return Stack Bar plot of lagged return coefficients
+#' @author R
+#' @seealso \code{\link[graphics]{boxplot}}
+#' @references Burghardt, Duncan and Liu(2013) \emph{It's the autocorrelation, stupid}. AlternativeEdge Note November, 2012 }
+#' @keywords Autocorrelation lag factors
+#' @examples
+#'
+#' data(edhec[,1])
+#' chart.Autocorrelation(edhec[,1])
+#'
+#' @rdname chart.Autocorrelation
+#' @export
+chart.Autocorrelation <-
+ function (R, ...)
+ { # @author R
+
+ # DESCRIPTION:
+ # A wrapper to create box and whiskers plot, of autocorrelation lag coeffiecients
+ # of the First six factors
+
+ R = checkData(R, method="xts")
+
+# Graph autos with adjacent bars using rainbow colors
+
+aa= table.Autocorrelation(R)
+ barplot(as.matrix(aa), main="ACF Lag Plot", ylab= "Value of Coefficient",
+ , xlab = NULL,col=rainbow(6))
+
+ # Place the legend at the top-left corner with no frame
+ # using rainbow colors
+ legend("topright", c("1","2","3","4","5","6"), cex=0.6,
+ bty="n", fill=rainbow(6));
+
+
+
+
+}
+###############################################################################
+# 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: Chart.Autocorrelation.R 2271 2012-09-02 01:56:23Z braverock $
+#
+###############################################################################
Added: pkg/PerformanceAnalytics/sandbox/Shubhankit/R/maxDDGBM.R
===================================================================
--- pkg/PerformanceAnalytics/sandbox/Shubhankit/R/maxDDGBM.R (rev 0)
+++ pkg/PerformanceAnalytics/sandbox/Shubhankit/R/maxDDGBM.R 2013-08-16 11:08:26 UTC (rev 2796)
@@ -0,0 +1,174 @@
+#' Expected Drawdown using Brownian Motion Assumptions
+#'
+#' Works on the model specified by Maddon-Ismail
+#'
+#'
+#'
+#' @param R an xts, vector, matrix, data frame, timeSeries or zoo object of
+#' asset returns
+
+#' @author R
+#' @keywords Expected Drawdown Using Brownian Motion Assumptions
+#'
+#' @export
+EMaxDDGBM <-
+ function (R,digits =4)
+ {# @author
+
+ # DESCRIPTION:
+ # Downside Risk Summary: Statistics and Stylized Facts
[TRUNCATED]
To get the complete diff run:
svnlook diff /svnroot/returnanalytics -r 2796
More information about the Returnanalytics-commits
mailing list