Skip to content

Commit

Permalink
fix: freq undefined when scale set for some tables
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
domodwyer committed Jul 5, 2021
1 parent b41c9fe commit e55aa64
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
7 changes: 5 additions & 2 deletions R/table.Distributions.R
Expand Up @@ -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")},
Expand All @@ -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) {
Expand Down
5 changes: 4 additions & 1 deletion R/table.DownsideRiskRatio.R
Expand Up @@ -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")},
Expand All @@ -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)
}
Expand Down
5 changes: 4 additions & 1 deletion R/table.Variability.R
Expand Up @@ -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")},
Expand All @@ -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) {
Expand Down

0 comments on commit e55aa64

Please sign in to comment.