From e55aa64dd76fe3f87a9fffa8a6550dbda8334e21 Mon Sep 17 00:00:00 2001 From: Dom Date: Mon, 5 Jul 2021 23:25:29 +0100 Subject: [PATCH] fix: freq undefined when scale set for some tables This commit removes references to 'freq' which is not assigned when the argument 'scale' != NA for the following tables: * table.Distributions * table.DownsideRiskRatio * table.Variability Fixes #128. --- R/table.Distributions.R | 7 +++++-- R/table.DownsideRiskRatio.R | 5 ++++- R/table.Variability.R | 5 ++++- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/R/table.Distributions.R b/R/table.Distributions.R index 3e942ab1..5e169919 100644 --- a/R/table.Distributions.R +++ b/R/table.Distributions.R @@ -42,7 +42,8 @@ function (R, scale = NA, digits = 4) #set up frequency if(is.na(scale)) { - freq = periodicity(y) + freq = periodicity(R) + name <- paste0(freq$scale," Std Dev") switch(freq$scale, minute = {stop("Data periodicity too high")}, hourly = {stop("Data periodicity too high")}, @@ -52,13 +53,15 @@ function (R, scale = NA, digits = 4) quarterly = {scale = 4}, yearly = {scale = 1} ) + } else { + name <- paste0("Std Dev") } # for each column, do the following: for(column in 1:columns) { z = c(StdDev.annualized(y[,column,drop=FALSE])/sqrt(scale), skewness(y[,column,drop=FALSE], method = "moment"), kurtosis(y[,column,drop=FALSE], method = "moment"), kurtosis(y[,column,drop=FALSE], method = "excess"), skewness(y[,column,drop=FALSE], method = "sample"), kurtosis(y[,column,drop=FALSE], method = "sample_excess")) - znames = c(paste(freq$scale," Std Dev"), "Skewness", "Kurtosis", "Excess kurtosis", "Sample skewness", "Sample excess kurtosis") + znames = c(name, "Skewness", "Kurtosis", "Excess kurtosis", "Sample skewness", "Sample excess kurtosis") if(column == 1) { diff --git a/R/table.DownsideRiskRatio.R b/R/table.DownsideRiskRatio.R index aaa30718..647a3487 100644 --- a/R/table.DownsideRiskRatio.R +++ b/R/table.DownsideRiskRatio.R @@ -46,6 +46,7 @@ function (R, MAR = 0, scale = NA, digits = 4) #set up frequency if(is.na(scale)) { freq = periodicity(R) + name <- paste0(freq$scale," downside risk") switch(freq$scale, minute = {stop("Data periodicity too high")}, hourly = {stop("Data periodicity too high")}, @@ -55,13 +56,15 @@ function (R, MAR = 0, scale = NA, digits = 4) quarterly = {scale = 4}, yearly = {scale = 1} ) + } else { + name <- paste0("downside risk") } # for each column, do the following: for(column in 1:columns) { z = c(DownsideDeviation(y[,column,drop=FALSE], MAR = MAR), DownsideDeviation(y[,column,drop=FALSE], MAR = MAR)*sqrt(scale), DownsidePotential(y[,column,drop=FALSE], MAR = MAR), UpsideRisk(y[,column,drop=FALSE], MAR = MAR, stat = "potential")/DownsidePotential(y[,column,drop=FALSE], MAR = MAR), SortinoRatio(y[,column,drop=FALSE], MAR = MAR), UpsideRisk(y[,column,drop=FALSE], MAR = MAR, stat = "potential"), UpsidePotentialRatio(y[,column,drop=FALSE], MAR = MAR), OmegaSharpeRatio(y[,column,drop=FALSE], MAR = MAR)) - znames = c(paste0(freq$scale," downside risk"), "Annualised downside risk", "Downside potential", "Omega", "Sortino ratio", "Upside potential", "Upside potential ratio", "Omega-sharpe ratio") + znames = c(name, "Annualised downside risk", "Downside potential", "Omega", "Sortino ratio", "Upside potential", "Upside potential ratio", "Omega-sharpe ratio") if(column == 1) { resultingtable = data.frame(Value = z, row.names = znames) } diff --git a/R/table.Variability.R b/R/table.Variability.R index b86d2e44..eae8e876 100644 --- a/R/table.Variability.R +++ b/R/table.Variability.R @@ -46,6 +46,7 @@ function (R, scale = NA, geometric = TRUE, digits = 4) #set up frequency if(is.na(scale)) { freq = periodicity(R) + name <- paste0(freq$scale," Std Dev") switch(freq$scale, minute = {stop("Data periodicity too high")}, hourly = {stop("Data periodicity too high")}, @@ -55,13 +56,15 @@ function (R, scale = NA, geometric = TRUE, digits = 4) quarterly = {scale = 4}, yearly = {scale = 1} ) + } else { + name <- paste0("Std Dev") } # for each column, do the following: for(column in 1:columns) { z = c(MeanAbsoluteDeviation(y[,column,drop=FALSE]), StdDev.annualized(y[,column,drop=FALSE], scale = scale)/sqrt(scale), StdDev.annualized(y[,column,drop=FALSE], scale = scale)) - znames = c("Mean Absolute deviation", paste0(freq$scale," Std Dev"), "Annualized Std Dev") + znames = c("Mean Absolute deviation", name, "Annualized Std Dev") if(column == 1) {