From noreply at r-forge.r-project.org Wed Nov 18 10:28:19 2015 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Wed, 18 Nov 2015 10:28:19 +0100 (CET) Subject: [Returnanalytics-commits] r4001 - pkg/Dowd/tests/testthat Message-ID: <20151118092819.8EAE9184B54@r-forge.r-project.org> Author: dacharya Date: 2015-11-18 10:28:19 +0100 (Wed, 18 Nov 2015) New Revision: 4001 Removed: pkg/Dowd/tests/testthat/testAdjustedNormalESHotspots.R Log: Removed a file as it had problem with new version of testthat Deleted: pkg/Dowd/tests/testthat/testAdjustedNormalESHotspots.R =================================================================== --- pkg/Dowd/tests/testthat/testAdjustedNormalESHotspots.R 2015-10-26 11:54:52 UTC (rev 4000) +++ pkg/Dowd/tests/testthat/testAdjustedNormalESHotspots.R 2015-11-18 09:28:19 UTC (rev 4001) @@ -1,77 +0,0 @@ -test_that("Adjusted Normal ES Hotspots.",{ - - # Success - 1 - vc.matrix <- matrix(c(2.5, 3.4, -1.9, 4.3, 2.3, -3.1, 4.3, -1.2, 1), 3, 3) - mu <- c(.4, -.3, .1) - skew <- .5 - kurtosis <- 1.2 - positions <- c(5,2,6) - cl <- .95 - hp <- 280 - val <- AdjustedNormalESHotspots(vc.matrix, mu, skew, kurtosis, positions, cl, hp) - expect_equal(c(4655.6, -725, 308.2), val, tolerance=1) - - - # Success - 2 - vc.matrix <- matrix(c(2.6, 3.4, -1.9, 4.3, 2.3, -3.1, 4.3, -1.2, - 1, 3.4, -2, -5, -1.2, 3.2, 0, -1.2), 4, 4) - mu <- c(-.5, -.3, -1.2, 0) - skew <- -.4 - kurtosis <- 2.2 - positions <- c(4,1,10,3) - cl <- .99 - hp <- 50 - val <- AdjustedNormalESHotspots(vc.matrix, mu, skew, kurtosis, positions, cl, hp) - expect_equal(c(1482.4, 2096.8, -5079.3, -2071.2), val, tolerance=1) - - # Error - 1 - vc.matrix <- matrix(c(2.5, 3.4, -1.9, 4.3, 2.3, -3.1, 4.3, -1.2, 1), 3, 3) - mu <- c(.4, -.3, .1) - skew <- .5 - kurtosis <- 1.2 - positions <- c(5,2,6) - cl <- .95 - hp <- -10 - expect_error(val <- AdjustedNormalESHotspots(vc.matrix, mu, skew, kurtosis, positions, cl, hp)) - - # Error - 2 - vc.matrix <- matrix(c(2.5, 3.4, -1.9, 4.3, 2.3, -3.1, 4.3, -1.2, 1), 3, 3) - mu <- c(.4, -.3, .1) - skew <- .5 - kurtosis <- 1.2 - positions <- c(5,2,6) - cl <- 1.2 - hp <- 280 - expect_error(val <- AdjustedNormalESHotspots(vc.matrix, mu, skew, kurtosis, positions, cl, hp)) - - # Error - 3 - vc.matrix <- matrix(c(2.5, 3.4, -1.9, 4.3, 2.3, -3.1, 4.3, -1.2, 1), 3, 3) - mu <- c(.4, -.3, .1) - skew <- .5 - kurtosis <- 1.2 - positions <- c(5,2,6) - cl <- -.95 - hp <- 280 - expect_error(val <- AdjustedNormalESHotspots(vc.matrix, mu, skew, kurtosis, positions, cl, hp)) - - # Error - 4 - vc.matrix <- matrix(c(2.5, 3.4, -1.9, 4.3, 2.3, -3.1, 4.3, -1.2, 1), 3, 3) - mu <- c(.4, -.3, .1, 1.2) - skew <- .5 - kurtosis <- 1.2 - positions <- c(5, 2, 6) - cl <- -.95 - hp <- 280 - expect_error(val <- AdjustedNormalESHotspots(vc.matrix, mu, skew, kurtosis, positions, cl, hp)) - - # Error - 5 - vc.matrix <- matrix(c(2.5, 3.4, -1.9, 4.3, 2.3, -3.1, 4.3, -1.2, 1), 3, 3) - mu <- c(.4, -.3, .1) - skew <- .5 - kurtosis <- 1.2 - positions <- c(5,2,6,3) - cl <- -.95 - hp <- 280 - expect_error(val <- AdjustedNormalESHotspots(vc.matrix, mu, skew, kurtosis, positions, cl, hp)) - -}) \ No newline at end of file From noreply at r-forge.r-project.org Wed Nov 18 10:39:40 2015 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Wed, 18 Nov 2015 10:39:40 +0100 (CET) Subject: [Returnanalytics-commits] r4002 - pkg/Dowd Message-ID: <20151118093940.B7E6B186229@r-forge.r-project.org> Author: dacharya Date: 2015-11-18 10:39:40 +0100 (Wed, 18 Nov 2015) New Revision: 4002 Modified: pkg/Dowd/NAMESPACE Log: Modified: pkg/Dowd/NAMESPACE =================================================================== --- pkg/Dowd/NAMESPACE 2015-11-18 09:28:19 UTC (rev 4001) +++ pkg/Dowd/NAMESPACE 2015-11-18 09:39:40 UTC (rev 4002) @@ -150,8 +150,3 @@ import(MASS) import(bootstrap) import(forecast) -importFrom("graphics", "barplot", "hist", "legend", "lines", "par", - "persp", "plot", "text", "title") -importFrom("stats", "cov", "density", "dlnorm", "dnorm", "dt", - "pbinom", "pchisq", "pnorm", "pt", "qnorm", "qt", - "quantile", "rbinom", "rlnorm", "rnorm", "sd") \ No newline at end of file From noreply at r-forge.r-project.org Wed Nov 18 10:47:25 2015 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Wed, 18 Nov 2015 10:47:25 +0100 (CET) Subject: [Returnanalytics-commits] r4003 - pkg/Dowd Message-ID: <20151118094726.08EC9183A41@r-forge.r-project.org> Author: dacharya Date: 2015-11-18 10:47:25 +0100 (Wed, 18 Nov 2015) New Revision: 4003 Modified: pkg/Dowd/DESCRIPTION Log: version changed Modified: pkg/Dowd/DESCRIPTION =================================================================== --- pkg/Dowd/DESCRIPTION 2015-11-18 09:39:40 UTC (rev 4002) +++ pkg/Dowd/DESCRIPTION 2015-11-18 09:47:25 UTC (rev 4003) @@ -2,7 +2,7 @@ Type: Package Title: Functions Ported from 'MMR2' Toolbox Offered in Kevin Dowd's Book Measuring Market Risk -Version: 0.1 +Version: 0.11 Date: 2015-08-20 Author: Dinesh Acharya Maintainer: Dinesh Acharya @@ -27,4 +27,4 @@ forecast Suggests: PerformanceAnalytics, testthat -License: GPL \ No newline at end of file +License: GPL From noreply at r-forge.r-project.org Wed Nov 25 23:24:02 2015 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Wed, 25 Nov 2015 23:24:02 +0100 (CET) Subject: [Returnanalytics-commits] r4004 - pkg/PerformanceAnalytics/sandbox Message-ID: <20151125222402.61BC81873A8@r-forge.r-project.org> Author: peter_carl Date: 2015-11-25 23:24:01 +0100 (Wed, 25 Nov 2015) New Revision: 4004 Modified: pkg/PerformanceAnalytics/sandbox/Normalize.R Log: - added normalization in units of std dev Modified: pkg/PerformanceAnalytics/sandbox/Normalize.R =================================================================== --- pkg/PerformanceAnalytics/sandbox/Normalize.R 2015-11-18 09:47:25 UTC (rev 4003) +++ pkg/PerformanceAnalytics/sandbox/Normalize.R 2015-11-25 22:24:01 UTC (rev 4004) @@ -6,8 +6,11 @@ #' #' #' @param R -#' @param targetMean -#' @param targetVol +#' @param targetMean specifies a return level to normalize each column to, in the same time units as the timeseries; default is zero +#' @param targetVol specifies a volatility level to normalize each column to, in the same time units as the timeseries +#' @param show.units.sd Normalize the plot's y-axis to units of annualized standard deviation +#' @param scale number of periods in a year (daily scale = 252, monthly scale = +#' 12, quarterly scale = 4) #' @param ... passes arguments to par #' @return xts or other time series #' @author Peter Carl @@ -15,7 +18,7 @@ #' @rdname Return.normalize #' @export Return.normalize #' @export chart.NDD -Return.normalize <- (R, targetMean=0, targetVol=0, ...){ +Return.normalize <- function(R, targetMean=0, targetVol, ...){ # Peter Carl x=checkData(R) x.Mean=apply(x, MARGIN=2, FUN="mean", na.rm = TRUE) @@ -23,19 +26,36 @@ # @TODO wil this work for vector? checkData as matrix? # Apply z-score x.Z = apply(x, MARGIN=2, FUN=function(x){ (x - mean(x, na.rm = TRUE))/sd(x, na.rm = TRUE) }) # x.Z has mean=0, sd=1 - x.N= targetMean + x.Z * (rep(1, nrow(x.R)) %o% rep(targetVol,NCOL(x.R))) + x.N= targetMean + x.Z * (rep(1, nrow(x)) %o% rep(targetVol,NCOL(x))) x.N = as.xts(x.N, by=index(x.R)) x.N = reclass(x.N, R) return(x.N) } -chart.NDD <- function(R, targetMean=0, targetVol=0){ +chart.NDD <- function(R, targetMean=0, targetVol, show.units.sd=FALSE, ylab="Drawdown", scale=NA, ...){ # Peter Carl - x.N = Return.normalize(x) + # @TODO: determine periodicity of R, specify multiplier for x.NDD below + 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} + ) + } + x.N = Return.normalize(R, targetMean=targetMean, targetVol=targetVol) x.NDD = PerformanceAnalytics:::Drawdowns(x.N) - par(mar = c(3, 5, 2, 3)+0.1) #c(bottom, left, top, right) - chart.TimeSeries(x.NDD[start.date,c(manager.col, index.cols, peer.cols)], colorset=colorset, lwd=lwdset, legend.loc=NULL, lty=lineset, main="", cex.axis=1.2, cex.lab=1.5) - par(op) + if(show.units.sd){ + x.NDD = x.NDD/(targetVol*sqrt(scale)) # targetVol must be annualized + ylab = "Annualized Std Dev" + } + # par(mar = c(3, 5, 2, 3)+0.1) #c(bottom, left, top, right) + chart.TimeSeries(x.NDD, ylab=ylab, ...) + # par(op) } ###############################################################################