Skip to content

Commit

Permalink
merge and comment out url in KellyRatio.R
Browse files Browse the repository at this point in the history
Merge branch 'master' of github.com:braverock/PerformanceAnalytics

# Conflicts:
#	R/KellyRatio.R
  • Loading branch information
JustinMShea committed Dec 13, 2024
2 parents 4efbbeb + 1a78585 commit f731a03
Show file tree
Hide file tree
Showing 72 changed files with 356 additions and 279 deletions.
3 changes: 2 additions & 1 deletion .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ codeblock.txt
^\.travis.yml
cran-comments.md
^\.github$
PerformanceAnalytics-Ex.Rout.save
PerformanceAnalytics-Ex.Rout.save
textplotPresentation-CRUG-2011.Rnw
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ Authors@R: c(
, person(given=c("Justin", "M."),family="Shea",role="ctb")
, person(given="Dhairya",family="Jain",role="ctb")
)
Version: 2.0.8
Date: 2024-12-04
Version: 2.0.8-1
Date: 2024-12-09
Description: Collection of econometric functions for performance and risk
analysis. In addition to standard risk and performance metrics, this
package aims to aid practitioners and researchers in utilizing the latest
Expand Down Expand Up @@ -62,5 +62,5 @@ License: GPL-2 | GPL-3
Encoding: UTF-8
LazyData: true
URL: https://github.com/braverock/PerformanceAnalytics
Copyright: (c) 2004-2022
Copyright: (c) 2004-2024
RoxygenNote: 7.3.2
31 changes: 16 additions & 15 deletions R/CAPM.alpha.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,24 @@
#' literature, it is an example of a simple single factor model,
#' comparing an asset to any arbitrary benchmark.
#'
#' @aliases CAPM.alpha
#' @aliases CAPM.alpha SFM.alpha
#' @param Ra an xts, vector, matrix, data frame, timeSeries or zoo object of
#' asset returns
#' @param Rb return vector of the benchmark asset
#' @param Rf risk free rate, in same period as your returns
#' @param \dots Other parameters like max.it or bb specific to lmrobdetMM regression.
#' @param digits (Optional): Number of digits to round the results to. Defaults to 3.
#' @param benchmarkCols (Optional): Boolean to show the benchmarks as columns. Defaults to TRUE.
#' @param method (Optional): string representing linear regression model, "LS" for Least Squares
#' and "Robust" for robust. Defaults to "LS
#' @param family (Optional):
#' @param digits Number of digits to round the results to. Defaults to 3.
#' @param benchmarkCols Boolean to show the benchmarks as columns. Defaults to TRUE.
#' @param method string representing linear regression model, "LS" for Least Squares
#' and "Robust" for robust. Defaults to "LS"
#' @param family
#' If method == "Robust":
#' This is a string specifying the name of the family of loss function
#' to be used (current valid options are "bisquare", "opt" and "mopt").
#' Incomplete entries will be matched to the current valid options.
#' Defaults to "mopt".
#' Else: the parameter is ignored
#' @param warning (Optional): Boolean to show warnings or not. Defaults to TRUE.
#' @param warning Boolean to show warnings or not. Defaults to TRUE.
#'
#' @author Dhairya Jain, Peter Carl
#' @seealso \code{\link{CAPM.beta}} \code{\link{CAPM.utils}}
Expand All @@ -42,15 +42,16 @@
#' data(managers)
#' SFM.alpha(managers[, "HAM1"], managers[, "SP500 TR"], Rf = managers[, "US 3m TR"])
#' SFM.alpha(managers[,1:3], managers[,8:10], Rf=.035/12)
#' SFM.alpha(managers[,1], managers[,8:10], Rf=.035/12, benchmarkCols=FALSE)
#' # SFM.alpha(managers[,1], managers[,8:10], Rf=.035/12, benchmarkCols=FALSE) # other variations
#' if(requireNamespace("RobStatTM", quietly = TRUE)) { # CRAN requires conditional execution
#' alphas <- SFM.alpha(managers[,1:6],
#' managers[,8:10],
#' Rf=.035/12, method="Robust",
#' family="opt", bb=0.25, max.it=200, digits=4)
#' alphas["HAM1", ]
#' alphas[, "Alpha : SP500 TR"]
#' } # CRAN can have issues with RobStatTM
#'
#' alphas <- SFM.alpha(managers[,1:6],
#' managers[,8:10],
#' Rf=.035/12, method="Robust",
#' family="opt", bb=0.25, max.it=200, digits=4)
#' alphas["HAM1", ]
#' alphas[, "Alpha : SP500 TR"]
#'
#' @rdname SFM.alpha
#' @export SFM.alpha CAPM.alpha
SFM.alpha <- CAPM.alpha <- function (Ra, Rb, Rf = 0, ..., digits=3, benchmarkCols = T, method="LS", family="mopt", warning=T){
Expand Down
83 changes: 44 additions & 39 deletions R/CAPM.beta.R
Original file line number Diff line number Diff line change
Expand Up @@ -62,49 +62,54 @@
#' @examples
#'
#' data(managers)
#' SFM.beta(managers[, "HAM1"], managers[, "SP500 TR"], Rf = managers[, "US 3m TR"])
#' SFM.beta(managers[,1:3], managers[,8:10], Rf=.035/12)
#' SFM.beta(managers[,1], managers[,8:10], Rf=.035/12, benchmarkCols=FALSE)
#'
#' SFM.beta(managers[, "HAM1"], managers[, "SP500 TR"], Rf = managers[, "US 3m TR"])
#' SFM.beta(managers[,1:3], managers[,8:10], Rf=.035/12)
#' SFM.beta(managers[,1], managers[,8:10], Rf=.035/12, benchmarkCols=FALSE)
#'
#' betas <- SFM.beta(managers[,1:6],
#' managers[,8:10],
#' Rf=.035/12, method="Robust",
#' family="opt", bb=0.25, max.it=200, digits=4)
#' betas["HAM1", ]
#' betas[, "Beta : SP500 TR"]
#' SFM.beta.bull(managers[, "HAM2"],
#' managers[, "SP500 TR"],
#' Rf = managers[, "US 3m TR"])
#'
#' SFM.beta.bear(managers[, "HAM2"],
#' managers[, "SP500 TR"],
#' Rf = managers[, "US 3m TR"])
#'
#' TimingRatio(managers[, "HAM2"],
#' managers[, "SP500 TR"],
#' Rf = managers[, "US 3m TR"])
#'
#' if(requireNamespace("RobStatTM", quietly = TRUE)) { # CRAN requires conditional execution
#' betas <- SFM.beta(managers[,1:6],
#' managers[,8:10],
#' Rf=.035/12, method="Robust",
#' family="opt", bb=0.25, max.it=200, digits=4)
#' betas["HAM1", ]
#' betas[, "Beta : SP500 TR"]
#'
#' SFM.beta.bull(managers[, "HAM2"],
#' managers[, "SP500 TR"],
#' Rf = managers[, "US 3m TR"])
#' SFM.beta.bull(managers[, "HAM2"],
#' managers[, "SP500 TR"],
#' Rf = managers[, "US 3m TR"],
#' method="Robust")
#' SFM.beta.bull(managers[, "HAM2"],
#' managers[, "SP500 TR"],
#' Rf = managers[, "US 3m TR"],
#' method="Robust")
#'
#' SFM.beta.bear(managers[, "HAM2"],
#' managers[, "SP500 TR"],
#' Rf = managers[, "US 3m TR"])
#' SFM.beta.bear(managers[, "HAM2"],
#' managers[, "SP500 TR"],
#' Rf = managers[, "US 3m TR"],
#' method="Robust")
#' SFM.beta.bear(managers[, "HAM2"],
#' managers[, "SP500 TR"],
#' Rf = managers[, "US 3m TR"],
#' method="Robust")
#'
#' TimingRatio(managers[, "HAM2"],
#' managers[, "SP500 TR"],
#' Rf = managers[, "US 3m TR"],
#' method="Robust", family="mopt")
#'
#' TimingRatio(managers[, "HAM2"],
#' managers[, "SP500 TR"],
#' Rf = managers[, "US 3m TR"])
#' TimingRatio(managers[, "HAM2"],
#' managers[, "SP500 TR"],
#' Rf = managers[, "US 3m TR"],
#' method="Robust", family="mopt")
#'
#' chart.Regression(managers[, "HAM2"],
#' managers[, "SP500 TR"],
#' Rf = managers[, "US 3m TR"],
#' fit="conditional",
#' main="Conditional Beta")
#'
#'

#' } # CRAN can have issues with RobStatTM
#'
#' chart.Regression(managers[, "HAM2"],
#' managers[, "SP500 TR"],
#' Rf = managers[, "US 3m TR"],
#' fit="conditional",
#' main="Conditional Beta")
#'
#' @rdname SFM.beta
#' @export SFM.beta CAPM.beta
SFM.beta <- CAPM.beta <- function (Ra, Rb, Rf = 0, ..., digits=3, benchmarkCols=T, method="LS", family="mopt", warning=T)
Expand Down
21 changes: 11 additions & 10 deletions R/ES.R
Original file line number Diff line number Diff line change
Expand Up @@ -213,10 +213,7 @@
#' expected shortfall. Mathematical Finance, 2002, vol. 14, 74-86.
###keywords ts multivariate distribution models
#' @examples
#'
#' if(!( Sys.info()[['sysname']]=="Windows") ){
#' # if on Windows, cut and paste this example
#'
#' \donttest{
#' data(edhec)
#'
#' # first do normal ES calc
Expand All @@ -232,12 +229,16 @@
#' ES(edhec, p=.99)
#' # or the equivalent alpha=.01
#' ES(edhec, p=.01)
#'
#' # now with outliers squished
#' ES(edhec, clean="boudt")
#'
#' # add Component ES for the equal weighted portfolio
#' ES(edhec, clean="boudt", portfolio_method="component")
#'
#' # CRAN (questionably(ahem) requires these methods to not run if you don't have Suggests loaded)
#' if(requireNamespace("robustbase", quietly = TRUE)){
# now with outliers squished
#' ES(edhec, clean="boudt")
#'
#' # add Component ES for the equal weighted portfolio
#' ES(edhec, clean="boudt", portfolio_method="component")
#' } # end CRAN workaround
#'
#'
#' } # end CRAN Windows check
#'
Expand Down
5 changes: 3 additions & 2 deletions R/KellyRatio.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@
#' @author Brian G. Peterson
#' @references Thorp, Edward O. (1997; revised 1998). The Kelly Criterion in
#' Blackjack, Sports Betting, and the Stock Market. #https://archive.ph/h1LuS
#' \url{https://en.wikipedia.org/wiki/Kelly_criterion}
###keywords ts multivariate distribution models
#' no longer online, but can be found at archive.ph /h1LuS \cr
#
# ## keywords ts multivariate distribution models
#' @examples
#'
#' data(managers)
Expand Down
9 changes: 6 additions & 3 deletions R/Omega.R
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,12 @@
#'
#' data(edhec)
#' Omega(edhec)
#' Omega(edhec[,13],method="interp",output="point")
#' Omega(edhec[,13],method="interp",output="full")
#'
#'
#' # CRAN (questionably(ahem) requires these methods to not run if you don't have Suggests loaded)
#' if(requireNamespace("Hmisc", quietly = TRUE)){
#' Omega(edhec[,13],method="interp",output="point")
#' Omega(edhec[,13],method="interp",output="full")
#' } # end spurious CRAN check
#' @export
Omega <-
function(R, L = 0, method = c("simple", "interp", "binomial", "blackscholes"),
Expand Down
2 changes: 1 addition & 1 deletion R/Return.calculate.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
###keywords ts multivariate distribution models
#' @examples
#'
#' \dontrun{
#' \dontrun{ # no internet access on CRAN tests
#' require(quantmod)
#' prices = Cl(getSymbols("IBM", from = "1999-01-01", to = "2007-01-01"))
#' }
Expand Down
5 changes: 3 additions & 2 deletions R/Return.locScaleRob.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@
#' "ED", "FIA", "GM", "LS", "MA",
#' "RV", "SS", "FOF")
#' # Cleaning the returns time series for manager data
#' outRob <- Return.locScaleRob(edhec$CA)
#'
#' if(requireNamespace("RobStatTM", quietly = TRUE)) { # CRAN requires conditional execution
#' outRob <- Return.locScaleRob(edhec$CA)
#' }
# Implementation of the robust filter for the IF TS
Return.locScaleRob <- function(R, alpha.robust=0.05, normal.efficiency=0.99, ...){

Expand Down
29 changes: 12 additions & 17 deletions R/SFM.coefficients.R
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,15 @@
#' performance measurement and attribution}. Wiley. 2004. \cr
###keywords ts multivariate distribution models
#' @examples
#'
#' data(managers)
#' SFM.coefficients(managers[,1], managers[,8])
#' SFM.coefficients(managers[,1:6], managers[,8:9], Rf = managers[,10])
#' SFM.coefficients(managers[,1:6], managers[,8:9],
#' if(requireNamespace("RobStatTM", quietly = TRUE)) { # CRAN requires conditional execution
#' data(managers)
#' SFM.coefficients(managers[,1], managers[,8])
#' SFM.coefficients(managers[,1:6], managers[,8:9], Rf = managers[,10])
#' SFM.coefficients(managers[,1:6], managers[,8:9],
#' Rf=.035/12, method="Robust",
#' family="mopt", bb=0.25,
#' max.it=200)
#'
#'
#' } # CRAN requires conditional execution
#' @rdname SFM.coefficients
#' @export SFM.coefficients
SFM.coefficients <- function(Ra, Rb, Rf=0, subset=TRUE, ..., method="Robust",
Expand Down Expand Up @@ -105,7 +104,7 @@ SFM.coefficients <- function(Ra, Rb, Rf=0, subset=TRUE, ..., method="Robust",
Rb.colnames <- colnames(Rb)

# ret.Model == TRUE means internal usage. Hence, if not internal usage
if (Model==F){
if (Model==FALSE){
if (warning && method=="Both"){
warning("Using 'Both' while using SFM.Coefficients will lead to ill-formatted output");
}
Expand Down Expand Up @@ -195,15 +194,7 @@ SFM.coefficients <- function(Ra, Rb, Rf=0, subset=TRUE, ..., method="Robust",

# FUNCTION:

if (!requireNamespace("RobStatTM", quietly=TRUE)){
c = readline(prompt = "You need to install package RobStatTM to use this function. Do you want to install it? (y|N): ");
if(c=="y" || c=="Y"){
utils::install.packages("RobStatTM")
}
else{
stop("Aborted")
}
}

# subset is assumed to be a logical vector
if(missing(subset))
subset <-TRUE
Expand All @@ -228,6 +219,8 @@ SFM.coefficients <- function(Ra, Rb, Rf=0, subset=TRUE, ..., method="Robust",
model= model.lm))
},
Robust = {
stopifnot("package:RobStatTM" %in% search() || requireNamespace("RobStatTM", quietly = TRUE))

model.rob.lm = RobStatTM::lmrobdetMM(Alpha ~ Beta, data=merged,
subset=subset,
control = RobStatTM::lmrobdet.control(family=family, ...))
Expand All @@ -236,6 +229,8 @@ SFM.coefficients <- function(Ra, Rb, Rf=0, subset=TRUE, ..., method="Robust",
model= model.rob.lm))
},
Both = {
stopifnot("package:RobStatTM" %in% search() || requireNamespace("RobStatTM", quietly = TRUE))

model.rob.lm = RobStatTM::lmrobdetMM(Alpha ~ Beta, data=merged,
subset=subset,
control = RobStatTM::lmrobdet.control(family=family))
Expand Down
4 changes: 2 additions & 2 deletions R/SFM.fit.models.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#' @param plots Boolean to output plots after the function. Defaults to TRUE
#' @author Dhairya Jain
#' @examples
#'
#' \dontrun{
#' # First we load the data
#' data(managers)
#' mgrs <- managers["2002/"] # So that all have managers have complete history
Expand All @@ -42,7 +42,7 @@
#'
#' SFM.fit.models(mgrs$HAM2, mgrs$SP500, Rf = mgrs$RF, family = "opt",
#' plots=FALSE)
#'
#' }
#' @rdname SFM.fit.models
#' @export SFM.fit.models
SFM.fit.models <- function(Ra, Rb, Rf=0, family = "mopt",
Expand Down
7 changes: 2 additions & 5 deletions R/StdDev.R
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,7 @@
#' @seealso \code{\link{Return.clean}} \code{sd}
###keywords ts multivariate distribution models
#' @examples
#'
#' if(!( Sys.info()[['sysname']]=="Windows") ){
#' # if on Windows, cut and paste this example
#'
#' \donttest{
#' data(edhec)
#'
#' # first do normal StdDev calc
Expand All @@ -79,7 +76,7 @@
#' # add Component StdDev for the equal weighted portfolio
#' StdDev(edhec, clean="boudt", portfolio_method="component")
#'
#' } # end CRAN Windows check
#' } # end CRAN check
#'
#' @export
StdDev <- function (R , ..., clean=c("none","boudt","geltner", "locScaleRob"), portfolio_method=c("single","component"),
Expand Down
7 changes: 2 additions & 5 deletions R/VaR.R
Original file line number Diff line number Diff line change
Expand Up @@ -297,10 +297,7 @@
#'
###keywords ts multivariate distribution models
#' @examples
#'
#' if(!( Sys.info()[['sysname']]=="Windows") ){
#' # if on Windows, cut and paste this example
#'
#' \donttest{
#' data(edhec)
#'
#' # first do normal VaR calc
Expand All @@ -323,7 +320,7 @@
#' # add Component VaR for the equal weighted portfolio
#' VaR(edhec, clean="boudt", portfolio_method="component")
#'
#' } # end Windows check
#' } # end CRAN check
#'
#' @export
VaR <-
Expand Down
Loading

0 comments on commit f731a03

Please sign in to comment.