From noreply at r-forge.r-project.org Mon Apr 13 08:38:17 2015 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Mon, 13 Apr 2015 08:38:17 +0200 (CEST) Subject: [Returnanalytics-commits] r3628 - in pkg/FactorAnalytics: . R man vignettes Message-ID: <20150413063817.553E9185831@r-forge.r-project.org> Author: arorar Date: 2015-04-13 08:38:17 +0200 (Mon, 13 Apr 2015) New Revision: 3628 Added: pkg/FactorAnalytics/R/fmmc.R pkg/FactorAnalytics/man/fmmc.Rd pkg/FactorAnalytics/man/fmmc.estimate.se.Rd pkg/FactorAnalytics/vignettes/fmmc_vignette.Rnw Modified: pkg/FactorAnalytics/DESCRIPTION pkg/FactorAnalytics/NAMESPACE pkg/FactorAnalytics/vignettes/FA.bib Log: Added new code to compute risk and performance measures and thier standard errors using Factor Model Monte Carlo as described in Jiang and Martin 2013 Modified: pkg/FactorAnalytics/DESCRIPTION =================================================================== --- pkg/FactorAnalytics/DESCRIPTION 2015-03-25 13:16:56 UTC (rev 3627) +++ pkg/FactorAnalytics/DESCRIPTION 2015-04-13 06:38:17 UTC (rev 3628) @@ -1,36 +1,42 @@ -Package: factorAnalytics -Type: Package -Title: Factor Analytics -Version:2.0.16 -Date:2015-03-21 -Author: Eric Zivot, Sangeetha Srinivasan and Yi-An Chen -Maintainer: Sangeetha Srinivasan -Description: An R package for the estimation and risk analysis of linear factor - models for asset returns and portfolios. It contains model fitting methods - for the three major types of factor models: time series (or, macroeconomic) - factor model, fundamental factor model and statistical factor model. They - allow for different types of distributions to be specified for modeling the - fat-tailed behavior of financial returns, including Edgeworth expansions. - Risk analysis measures such as VaR and ES, as well as performance - attribution for factor models (factor-contributed vs idiosyncratic returns) - are included. -License: GPL-2 -Depends: - R (>= 3.0.0), - xts (>= 0.9) -Imports: - PerformanceAnalytics(>= 1.1.0), - corrplot, - robust, - leaps, - lars, - strucchange, - lmtest, - sandwich, - lattice, - MASS -Suggests: - testthat, quantmod, knitr -LazyLoad: yes -LazyDataCompression: xz -URL: http://r-forge.r-project.org/R/?group_id=579 +Package: factorAnalytics +Type: Package +Title: Factor Analytics +Version:2.0.16 +Date:2015-03-21 +Author: Eric Zivot, Sangeetha Srinivasan and Yi-An Chen +Maintainer: Sangeetha Srinivasan +Description: An R package for the estimation and risk analysis of linear factor + models for asset returns and portfolios. It contains model fitting methods + for the three major types of factor models: time series (or, macroeconomic) + factor model, fundamental factor model and statistical factor model. They + allow for different types of distributions to be specified for modeling the + fat-tailed behavior of financial returns, including Edgeworth expansions. + Risk analysis measures such as VaR and ES, as well as performance + attribution for factor models (factor-contributed vs idiosyncratic returns) + are included. +License: GPL-2 +Depends: + R (>= 3.0.0), + xts (>= 0.9), + foreach (>= 1.4) +Imports: + PerformanceAnalytics(>= 1.1.0), + corrplot, + robust, + leaps, + lars, + strucchange, + lmtest, + sandwich, + lattice, + MASS, + boot, + parallel, + doSNOW, + RCurl, + bestglm +Suggests: + testthat, quantmod, knitr +LazyLoad: yes +LazyDataCompression: xz +URL: http://r-forge.r-project.org/R/?group_id=579 Modified: pkg/FactorAnalytics/NAMESPACE =================================================================== --- pkg/FactorAnalytics/NAMESPACE 2015-03-25 13:16:56 UTC (rev 3627) +++ pkg/FactorAnalytics/NAMESPACE 2015-04-13 06:38:17 UTC (rev 3628) @@ -1,70 +1,82 @@ -# Generated by roxygen2 (4.0.2): do not edit by hand - -S3method(coef,sfm) -S3method(coef,tsfm) -S3method(fitted,sfm) -S3method(fitted,tsfm) -S3method(fmCov,sfm) -S3method(fmCov,tsfm) -S3method(fmEsDecomp,sfm) -S3method(fmEsDecomp,tsfm) -S3method(fmSdDecomp,sfm) -S3method(fmSdDecomp,tsfm) -S3method(fmVaRDecomp,sfm) -S3method(fmVaRDecomp,tsfm) -S3method(plot,pafm) -S3method(plot,sfm) -S3method(plot,tsfm) -S3method(plot,tsfmUpDn) -S3method(predict,sfm) -S3method(predict,tsfm) -S3method(predict,tsfmUpDn) -S3method(print,pafm) -S3method(print,sfm) -S3method(print,summary.sfm) -S3method(print,summary.tsfm) -S3method(print,summary.tsfmUpDn) -S3method(print,tsfm) -S3method(print,tsfmUpDn) -S3method(residuals,sfm) -S3method(residuals,tsfm) -S3method(summary,pafm) -S3method(summary,sfm) -S3method(summary,tsfm) -S3method(summary,tsfmUpDn) -export(dCornishFisher) -export(fitSfm) -export(fitTsfm) -export(fitTsfmLagBeta) -export(fitTsfmMT) -export(fitTsfmUpDn) -export(fmCov) -export(fmEsDecomp) -export(fmSdDecomp) -export(fmVaRDecomp) -export(pCornishFisher) -export(paFm) -export(qCornishFisher) -export(rCornishFisher) -importFrom(MASS,ginv) -importFrom(PerformanceAnalytics,Return.cumulative) -importFrom(PerformanceAnalytics,VaR) -importFrom(PerformanceAnalytics,chart.ACFplus) -importFrom(PerformanceAnalytics,chart.Histogram) -importFrom(PerformanceAnalytics,chart.QQPlot) -importFrom(PerformanceAnalytics,chart.TimeSeries) -importFrom(PerformanceAnalytics,checkData) -importFrom(corrplot,corrplot) -importFrom(lars,cv.lars) -importFrom(lars,lars) -importFrom(lattice,barchart) -importFrom(lattice,panel.barchart) -importFrom(lattice,panel.grid) -importFrom(lattice,xyplot) -importFrom(leaps,regsubsets) -importFrom(lmtest,coeftest.default) -importFrom(robust,lmRob) -importFrom(robust,step.lmRob) -importFrom(sandwich,vcovHAC.default) -importFrom(sandwich,vcovHC.default) -importFrom(strucchange,efp) +# Generated by roxygen2 (4.1.0): do not edit by hand + +S3method(coef,sfm) +S3method(coef,tsfm) +S3method(fitted,sfm) +S3method(fitted,tsfm) +S3method(fmCov,sfm) +S3method(fmCov,tsfm) +S3method(fmEsDecomp,sfm) +S3method(fmEsDecomp,tsfm) +S3method(fmSdDecomp,sfm) +S3method(fmSdDecomp,tsfm) +S3method(fmVaRDecomp,sfm) +S3method(fmVaRDecomp,tsfm) +S3method(plot,pafm) +S3method(plot,sfm) +S3method(plot,tsfm) +S3method(plot,tsfmUpDn) +S3method(predict,sfm) +S3method(predict,tsfm) +S3method(predict,tsfmUpDn) +S3method(print,pafm) +S3method(print,sfm) +S3method(print,summary.sfm) +S3method(print,summary.tsfm) +S3method(print,summary.tsfmUpDn) +S3method(print,tsfm) +S3method(print,tsfmUpDn) +S3method(residuals,sfm) +S3method(residuals,tsfm) +S3method(summary,pafm) +S3method(summary,sfm) +S3method(summary,tsfm) +S3method(summary,tsfmUpDn) +export(dCornishFisher) +export(fitSfm) +export(fitTsfm) +export(fitTsfmLagBeta) +export(fitTsfmMT) +export(fitTsfmUpDn) +export(fmCov) +export(fmEsDecomp) +export(fmSdDecomp) +export(fmVaRDecomp) +export(fmmc) +export(fmmc.estimate.se) +export(pCornishFisher) +export(paFm) +export(qCornishFisher) +export(rCornishFisher) +importFrom(MASS,ginv) +importFrom(PerformanceAnalytics,Return.cumulative) +importFrom(PerformanceAnalytics,VaR) +importFrom(PerformanceAnalytics,chart.ACFplus) +importFrom(PerformanceAnalytics,chart.Histogram) +importFrom(PerformanceAnalytics,chart.QQPlot) +importFrom(PerformanceAnalytics,chart.TimeSeries) +importFrom(PerformanceAnalytics,checkData) +importFrom(RCurl,merge.list) +importFrom(bestglm,bestglm) +importFrom(boot,boot) +importFrom(corrplot,corrplot) +importFrom(doSNOW,registerDoSNOW) +importFrom(foreach,foreach) +importFrom(lars,cv.lars) +importFrom(lars,lars) +importFrom(lattice,barchart) +importFrom(lattice,panel.barchart) +importFrom(lattice,panel.grid) +importFrom(lattice,xyplot) +importFrom(leaps,regsubsets) +importFrom(lmtest,coeftest.default) +importFrom(parallel,clusterEvalQ) +importFrom(parallel,clusterExport) +importFrom(parallel,detectCores) +importFrom(parallel,makeCluster) +importFrom(parallel,stopCluster) +importFrom(robust,lmRob) +importFrom(robust,step.lmRob) +importFrom(sandwich,vcovHAC.default) +importFrom(sandwich,vcovHC.default) +importFrom(strucchange,efp) Added: pkg/FactorAnalytics/R/fmmc.R =================================================================== --- pkg/FactorAnalytics/R/fmmc.R (rev 0) +++ pkg/FactorAnalytics/R/fmmc.R 2015-04-13 06:38:17 UTC (rev 3628) @@ -0,0 +1,386 @@ +#' @title Functions to compute estimates and thier standard errors using fmmc +#' +#' Control default arguments. Usually for factorAnalytics. +#' +#' @details +#' This method takes in the additional arguments list and checks if parameters +#' are set. Then it defaults values if they are unset. Currently it controls the +#' fit.method(default: OLS) and variable.selection(default: subsets). If +#' variable.selection is set to values other than subsets/none then it will +#' default to subsets. +#' arguments for factorAnalytics +#' +#' @param ... Arguments that must be passed to fitTsfm +#' +#' +.fmmc.default.args <- function(...) { + add.args <- list(...) + if(!"fit.method" %in% names(add.args)) add.args[["fit.method"]] <- "LS" + + if(!"variable.selection" %in% names(add.args)) + add.args[["variable.selection"]] <- "subsets" + else { + if(!add.args[["variable.selection"]] %in% c("none", "subsets")) + add.args[["variable.selection"]] <- "subsets" + } + + if (add.args[["variable.selection"]] == "subsets") { + if(!"nvmax" %in% names(add.args)) + add.args[["nvmax"]] <- NA + } + + add.args +} + +#' Select factors based on BIC criteria +#' +#' @details +#' This method selects the best factors and based on the BIC criteria. It uses +#' the user supplied max count for max factors or defaults to half the total +#' number of factors +#' +#' @param data Data to use for selecting relevant factors. First column is the +#' response. The remaining columns is an exhaustive list of factors. +#' @param maxfactors An upper limit on the number of factors. +#' +#' +.fmmc.select.factors <- function(data, maxfactors) { + # default the max number of factors to half the number of factors + + maxfactors <- ifelse(is.na(maxfactors), floor((ncol(data) - 1)/2), + maxfactors) + if(maxfactors > 18) + warning("Max model size greater than 18. Consider reducing the size.") + + .data <- na.omit(cbind(data[,-1],data[,1])) + + fit <- c() + val <- tryCatch({ + fit <- bestglm(data.frame(na.omit(coredata(.data))), + IC="BIC",method="exhaustive", nvmax=maxfactors) + }, + error = function(e) NA, + warning = function(w) NA) + + if(inherits(val, "error")) { + warning(paste(colnames(data[1])," will be skipped. Model fitting failed")) + return(NA) + } + + fact.cols <- colnames(fit$BestModel$model)[-1] + fact.cols +} + + +#' This is the main implementation of the Factor Model Monte Carlo method. It returns +#' a fmmc object that contains the joint empirical density of factors and returns. This +#' fmmc object can be reused to for calucluting risk and performance estimates along +#' with standard errors for the estimates +#' +#' @details +#' This method takes in data, factors and residual type. It then does the following +#' 1. Fit a time series factor model to the data using user supplied selection and +#' fit variables or it defaults them to stepwise and OLS respectively. If any +#' of the betas are NA then the corresponding factors are dropped +#' 2. If the residual type beisdes empirical is specified then it fits the +#' corresponding distribution to the residuals and simulates from the fitted +#' distribution. The number of NA's in the simulated sample are the same as +#' original residuals. +#' 3. It then merges factors and non-NA residuals for each asset to create a full +#' outer join of the factors and residuals. We use this joined data to create new +#' simulated returns. Returns together with factors define a joint emperical density. +#' +#' @param R single vector of returns +#' @param factors matrix of factor returns +#' @param ... allows passing paramters to factorAnalytics. +#' @author Rohit Arora +#' +#' +.fmmc.proc <- function(R, factors ,... ) { + + # Check if the classes of Returns and factors are correct + if(is.null(nrow(R)) || is.null(nrow(factors))) { + warning("Inputs are not matrix") + return(NA) + } + + factors.data <- na.omit(factors) + T <- nrow(factors.data); T1 <- nrow(R) + if (T < T1) { + warning("Length of factors cannot be less than assets") + return(NA) + } + + # Start getting ready to fit a time-series factor model to the data. + .data <- as.matrix(merge(R,factors.data)) + + #default args if not set + add.args <- .fmmc.default.args(...) + fit.method <- add.args[["fit.method"]] + variable.selection <- add.args[["variable.selection"]] + + #short term hack till factorAnalytics fixes handling of "all subsets" + if(variable.selection == "subsets") { + + fact.cols <- .fmmc.select.factors(.data, add.args[["nvmax"]]) + if (0 == length(fact.cols)) { + warning(paste(colnames(R)," will be skipped. No suitable factor + exposures found")) + return(NA) + } + + factors.data <- factors.data[,fact.cols] + .data <- as.matrix(merge(R,factors.data)) + variable.selection <- add.args[["variable.selection"]] <- "none" + add.args[["nvmax"]] <- NULL + } + + # Lets fit the time-series model + args <- list(asset.names=colnames(R), + factor.names=colnames(factors.data), data=.data) + + args <- merge.list(args,add.args) + + # We do not need to remove NA's. Beta's do no change if NA's are not removed + possibleError <- tryCatch( + fit <- do.call(fitTsfm, args), + error=function(e) + e) + + if(inherits(possibleError, "error")) { + warning(paste("Timeseries model fitting failed for ", colnames(R))) + return(NA) + } + + resid <- do.call(merge,lapply(lapply(fit$asset.fit,residuals),as.xts)) + beta <- t(fit$beta) + + if(any(is.na(beta))) { + warning("some of the betas where NA in .fmmc.proc. Dropping those") + beta <- beta[!is.na(c(beta)), 1, drop=FALSE] + names.factors <- colnames(factors.data) + names.beta <- colnames(fit$beta) + factors.data <- as.matrix(factors.data[,names.factors %in% names.beta]) + } + + # define a joint empirical density for the factors and residuals and use + # that to calculate the returns. + .data <- as.matrix(merge(as.matrix(factors.data), resid)) + alpha <- matrix(as.numeric(fit$alpha), nrow=nrow(.data), ncol=1, byrow=TRUE) + + returns <- alpha + .data[,-ncol(.data),drop=FALSE] %*% beta + + .data[,ncol(.data),drop=FALSE] + + result <- list(bootdist = list(returns = returns, + factors = .data[,-ncol(.data),drop=FALSE]), + data = list(R = R, factors = factors.data), args = add.args) + result +} + +#' Statistic function for the boot call. It calculates the risk or performnace +#' meeasure by using the estimatation function in its argument list. +#' +#' @details +#' This method works as follows. +#' 1. Get data with factors and returns. +#' 2. Subset T rows from the data. +#' 3. Discard first TR-TR1 of the asset returns by setting them to NA +#' 4. calls .fmmc.proc method over the new data set to get a new joint empirical +#' distribution of returns and factors +#' 5. We use the new returns with the estimation function to calculate the +#' risk or performance measure. +#' +#' @param data matrix of (all factors + returns of just 1 asset) +#' @param indices row numbers generated by boot +#' @param args additinal paramters needed for subsetting the data and calulating +#' the perfomance/risk measure. +#' @author Rohit Arora +#' +#' +.fmmc.boot <- function(data, indices, args) { + + TR <- args$TR + TR1 <- args$TR1 + estimate.func <- args$estimate.func + fit.method <- args$fit.method + var.sel <- args$var.sel + + fun <- match.fun(estimate.func) + + # we just need TR rows of data + ind <- sample(indices, TR , replace = TRUE) + data <- data[ind,] + + # discard the first (TR-TR1) portion of returns if using fmmc. For + # complete data TR = TR1 + .data <- data + .data[1:(TR-TR1),ncol(.data)] <- NA + + # If the data does not have dates then it cannot be transformed to xts. + # So lets fake dates to make xts happy + .data <- as.xts(.data , order.by=seq(as.Date("1980/1/1"), by = "day", + length.out = nrow(.data))) + + # lets get a new empirical distribution of factors and returns for a new subset + fmmcObj <- .fmmc.proc(R=.data[,ncol(.data),drop=FALSE], + factors=.data[,-ncol(.data)], + fit.method = fit.method, variable.selection = var.sel) + + # lets calculate the performance or risk estimate + measure <- fun(fmmcObj$bootdist$returns) + measure +} + +#' Main function to calculate the risk/performance estimate and calculate the +#' standard error of the estimate using bootstrapping. +#' +#' @details +#' bootstrapping in our case can be painfully slow, so we exploit the parallel +#' capabilities of boot function. All cores on your machine are used. +#' We use the boot call from the boot library for calculating the estimate and +#' its standard error. +#' +#' @param fmmcObj object returned by fmmc proc. This is a comprehensive object +#' with all data for factors and returns. +#' @param nboot number of bootstap samples. Not sure how many repetations are +#' reuired but remember bias-variance tradeoff. Increasing nboot will only +#' reduce variance and not have a significant effect on bias(estimate) +#' @param estimate.func this is a handle to the function used for calulating +#' the perfomance/risk measure. +#' @param cl A cluster for running across multiple cores +#' @author Rohit Arora +#' +#' +.fmmc.se <- function(fmmcObj, nboot = 50, estimate.func, cl = NULL) { + + parallel <- if(is.null(cl)) "no" else "snow" + ncpus <- if(is.null(cl)) 1 else detectCores() + + # length of factors + TR <- nrow(fmmcObj$data$factors) + + # length of the asset returns + len <- nrow(fmmcObj$data$R) - + apply(fmmcObj$data$R, 2, function(col) which.min(is.na(col))) + 1 + + returns <- fmmcObj$bootdist$returns + factors <- fmmcObj$bootdist$factors + + # no need to do variable selection again. So lets turn it off + args <- list(TR = TR, TR1 = len, estimate.func = estimate.func, + fit.method = fmmcObj$args[["fit.method"]], var.sel = "none") + + result <- boot(data=cbind(factors, returns), statistic = .fmmc.boot, + R = nboot, parallel = parallel, ncpus = ncpus, cl = cl, args=args) + + se <- apply(result$t,2,sd) + se +} + +#' Worker function that acts between the fmmc procedure and calling method. +#' +#' @details +#' This method takes in data as single time series and factors as xts objects +#' It then calls the actual estimation procedure. +#' +#' @param R single vector of returns +#' @param factors matrix of factor returns +#' @param ... allows passing paramters to factorAnalytics. +#' @author Rohit Arora +#' +#' +#' +.fmmc.worker <- function(R, factors, ...) { + fmmc.obj <- .fmmc.proc(R=R, factors=factors, ...) + fmmc.obj +} + +#' Compute fmmc objects that can be used for calcuation of estimates and their +#' standard errors +#' +#' @details +#' This method takes in data and factors as xts objects where multiple +#' time series with different starting dates are merged together. It then +#' computes FMMC objects as described in Jiang and Martin (2013) +#' +#' @param R matrix of returns +#' @param factors matrix of factor returns +#' @param parallel flag to utilize multiplecores on the cpu. All cores are used. +#' @param ... Arguments that must be passed to fitTsfm +#' +#' @importFrom parallel makeCluster detectCores clusterEvalQ clusterExport +#' stopCluster +#' @importFrom boot boot +#' @importFrom foreach foreach +#' @importFrom doSNOW registerDoSNOW +#' @importFrom RCurl merge.list +#' @importFrom bestglm bestglm +#' +#' @return returns an list of fmmc objects +#' +#' @author Rohit Arora +#' @export +#' +#' +fmmc <- function(R, factors, parallel=FALSE, ...) { + + ret <- NA + assets.count <- ncol(R) + + if (parallel) { + cl <- makeCluster(detectCores()) + registerDoSNOW(cl) + ret <- foreach (i = 1:assets.count) %dopar% .fmmc.worker(R[,i], factors, ...) + stopCluster(cl) + } else + ret <- foreach (i = 1:assets.count) %do% .fmmc.worker(R[,i], factors, ...) + + result <- ret[lapply(ret,length) > 1] + result +} + +#' Main function to calculate the standard errror of the estimate +#' +#' @details +#' This method takes in a list of fmmc objects and a callback function to compute +#' an estimate. The first argument of the callback function must be the data +#' bootstrapped using fmmc procedure. The remaining arguments can be suitably +#' bound to the parameters as needed. This function can also be used to calculate +#' the standard error using the se flag. +#' +#' @param fmmcObjs A list of fmmc objects computed using .fmmc.proc and containing +#' bootstrapped returns +#' @param fun A callback function where the first argument is returns and all the +#' other arguments are bounded to values +#' @param se A flag to indicate if standard error for the estimate must be calculated +#' @param parallel A flag to indicate if multiple cpu cores must be used +#' @param nboot Number of bootstrap samples +#' +#' @return returns the estimates and thier standard errors given fmmc objects +#' +#' @author Rohit Arora +#' @export +#' +fmmc.estimate.se <- function(fmmcObjs, fun=NULL, se=FALSE, nboot=100, + parallel = FALSE) { + + est <- se.est <- rep(NA, length(fmmcObjs)) + result <- cbind(est, se.est); colnames(result) <- c("estimate","se") + rownames(result) <- unlist(lapply(fmmcObjs, function(obj) colnames(obj$data$R))) + + if(is.null(fun)) return(result) + + cl <- NULL + if(parallel) { + cl <- makeCluster(detectCores()) + clusterEvalQ(cl, library(xts)) + } + + result[,1] <- unlist(lapply(fmmcObjs, function(obj) fun(obj$bootdist$returns))) + result[,2] <- if(se) unlist( + lapply(fmmcObjs, function(obj) .fmmc.se(obj, nboot, fun, cl))) + + if(parallel) stopCluster(cl) + + result +} \ No newline at end of file Added: pkg/FactorAnalytics/man/fmmc.Rd =================================================================== --- pkg/FactorAnalytics/man/fmmc.Rd (rev 0) +++ pkg/FactorAnalytics/man/fmmc.Rd 2015-04-13 06:38:17 UTC (rev 3628) @@ -0,0 +1,34 @@ +% Generated by roxygen2 (4.1.0): do not edit by hand +% Please edit documentation in R/fmmc.R +\name{fmmc} +\alias{fmmc} +\title{Compute fmmc objects that can be used for calcuation of estimates and their +standard errors} +\usage{ +fmmc(R, factors, parallel = FALSE, ...) +} +\arguments{ +\item{R}{matrix of returns} + +\item{factors}{matrix of factor returns} + +\item{parallel}{flag to utilize multiplecores on the cpu. All cores are used.} + +\item{...}{Arguments that must be passed to fitTsfm} +} +\value{ +returns an list of fmmc objects +} +\description{ +Compute fmmc objects that can be used for calcuation of estimates and their +standard errors +} +\details{ +This method takes in data and factors as xts objects where multiple +time series with different starting dates are merged together. It then +computes FMMC objects as described in Jiang and Martin (2013) +} +\author{ +Rohit Arora +} + Added: pkg/FactorAnalytics/man/fmmc.estimate.se.Rd =================================================================== --- pkg/FactorAnalytics/man/fmmc.estimate.se.Rd (rev 0) +++ pkg/FactorAnalytics/man/fmmc.estimate.se.Rd 2015-04-13 06:38:17 UTC (rev 3628) @@ -0,0 +1,39 @@ +% Generated by roxygen2 (4.1.0): do not edit by hand +% Please edit documentation in R/fmmc.R +\name{fmmc.estimate.se} +\alias{fmmc.estimate.se} +\title{Main function to calculate the standard errror of the estimate} +\usage{ +fmmc.estimate.se(fmmcObjs, fun = NULL, se = FALSE, nboot = 100, + parallel = FALSE) +} +\arguments{ +\item{fmmcObjs}{A list of fmmc objects computed using .fmmc.proc and containing +bootstrapped returns} + +\item{fun}{A callback function where the first argument is returns and all the +other arguments are bounded to values} + +\item{se}{A flag to indicate if standard error for the estimate must be calculated} + +\item{nboot}{Number of bootstrap samples} + +\item{parallel}{A flag to indicate if multiple cpu cores must be used} +} +\value{ +returns the estimates and thier standard errors given fmmc objects +} +\description{ +Main function to calculate the standard errror of the estimate +} +\details{ +This method takes in a list of fmmc objects and a callback function to compute +an estimate. The first argument of the callback function must be the data +bootstrapped using fmmc procedure. The remaining arguments can be suitably +bound to the parameters as needed. This function can also be used to calculate +the standard error using the se flag. +} +\author{ +Rohit Arora +} + Modified: pkg/FactorAnalytics/vignettes/FA.bib =================================================================== --- pkg/FactorAnalytics/vignettes/FA.bib 2015-03-25 13:16:56 UTC (rev 3627) +++ pkg/FactorAnalytics/vignettes/FA.bib 2015-04-13 06:38:17 UTC (rev 3628) @@ -1,169 +1,162 @@ - at article{bai2002determining, - title={Determining the number of factors in approximate factor models}, - author={Bai, Jushan and Ng, Serena}, - journal={Econometrica}, - volume={70}, - number={1}, - pages={191--221}, - year={2002}, - publisher={Wiley Online Library} -} - - at book{berndt1991practice, - title={The practice of econometrics: classic and contemporary}, - author={Berndt, Ernst R}, - year={1991}, - publisher={Addison-Wesley Reading, MA} -} - - at article{chen1986economic, - title={Economic forces and the stock market}, - author={Chen, Nai-Fu and Roll, Richard and Ross, Stephen A}, - journal={Journal of business}, - pages={383--403}, - year={1986}, - publisher={JSTOR} -} - - at book{christopherson2009portfolio, - title={Portfolio performance measurement and benchmarking}, - author={Christopherson, Jon A and Carino, David R and Ferson, Wayne E}, - year={2009}, - publisher={McGraw Hill Professional} -} - - at article{connor1988risk, - title={Risk and return in an equilibrium APT: Application of a new test methodology}, - author={Connor, Gregory and Korajczyk, Robert A}, - journal={Journal of Financial Economics}, - volume={21}, - number={2}, - pages={255--289}, - year={1988}, - publisher={Elsevier} -} - - at article{connor1993test, - title={A test for the number of factors in an approximate factor model}, - author={Connor, Gregory and Korajczyk, Robert A}, - journal={The Journal of Finance}, - volume={48}, - number={4}, - pages={1263--1291}, - year={1993}, - publisher={Wiley Online Library} -} - - at article{efron2004least, - title={Least angle regression}, - author={Efron, Bradley and Hastie, Trevor and Johnstone, Iain and Tibshirani, Robert and others}, - journal={The Annals of statistics}, - volume={32}, - number={2}, - pages={407--499}, - year={2004}, - publisher={Institute of Mathematical Statistics} -} - - at article{epperlein2006portfolio, - title={Portfolio risk analysis Cracking VAR with kernels}, - author={Epperlein, Eduardo and Smillie, Alan}, - journal={RISK-LONDON-RISK MAGAZINE LIMITED-}, - volume={19}, - number={8}, - pages={70}, - year={2006}, - publisher={RISK MAGAZINE LIMITED} -} - - at article{hallerbach2003decomposing, - title={Decomposing Portfolio Value-at-Risk: A General Analysis}, - author={Hallerbach}, - journal={Journal of Risk}, - volume={5}, - number={2}, - pages={1--18}, - year={2003}, - publisher={http://www.risk.net/} -} - - at book{hastie2009elements, - title={The elements of statistical learning}, - author={Hastie, Trevor and Tibshirani, Robert and Friedman, Jerome and Hastie, T and Friedman, J and Tibshirani, R}, - volume={2}, - number={1}, - year={2009}, - publisher={Springer} -} - - at article{henriksson1981market, - title={On market timing and investment performance. II. Statistical procedures for evaluating forecasting skills}, - author={Henriksson, Roy D and Merton, Robert C}, - journal={Journal of business}, - pages={513--533}, - year={1981}, - publisher={JSTOR} -} - - at misc{kahn1999active, - title={Active Portfolio Management}, - author={Kahn, R and Grinold, R}, - year={1999}, - publisher={McGraw-Hill} -} - - at article{meucci2007risk, - title={Risk contributions from generic user-defined factors}, - author={Meucci, Attilio}, - journal={RISK-LONDON-RISK MAGAZINE LIMITED-}, - volume={20}, - number={6}, - pages={84}, - year={2007}, - publisher={RISK MAGAZINE LIMITED} -} - - at book{ruppert2010statistics, - title={Statistics and data analysis for financial engineering}, - author={Ruppert, David}, - year={2010}, - publisher={Springer} -} - - at article{sharpe1964capital, - title={Capital asset prices: A theory of market equilibrium under conditions of risk*}, - author={Sharpe, William F}, - journal={The journal of finance}, - volume={19}, - number={3}, - pages={425--442}, - year={1964}, - publisher={Wiley Online Library} -} - - at article{treynor1966can, - title={Can mutual funds outguess the market}, - author={Treynor, Jack and Mazuy, Kay}, - journal={Harvard business review}, - volume={44}, - number={4}, - pages={131--136}, - year={1966} -} - - at article{yamai2002comparative, - title={Comparative analyses of expected shortfall and value-at-risk: their estimation error, decomposition, and optimization}, - author={Yamai, Yasuhiro and Yoshiba, Toshinao}, - journal={Monetary and economic studies}, - volume={20}, - number={1}, - pages={87--121}, - year={2002}, - publisher={Institute for Monetary and Economic Studies, Bank of Japan} -} - - at article{zivot2006modeling, - title={Modeling Financial Time Series with S-Plus Springer-Verlag}, - author={Zivot, Eric and Jia-hui, WANG}, - year={2006} -} + at article{bai2002determining, +author = {Bai, Jushan and Ng, Serena}, +journal = {Econometrica}, +number = {1}, +pages = {191--221}, +publisher = {Wiley Online Library}, +title = {{Determining the number of factors in approximate factor models}}, +volume = {70}, +year = {2002} +} + at book{berndt1991practice, +author = {Berndt, Ernst R}, +publisher = {Addison-Wesley Reading, MA}, +title = {{The practice of econometrics: classic and contemporary}}, +year = {1991} +} + at article{chen1986economic, +author = {Chen, Nai-Fu and Roll, Richard and Ross, Stephen A}, +journal = {Journal of business}, +pages = {383--403}, +publisher = {JSTOR}, +title = {{Economic forces and the stock market}}, +year = {1986} +} + at book{christopherson2009portfolio, +author = {Christopherson, Jon A and Carino, David R and Ferson, Wayne E}, +publisher = {McGraw Hill Professional}, +title = {{Portfolio performance measurement and benchmarking}}, +year = {2009} +} + at article{connor1988risk, +author = {Connor, Gregory and Korajczyk, Robert A}, +journal = {Journal of Financial Economics}, +number = {2}, +pages = {255--289}, +publisher = {Elsevier}, +title = {{Risk and return in an equilibrium APT: Application of a new test methodology}}, +volume = {21}, +year = {1988} +} + at article{connor1993test, +author = {Connor, Gregory and Korajczyk, Robert A}, +journal = {The Journal of Finance}, +number = {4}, +pages = {1263--1291}, +publisher = {Wiley Online Library}, +title = {{A test for the number of factors in an approximate factor model}}, +volume = {48}, +year = {1993} +} + at article{efron2004least, +author = {Efron, Bradley and Hastie, Trevor and Johnstone, Iain and Tibshirani, Robert and Others}, +journal = {The Annals of statistics}, +number = {2}, +pages = {407--499}, +publisher = {Institute of Mathematical Statistics}, +title = {{Least angle regression}}, +volume = {32}, +year = {2004} +} + at article{epperlein2006portfolio, +author = {Epperlein, Eduardo and Smillie, Alan}, +journal = {RISK-LONDON-RISK MAGAZINE LIMITED-}, +number = {8}, +pages = {70}, +publisher = {RISK MAGAZINE LIMITED}, +title = {{Portfolio risk analysis Cracking VAR with kernels}}, +volume = {19}, +year = {2006} +} + at article{hallerbach2003decomposing, +author = {Hallerbach}, +journal = {Journal of Risk}, +number = {2}, +pages = {1--18}, +publisher = {http://www.risk.net/}, +title = {{Decomposing Portfolio Value-at-Risk: A General Analysis}}, +volume = {5}, +year = {2003} +} + at book{hastie2009elements, +author = {Hastie, Trevor and Tibshirani, Robert and Friedman, Jerome and Hastie, T and Friedman, J and Tibshirani, R}, +number = {1}, +publisher = {Springer}, +title = {{The elements of statistical learning}}, +volume = {2}, +year = {2009} +} + at article{henriksson1981market, +author = {Henriksson, Roy D and Merton, Robert C}, +journal = {Journal of business}, +pages = {513--533}, +publisher = {JSTOR}, +title = {{On market timing and investment performance. II. Statistical procedures for evaluating forecasting skills}}, +year = {1981} +} + at misc{kahn1999active, +author = {Kahn, R and Grinold, R}, +publisher = {McGraw-Hill}, +title = {{Active Portfolio Management}}, +year = {1999} +} + at article{meucci2007risk, +author = {Meucci, Attilio}, +journal = {RISK-LONDON-RISK MAGAZINE LIMITED-}, +number = {6}, +pages = {84}, +publisher = {RISK MAGAZINE LIMITED}, +title = {{Risk contributions from generic user-defined factors}}, +volume = {20}, +year = {2007} +} + at book{ruppert2010statistics, +author = {Ruppert, David}, +publisher = {Springer}, +title = {{Statistics and data analysis for financial engineering}}, +year = {2010} +} + at article{sharpe1964capital, +author = {Sharpe, William F}, +journal = {The journal of finance}, +number = {3}, +pages = {425--442}, +publisher = {Wiley Online Library}, +title = {{Capital asset prices: A theory of market equilibrium under conditions of risk*}}, +volume = {19}, +year = {1964} [TRUNCATED] To get the complete diff run: svnlook diff /svnroot/returnanalytics -r 3628 From noreply at r-forge.r-project.org Wed Apr 15 02:10:22 2015 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Wed, 15 Apr 2015 02:10:22 +0200 (CEST) Subject: [Returnanalytics-commits] r3629 - in pkg/FactorAnalytics: . R man vignettes Message-ID: <20150415001022.6CDE0184501@r-forge.r-project.org> Author: pragnya Date: 2015-04-15 02:10:21 +0200 (Wed, 15 Apr 2015) New Revision: 3629 Modified: pkg/FactorAnalytics/DESCRIPTION pkg/FactorAnalytics/NAMESPACE pkg/FactorAnalytics/R/Misc.R pkg/FactorAnalytics/R/fitTsfm.R pkg/FactorAnalytics/R/plot.tsfm.r pkg/FactorAnalytics/R/summary.tsfm.r pkg/FactorAnalytics/man/CornishFisher.Rd pkg/FactorAnalytics/man/fitSfm.Rd pkg/FactorAnalytics/man/fitTsfm.Rd pkg/FactorAnalytics/man/fitTsfm.control.Rd pkg/FactorAnalytics/man/fitTsfmLagBeta.Rd pkg/FactorAnalytics/man/fitTsfmMT.Rd pkg/FactorAnalytics/man/fitTsfmUpDn.Rd pkg/FactorAnalytics/man/fmCov.Rd pkg/FactorAnalytics/man/fmEsDecomp.Rd pkg/FactorAnalytics/man/fmSdDecomp.Rd pkg/FactorAnalytics/man/fmVaRDecomp.Rd pkg/FactorAnalytics/man/fmmc.Rd pkg/FactorAnalytics/man/fmmc.estimate.se.Rd pkg/FactorAnalytics/man/paFm.Rd pkg/FactorAnalytics/man/plot.pafm.Rd pkg/FactorAnalytics/man/plot.sfm.Rd pkg/FactorAnalytics/man/plot.tsfm.Rd pkg/FactorAnalytics/man/plot.tsfmUpDn.Rd pkg/FactorAnalytics/man/predict.sfm.Rd pkg/FactorAnalytics/man/predict.tsfm.Rd pkg/FactorAnalytics/man/predict.tsfmUpDn.Rd pkg/FactorAnalytics/man/print.pafm.Rd pkg/FactorAnalytics/man/print.sfm.Rd pkg/FactorAnalytics/man/print.tsfm.Rd pkg/FactorAnalytics/man/print.tsfmUpDn.Rd pkg/FactorAnalytics/man/summary.pafm.Rd pkg/FactorAnalytics/man/summary.sfm.Rd pkg/FactorAnalytics/man/summary.tsfm.Rd pkg/FactorAnalytics/man/summary.tsfmUpDn.Rd pkg/FactorAnalytics/vignettes/fitTsfm_vignette.R pkg/FactorAnalytics/vignettes/fitTsfm_vignette.Rnw pkg/FactorAnalytics/vignettes/fitTsfm_vignette.pdf Log: Expanded and modified plot.tsfm; fixed minor bugs in fitTsfm, summary.tsfm Modified: pkg/FactorAnalytics/DESCRIPTION =================================================================== --- pkg/FactorAnalytics/DESCRIPTION 2015-04-13 06:38:17 UTC (rev 3628) +++ pkg/FactorAnalytics/DESCRIPTION 2015-04-15 00:10:21 UTC (rev 3629) @@ -1,42 +1,43 @@ -Package: factorAnalytics -Type: Package -Title: Factor Analytics -Version:2.0.16 -Date:2015-03-21 -Author: Eric Zivot, Sangeetha Srinivasan and Yi-An Chen -Maintainer: Sangeetha Srinivasan -Description: An R package for the estimation and risk analysis of linear factor - models for asset returns and portfolios. It contains model fitting methods - for the three major types of factor models: time series (or, macroeconomic) - factor model, fundamental factor model and statistical factor model. They - allow for different types of distributions to be specified for modeling the - fat-tailed behavior of financial returns, including Edgeworth expansions. - Risk analysis measures such as VaR and ES, as well as performance - attribution for factor models (factor-contributed vs idiosyncratic returns) - are included. -License: GPL-2 -Depends: - R (>= 3.0.0), - xts (>= 0.9), - foreach (>= 1.4) -Imports: - PerformanceAnalytics(>= 1.1.0), - corrplot, - robust, - leaps, - lars, - strucchange, - lmtest, - sandwich, - lattice, - MASS, - boot, - parallel, - doSNOW, - RCurl, - bestglm -Suggests: - testthat, quantmod, knitr -LazyLoad: yes -LazyDataCompression: xz -URL: http://r-forge.r-project.org/R/?group_id=579 +Package: factorAnalytics +Type: Package +Title: Factor Analytics +Version:2.0.17 +Date:2015-04-14 +Author: Eric Zivot, Sangeetha Srinivasan and Yi-An Chen +Maintainer: Sangeetha Srinivasan +Description: An R package for the estimation and risk analysis of linear factor + models for asset returns and portfolios. It contains model fitting methods + for the three major types of factor models: time series (or, macroeconomic) + factor model, fundamental factor model and statistical factor model. They + allow for different types of distributions to be specified for modeling the + fat-tailed behavior of financial returns, including Edgeworth expansions. + Risk analysis measures such as VaR and ES, as well as performance + attribution for factor models (factor-contributed vs idiosyncratic returns) + are included. +License: GPL-2 +Depends: + R (>= 3.0.0), + xts (>= 0.9), + foreach (>= 1.4) +Imports: + PerformanceAnalytics(>= 1.4), + corrplot, + robust, + leaps, + lars, + strucchange, + lmtest, + sandwich, + lattice, + MASS, + sn, + boot, + parallel, + doSNOW, + RCurl, + bestglm +Suggests: + testthat, quantmod, knitr +LazyLoad: yes +LazyDataCompression: xz +URL: http://r-forge.r-project.org/R/?group_id=579 Modified: pkg/FactorAnalytics/NAMESPACE =================================================================== --- pkg/FactorAnalytics/NAMESPACE 2015-04-13 06:38:17 UTC (rev 3628) +++ pkg/FactorAnalytics/NAMESPACE 2015-04-15 00:10:21 UTC (rev 3629) @@ -1,82 +1,86 @@ -# Generated by roxygen2 (4.1.0): do not edit by hand - -S3method(coef,sfm) -S3method(coef,tsfm) -S3method(fitted,sfm) -S3method(fitted,tsfm) -S3method(fmCov,sfm) -S3method(fmCov,tsfm) -S3method(fmEsDecomp,sfm) -S3method(fmEsDecomp,tsfm) -S3method(fmSdDecomp,sfm) -S3method(fmSdDecomp,tsfm) -S3method(fmVaRDecomp,sfm) -S3method(fmVaRDecomp,tsfm) -S3method(plot,pafm) -S3method(plot,sfm) -S3method(plot,tsfm) -S3method(plot,tsfmUpDn) -S3method(predict,sfm) -S3method(predict,tsfm) -S3method(predict,tsfmUpDn) -S3method(print,pafm) -S3method(print,sfm) -S3method(print,summary.sfm) -S3method(print,summary.tsfm) -S3method(print,summary.tsfmUpDn) -S3method(print,tsfm) -S3method(print,tsfmUpDn) -S3method(residuals,sfm) -S3method(residuals,tsfm) -S3method(summary,pafm) -S3method(summary,sfm) -S3method(summary,tsfm) -S3method(summary,tsfmUpDn) -export(dCornishFisher) -export(fitSfm) -export(fitTsfm) -export(fitTsfmLagBeta) -export(fitTsfmMT) -export(fitTsfmUpDn) -export(fmCov) -export(fmEsDecomp) -export(fmSdDecomp) -export(fmVaRDecomp) -export(fmmc) -export(fmmc.estimate.se) -export(pCornishFisher) -export(paFm) -export(qCornishFisher) -export(rCornishFisher) -importFrom(MASS,ginv) -importFrom(PerformanceAnalytics,Return.cumulative) -importFrom(PerformanceAnalytics,VaR) -importFrom(PerformanceAnalytics,chart.ACFplus) -importFrom(PerformanceAnalytics,chart.Histogram) -importFrom(PerformanceAnalytics,chart.QQPlot) -importFrom(PerformanceAnalytics,chart.TimeSeries) -importFrom(PerformanceAnalytics,checkData) -importFrom(RCurl,merge.list) -importFrom(bestglm,bestglm) -importFrom(boot,boot) -importFrom(corrplot,corrplot) -importFrom(doSNOW,registerDoSNOW) -importFrom(foreach,foreach) -importFrom(lars,cv.lars) -importFrom(lars,lars) -importFrom(lattice,barchart) -importFrom(lattice,panel.barchart) -importFrom(lattice,panel.grid) -importFrom(lattice,xyplot) -importFrom(leaps,regsubsets) -importFrom(lmtest,coeftest.default) -importFrom(parallel,clusterEvalQ) -importFrom(parallel,clusterExport) -importFrom(parallel,detectCores) -importFrom(parallel,makeCluster) -importFrom(parallel,stopCluster) -importFrom(robust,lmRob) -importFrom(robust,step.lmRob) -importFrom(sandwich,vcovHAC.default) -importFrom(sandwich,vcovHC.default) -importFrom(strucchange,efp) +# Generated by roxygen2 (4.1.0): do not edit by hand + +S3method(coef,sfm) +S3method(coef,tsfm) +S3method(fitted,sfm) +S3method(fitted,tsfm) +S3method(fmCov,sfm) +S3method(fmCov,tsfm) +S3method(fmEsDecomp,sfm) +S3method(fmEsDecomp,tsfm) +S3method(fmSdDecomp,sfm) +S3method(fmSdDecomp,tsfm) +S3method(fmVaRDecomp,sfm) +S3method(fmVaRDecomp,tsfm) +S3method(plot,pafm) +S3method(plot,sfm) +S3method(plot,tsfm) +S3method(plot,tsfmUpDn) +S3method(predict,sfm) +S3method(predict,tsfm) +S3method(predict,tsfmUpDn) +S3method(print,pafm) +S3method(print,sfm) +S3method(print,summary.sfm) +S3method(print,summary.tsfm) +S3method(print,summary.tsfmUpDn) +S3method(print,tsfm) +S3method(print,tsfmUpDn) +S3method(residuals,sfm) +S3method(residuals,tsfm) +S3method(summary,pafm) +S3method(summary,sfm) +S3method(summary,tsfm) +S3method(summary,tsfmUpDn) +export(dCornishFisher) +export(fitSfm) +export(fitTsfm) +export(fitTsfmLagBeta) +export(fitTsfmMT) +export(fitTsfmUpDn) +export(fmCov) +export(fmEsDecomp) +export(fmSdDecomp) +export(fmVaRDecomp) +export(fmmc) +export(fmmc.estimate.se) +export(pCornishFisher) +export(paFm) +export(qCornishFisher) +export(rCornishFisher) +importFrom(MASS,ginv) +importFrom(PerformanceAnalytics,Return.cumulative) +importFrom(PerformanceAnalytics,VaR) +importFrom(PerformanceAnalytics,chart.ACFplus) +importFrom(PerformanceAnalytics,chart.Correlation) +importFrom(PerformanceAnalytics,chart.Histogram) +importFrom(PerformanceAnalytics,chart.QQPlot) +importFrom(PerformanceAnalytics,chart.TimeSeries) +importFrom(PerformanceAnalytics,checkData) +importFrom(RCurl,merge.list) +importFrom(bestglm,bestglm) +importFrom(boot,boot) +importFrom(corrplot,corrplot) +importFrom(corrplot,corrplot.mixed) +importFrom(doSNOW,registerDoSNOW) +importFrom(foreach,foreach) +importFrom(lars,cv.lars) +importFrom(lars,lars) +importFrom(lattice,barchart) +importFrom(lattice,panel.barchart) +importFrom(lattice,panel.grid) +importFrom(lattice,xyplot) +importFrom(leaps,regsubsets) +importFrom(lmtest,coeftest.default) +importFrom(parallel,clusterEvalQ) +importFrom(parallel,clusterExport) +importFrom(parallel,detectCores) +importFrom(parallel,makeCluster) +importFrom(parallel,stopCluster) +importFrom(robust,lmRob) +importFrom(robust,step.lmRob) +importFrom(sandwich,vcovHAC.default) +importFrom(sandwich,vcovHC.default) +importFrom(sn,dst) +importFrom(sn,st.mple) +importFrom(strucchange,efp) Modified: pkg/FactorAnalytics/R/Misc.R =================================================================== --- pkg/FactorAnalytics/R/Misc.R 2015-04-13 06:38:17 UTC (rev 3628) +++ pkg/FactorAnalytics/R/Misc.R 2015-04-15 00:10:21 UTC (rev 3629) @@ -5,13 +5,14 @@ #' where they are needed and the namespace file. #' #' @importFrom PerformanceAnalytics checkData VaR chart.TimeSeries chart.ACFplus -#' chart.Histogram chart.QQPlot Return.cumulative +#' chart.Histogram chart.QQPlot Return.cumulative chart.Correlation #' @importFrom robust lmRob step.lmRob #' @importFrom leaps regsubsets #' @importFrom lars lars cv.lars #' @importFrom lmtest coeftest.default #' @importFrom sandwich vcovHC.default vcovHAC.default -#' @importFrom lattice barchart panel.barchart panel.grid xyplot -#' @importFrom corrplot corrplot +#' @importFrom lattice barchart panel.barchart panel.grid +#' @importFrom corrplot corrplot.mixed #' @importFrom strucchange efp -#' @importFrom MASS ginv \ No newline at end of file +#' @importFrom MASS ginv +#' @importFrom sn dst st.mple \ No newline at end of file Modified: pkg/FactorAnalytics/R/fitTsfm.R =================================================================== --- pkg/FactorAnalytics/R/fitTsfm.R 2015-04-13 06:38:17 UTC (rev 3628) +++ pkg/FactorAnalytics/R/fitTsfm.R 2015-04-15 00:10:21 UTC (rev 3629) @@ -92,7 +92,7 @@ #' \item{fitted}{xts data object of fitted values; iff #' \code{variable.selection="lars"}} #' \item{call}{the matched function call.} -#' \item{data}{xts data object containing the assets and factors.} +#' \item{data}{xts data object containing the asset(s) and factor(s) returns.} #' \item{asset.names}{asset.names as input.} #' \item{factor.names}{factor.names as input.} #' \item{mkt.name}{mkt.name as input} @@ -185,7 +185,7 @@ if (missing(factor.names) && !is.null(mkt.name)) { factor.names <- NULL } - + # extract arguments to pass to different fit and variable selection functions decay <- control$decay nvmin <- control$nvmin @@ -193,7 +193,7 @@ m1 <- match(c("weights","model","x","y","qr"), names(control), 0L) lm.args <- control[m1, drop=TRUE] - m2 <- match(c("weights","model","x","y","nrep", "efficiency"), + m2 <- match(c("weights","model","x","y","nrep","efficiency"), names(control), 0L) lmRob.args <- control[m2, drop=TRUE] m3 <- match(c("scope","scale","direction","trace","steps","k"), @@ -410,14 +410,13 @@ for (i in asset.names) { # completely remove NA cases reg.xts <- na.omit(dat.xts[, c(i, factor.names)]) - # convert to matrix - reg.mat <- as.matrix(reg.xts) + # convert data to mat/vec + xmat <- as.matrix(reg.xts[,factor.names]) + yvec <- as.matrix(reg.xts)[,i] # fit lars regression model - lars.fit <- do.call(lars, c(list(x=reg.mat[,factor.names],y=reg.mat[,i]), - lars.args)) + lars.fit <- do.call(lars, c(list(x=xmat, y=yvec),lars.args)) lars.sum <- summary(lars.fit) - lars.cv <- do.call(cv.lars, c(list(x=reg.mat[,factor.names],y=reg.mat[,i], - mode="step"),cv.lars.args)) + lars.cv <- do.call(cv.lars, c(list(x=xmat,y=yvec,mode="step"),cv.lars.args)) # including plot.it=FALSE to cv.lars strangely gives an error: "Argument s # out of range". And, specifying index=seq(nrow(lars.fit$beta)-1) resolves # the issue, but care needs to be taken for small N @@ -431,8 +430,7 @@ } # get factor model coefficients & fitted values at the step obtained above coef.lars <- predict(lars.fit, s=s, type="coef", mode="step") - fitted.lars <- predict(lars.fit, reg.mat[,factor.names], s=s, type="fit", - mode="step") + fitted.lars <- predict(lars.fit, xmat, s=s, type="fit", mode="step") fitted.list[[i]] <- xts(fitted.lars$fit, index(reg.xts)) # extract and assign the results asset.fit[[i]] = lars.fit @@ -507,13 +505,13 @@ if (length(object$asset.names)>1) { # get fitted values from each linear factor model fit # and convert them into xts/zoo objects - fitted.list = sapply(object$asset.fit, - function(x) checkData(fitted(x,...))) + fitted.list = lapply(object$asset.fit, + function(x) checkData(fitted(x))) # this is a list of xts objects, indexed by the asset name # merge the objects in the list into one xts object fitted.xts <- do.call(merge, fitted.list) } else { - fitted.xts <- checkData(fitted(object$asset.fit[[1]],...)) + fitted.xts <- checkData(fitted(object$asset.fit[[1]])) colnames(fitted.xts) <- object$asset.names } } @@ -535,13 +533,13 @@ if (length(object$asset.names)>1) { # get residuals from each linear factor model fit # and convert them into xts/zoo objects - residuals.list = sapply(object$asset.fit, - function(x) checkData(residuals(x,...))) + residuals.list = lapply(object$asset.fit, + function(x) checkData(residuals(x))) # this is a list of xts objects, indexed by the asset name # merge the objects in the list into one xts object residuals.xts <- do.call(merge, residuals.list) } else { - residuals.xts <- checkData(residuals(object$asset.fit[[1]],...)) + residuals.xts <- checkData(residuals(object$asset.fit[[1]])) colnames(residuals.xts) <- object$asset.names } } Modified: pkg/FactorAnalytics/R/plot.tsfm.r =================================================================== --- pkg/FactorAnalytics/R/plot.tsfm.r 2015-04-13 06:38:17 UTC (rev 3628) +++ pkg/FactorAnalytics/R/plot.tsfm.r 2015-04-15 00:10:21 UTC (rev 3629) @@ -20,12 +20,17 @@ #' In case the \code{tsfm} object \code{x} contains only a single asset fit, #' plot.tsfm can infer \code{asset.name} without user input. #' -#' CUSUM plots (individual asset plot options 14, 15 and 16) are applicable +#' CUSUM plots (individual asset plot options 15, 16 and 17) are applicable #' only for \code{fit.method="LS"}. #' -#' Rolling estimates (individual asset plot option 17) is not applicable for -#' \code{variable.slection="lars"}. +#' Modified residuals, rolling regression and single factor model plots +#' (individual asset plot options 4, 18 and 19) are not applicable for +#' \code{variable.selection="lars"}. #' +#' The last option for plotting asset returns vs. factor returns (individual +#' asset plot option 19 and group plot 12) are only applicable for single factor +#' models. +#' #' @param x an object of class \code{tsfm} produced by \code{fitTsfm}. #' @param which a number to indicate the type of plot. If a subset of the plots #' is required, specify a subset of the numbers 1:10 for group plots and 1:16 @@ -34,48 +39,53 @@ #' For plots of a group of assets: \cr #' 1 = Factor model coefficients: Alpha, \cr #' 2 = Factor model coefficients: Betas, \cr -#' 3 = Actual and Fitted asset returns, \cr +#' 3 = Actual and fitted, \cr #' 4 = R-squared, \cr -#' 5 = Residual Volatility,\cr -#' 6 = Factor Model Residual Correlation \cr -#' 7 = Factor Model Correlation,\cr -#' 8 = Factor Contribution to SD,\cr -#' 9 = Factor Contribution to ES,\cr -#' 10 = Factor Contribution to VaR \cr \cr +#' 5 = Residual volatility,\cr +#' 6 = Factor model residuals scatterplot matrix, with histograms, density overlays, correlations and significance stars, \cr +#' 7 = Factor model residual correlation \cr +#' 8 = Factor model return correlation,\cr +#' 9 = Factor contribution to SD,\cr +#' 10 = Factor contribution to ES,\cr +#' 11 = Factor contribution to VaR, \cr +#' 12 = Asset returns vs factor returns (single factor model) \cr \cr #' For individual asset plots:\cr -#' 1 = Actual and fitted returns,\cr -#' 2 = Actual vs fitted asset returns,\cr -#' 3 = Residuals and fitted returns, \cr -#' 4 = Sqrt. of Std. Residuals vs Fitted, \cr +#' 1 = Actual and fitted,\cr +#' 2 = Actual vs fitted,\cr +#' 3 = Residuals vs fitted, \cr +#' 4 = Sqrt. of modified residuals vs fitted, \cr #' 5 = Residuals with standard error bands, \cr #' 6 = Time series of squared residuals, \cr #' 7 = Time series of absolute residuals,\cr #' 8 = SACF and PACF of residuals,\cr #' 9 = SACF and PACF of squared residuals,\cr #' 10 = SACF and PACF of absolute residuals,\cr -#' 11 = Density estimate of residuals, \cr -#' 12 = Histogram of residuals with normal curve overlayed,\cr -#' 13 = Normal QQ-plot of residuals,\cr -#' 14 = CUSUM test-Recursive residuals,\cr -#' 15 = CUSUM test-LS residuals,\cr -#' 16 = Recursive estimates (RE) test of LS regression coefficients,\cr -#' 17 = Rolling estimates over a 24-period observation window +#' 11 = Non-parametric density of residuals with normal overlaid, \cr +#' 12 = Non-parametric density of residuals with skew-t overlaid, \cr +#' 13 = Histogram of residuals with non-parametric density and normal overlaid,\cr +#' 14 = QQ-plot of residuals,\cr +#' 15 = CUSUM test-Recursive residuals,\cr +#' 16 = CUSUM test-LS residuals,\cr +#' 17 = Recursive estimates (RE) test of LS regression coefficients,\cr +#' 18 = Rolling regression over a 24-period observation window, \cr +#' 19 = Asset returns vs factor returns (single factor model) #' @param max.show maximum number of assets in a given plot. Default is 6. #' @param plot.single logical; If \code{TRUE} plots the characteristics of an #' individual asset's factor model. The type of plot is given by #' \code{which}. Default is \code{FALSE}. #' @param asset.name name of the individual asset to be plotted. Is necessary #' if \code{x} contains multiple asset fits and \code{plot.single=TRUE}. -#' @param colorset color palette to use for all the plots. Default is -#' \code{c(1:12)}. The 1st element will be used for individual time series -#' plots or the 1st series plotted, the 2nd element for the 2nd object in the -#' plot and so on. +#' @param colorset color palette to use for all the plots. The 1st element will +#' be used for individual time series plots or the 1st series plotted, the 2nd +#' element for the 2nd object in the plot and so on. #' @param legend.loc places a legend into one of nine locations on the chart: #' "bottomright", "bottom", "bottomleft", "left", "topleft", "top", "topright", #' "right", or "center". Default is "bottomright". Use \code{legend.loc=NULL} #' to suppress the legend. #' @param las one of {0, 1, 2, 3} to set the direction of axis labels, same as -#' in \code{plot}. Default here is 1. +#' in \code{plot}. Default is 1. +#' @param lwd set the line width, same as in \code{\link{plot}}. Default is 2. +#' @param maxlag optional number of lags to be calculated for ACF #' @param VaR.method a method for computing VaR; one of "modified", "gaussian", #' "historical" or "kernel". VaR is computed using #' \code{\link[PerformanceAnalytics]{VaR}}. Default is "historical". @@ -83,63 +93,75 @@ #' #' @author Eric Zivot, Sangeetha Srinivasan and Yi-An Chen #' -#' @seealso \code{\link{fitTsfm}} and \code{\link{summary.tsfm}} for details -#' about the time series factor model fit, extractor functions and summary -#' statistics. +#' @seealso \code{\link{fitTsfm}}, \code{\link{residuals.tsfm}}, +#' \code{\link{fitted.tsfm}}, \code{\link{fmCov.tsfm}} and +#' \code{\link{summary.tsfm}} for time series factor model fitting and related +#' S3 methods. Refer to \code{\link{fmSdDecomp}}, \code{\link{fmEsDecomp}}, +#' \code{\link{fmVaRDecomp}} for factor model risk measures. #' -#' \code{\link[strucchange]{efp}} for CUSUM tests. +#' Here is a list of plotting functions used. (I=individual, G=Group) +#' I(1,5,6,7), G(3) - \code{\link[PerformanceAnalytics]{chart.TimeSeries}}, +#' I(2,3,4,19), G(12) - \code{\link[graphics]{plot.default}}, +#' I(3,4) - \code{\link[graphics]{panel.smooth}}, +#' I(8,9,10) - \code{\link[PerformanceAnalytics]{chart.ACFplus}}, +#' I(11,12) - \code{\link[stats]{plot.density}}, +#' I(13) - \code{\link[PerformanceAnalytics]{chart.Histogram}}, +#' I(14) - \code{\link[PerformanceAnalytics]{chart.QQPlot}}, +#' I(15,16,17) - \code{\link[strucchange]{plot.efp}}, +#' I(18) - \code{\link[zoo]{plot.zoo}}, +#' G(1,2) - \code{\link[graphics]{barplot}}, +#' G(4,5,9,10,11) - \code{\link[lattice]{barchart}}, +#' G(6) - \code{\link[PerformanceAnalytics]{chart.Correlation}} and +#' G(7,8) - \code{\link[corrplot]{corrplot.mixed}}. #' -#' \code{\link[xts]{plot.xts}}, -#' \code{\link[PerformanceAnalytics]{chart.TimeSeries}}, -#' \code{\link[PerformanceAnalytics]{chart.ACFplus}}, -#' \code{\link[PerformanceAnalytics]{chart.Histogram}}, -#' \code{\link[PerformanceAnalytics]{chart.QQPlot}}, -#' \code{\link[graphics]{barplot}}, \code{\link[lattice]{barchart}} and -#' \code{\link[corrplot]{corrplot}} for plotting methods used. -#' -#' \code{\link{fmSdDecomp}}, \code{\link{fmEsDecomp}}, -#' \code{\link{fmVaRDecomp}} for factor model risk measures. -#' #' @examples #' #' # load data from the database #' data(managers) #' fit.macro <- fitTsfm(asset.names=colnames(managers[,(1:6)]), -#' factor.names=colnames(managers[,(7:8)]), +#' factor.names=colnames(managers[,(7:9)]), #' rf.name="US.3m.TR", data=managers) #' -#' # for group plots (default), user can select type from menu prompt +#' # for group plots (default), user can select plot option from menu prompt #' # menu is repeated to get multiple types of plots based on the same fit #' # plot(fit.macro) #' -#' # plot specific option(s) though which +#' # choose specific plot option(s) using which #' # plot the factor betas of 1st 4 assets fitted above #' plot(fit.macro, max.show=4, which=2) #' -#' # plot factor model return correlation; angular order of the eigenvectors -#' plot(fit.macro, which=7, order="AOE", method="ellipse", tl.pos = "d") +#' # plot factor model residuals scatterplot matrix, with histograms, density +#' # overlays, correlations and significance stars +#' plot(fit.macro, which=6) #' -#' # for individual plots: set plot.single=TRUE; specify asset.name +#' # for individual plots: set plot.single=TRUE and specify asset.name #' # histogram of residuals from an individual asset's factor model fit -#' plot(fit.macro, plot.single=TRUE, asset.name="HAM1", which=12) +#' plot(fit.macro, plot.single=TRUE, asset.name="HAM1", which=13) #' #' @importFrom PerformanceAnalytics chart.TimeSeries chart.ACFplus -#' chart.Histogram chart.QQPlot +#' chart.Histogram chart.QQPlot chart.Correlation #' @importFrom lattice barchart panel.barchart panel.grid -#' @importFrom corrplot corrplot +#' @importFrom corrplot corrplot.mixed #' @importFrom strucchange efp +#' @importFrom sn dst st.mple #' @importFrom robust lmRob #' #' @method plot tsfm #' @export plot.tsfm <- function(x, which=NULL, max.show=6, plot.single=FALSE, - asset.name, colorset=(1:12), legend.loc="topleft", las=1, - VaR.method="historical", ...) { + asset.name, legend.loc="topleft", las=1, lwd=2, + colorset=c("royalblue","dimgray","olivedrab", + "firebrick","goldenrod","mediumorchid", + "deepskyblue","chocolate","darkslategray"), + maxlag=15, VaR.method="historical", ...) { which.vec <- which which <- which[1] + meth <- x$fit.method # one of "LS", "DLS" or "Robust" + if (is.null(meth)) {meth <- "Lars"} + if (plot.single==TRUE) { if (missing(asset.name) && length(x$asset.names)>1) { @@ -151,12 +173,15 @@ i <- asset.name } # extract info from the fitTsfm object - plotData <- merge.xts(x$data[,i], fitted(x)[,i]) - colnames(plotData) <- c("Actual","Fitted") - Residuals <- residuals(x)[,i] - plotData2 <- merge.xts(Residuals, fitted(x)[,i]) - colnames(plotData2) <- c("Residuals","Fitted") + plotData <- merge.xts(x$data[,i], fitted(x)[,i], residuals(x)[,i]) + colnames(plotData) <- c("Actual","Fitted","Residuals") + Residuals <- na.omit(plotData[,"Residuals"]) fit <- x$asset.fit[[i]] + resid.sd <- x$resid.sd[i] + den <- density(Residuals) + xval <- den$x + den.norm <- dnorm(xval, mean=mean(Residuals), sd=resid.sd) + den.st <- dst(xval, dp=st.mple(x=matrix(1,nrow(Residuals)), y=as.vector(Residuals))$dp) # plot selection repeat { @@ -164,21 +189,23 @@ which <- menu(c("Actual and fitted asset returns", "Actual vs fitted asset returns", - "Residuals and fitted asset returns", - "Sqrt. of Std. Residuals vs Fitted", + "Residuals vs fitted asset returns", + "Sqrt. of modified residuals vs fitted", "Residuals with standard error bands", "Time series of squared residuals", "Time series of absolute residuals", "SACF and PACF of residuals", "SACF and PACF of squared residuals", "SACF and PACF of absolute residuals", - "Density Estimate of Residuals", - "Histogram of residuals with normal curve overlayed", - "Normal qq-plot of residuals", + "Non-parametric density of residuals with normal overlaid", + "Non-parametric density of residuals with skew-t overlaid", + "Histogram of residuals with non-parametric density and normal overlaid", + "QQ-plot of residuals", "CUSUM test-Recursive residuals", "CUSUM test-LS residuals", "Recursive estimates (RE) test of LS regression coefficients", - "Rolling estimates over a 24-period observation window"), + "Rolling estimates over a 24-period observation window", + "Asset returns vs factor returns (single factor model)"), title="\nMake a plot selection (or 0 to exit):") } @@ -186,139 +213,170 @@ switch(which, "1L" = { - ## time series plot of actual and fitted asset returns - chart.TimeSeries(plotData, main=paste("Actual and Fitted:",i), - colorset=colorset, xlab="", ylab="Asset returns", + ## Time series plot of actual and fitted asset returns + chart.TimeSeries(plotData[,1:2], main=paste("Actual and fitted:",i), + colorset=colorset, xlab="", ylab="Returns", lwd=lwd, legend.loc=legend.loc, pch=NULL, las=las, ...) }, "2L" = { - ## fitted vs actual asset returns - plot(coredata(plotData[,1]), coredata(plotData[,2]), - xlab="Actual", ylab="Fitted", - main=paste("Fitted vs Actual Returns:",i), las=las, ...) + ## Actual vs fitted asset returns + plot(x=coredata(plotData[,2]), y=coredata(plotData[,1]), + xlab="Fitted", ylab="Actual", col=colorset[1], + main=paste("Actual vs fitted:",i), las=las, ...) + abline(0, 1, col="dimgray",lty="dotted", lwd=lwd) }, "3L" = { - ## residuals vs fitted asset returns - plot(fit, which=1, main=paste("Residuals vs Fitted Returns:",i), - caption=NA, sub.caption="", las=las, ...) + ## Residuals vs fitted asset returns + plot(x=coredata(plotData[,2]), y=coredata(plotData[,3]), + xlab="Fitted", ylab="Residuals", col=colorset[1], + main=paste("Residuals vs fitted:",i), las=las, ...) + panel.smooth(x=coredata(plotData[,2]), y=coredata(plotData[,3]), + col=colorset[1], col.smooth=colorset[2], lwd=lwd) }, "4L" = { - ## square root of absolute residuals vs fitted asset returns - plot(fit, which=3, main=paste("Sqrt. of Std. Residuals vs Fitted:",i), - caption=NA, sub.caption="", las=las, ...) + ## Square root of absolute modified residuals vs fitted asset returns + if (meth=="Lars") { + stop("This option is not available for 'lars' fits.") + } + yval <- sqrt(abs(Residuals/sqrt(1-hatvalues(fit)))) + plot(x=coredata(na.omit(plotData[,2])), y=yval, xlab="Fitted", + ylab=expression(sqrt(abs("Modified Residuals"))), col=colorset[1], + main=paste("Sqrt. modified residuals vs fitted:",i), las=las, ...) + panel.smooth(x=coredata(na.omit(plotData[,2])), y=yval, + col=colorset[1], col.smooth=colorset[2], lwd=lwd) }, "5L" = { - ## time series plot of residuals with standard error bands + ## Time series plot of residuals with standard error bands chart.TimeSeries(Residuals, main=paste("Residuals:",i), colorset=colorset, xlab="", ylab="Residuals", - lwd=2, lty="solid", las=las, ...) - abline(h=1.96*x$resid.sd[i], lwd=2, lty="dotted", col="red") - abline(h=-1.96*x$resid.sd[i], lwd=2, lty="dotted", col="red") - legend(x=legend.loc, lty=c("solid","dotted"), - col=c(colorset[1],"red"), lwd=2, - legend=c("Residuals",expression("\u00b1 1.96"*sigma))) + lwd=lwd, lty="solid", las=las, ...) + abline(h=1.96*x$resid.sd[i], lwd=lwd, lty="dotted", col=colorset[2]) + abline(h=-1.96*x$resid.sd[i], lwd=lwd, lty="dotted", col=colorset[2]) + legend(x=legend.loc, lty=c("solid","dotted"), col=c(colorset[1:2]), + lwd=lwd, bty="n", legend=c("Residuals",expression("\u00b1 1.96 "*sigma))) }, "6L" = { - ## time series plot of squared residuals + ## Time series plot of squared residuals chart.TimeSeries(Residuals^2, colorset=colorset, xlab="", - ylab=" Squared Residuals", - main=paste("Squared Residuals:",i), - legend.loc=legend.loc, pch=NULL, las=las, ...) + ylab=" Squared residuals", lwd=lwd, + main=paste("Squared residuals:",i), + legend.loc=NULL, pch=NULL, las=las, ...) }, "7L" = { - ## time series plot of absolute residuals + ## Time series plot of absolute residuals chart.TimeSeries(abs(Residuals), colorset=colorset, xlab="", - ylab="Absolute Residuals", - main=paste("Absolute Residuals:",i), - legend.loc=legend.loc, pch=NULL, las=las, ...) + ylab="Absolute residuals", lwd=lwd, + main=paste("Absolute residuals:",i), + legend.loc=NULL, pch=NULL, las=las, ...) }, "8L" = { ## SACF and PACF of residuals - chart.ACFplus(Residuals, col=colorset[1], + chart.ACFplus(Residuals, maxlag=maxlag, main=paste("SACF & PACF - Residuals:",i), ...) }, "9L" = { ## SACF and PACF of squared residuals - chart.ACFplus(Residuals^2, col=colorset[1], ..., - main=paste("SACF & PACF - Squared residuals:",i)) + chart.ACFplus(Residuals^2, maxlag=maxlag, + main=paste("SACF & PACF - Squared residuals:",i), ...) }, "10L" = { ## SACF and PACF of absolute residuals - chart.ACFplus(abs(Residuals), col=colorset[1], ..., - main=paste("SACF & PACF - Absolute Residuals:",i)) + chart.ACFplus(abs(Residuals), maxlag=maxlag, + main=paste("SACF & PACF - Absolute residuals:",i), ...) }, "11L" = { - ## density estimate of residuals - plot(density(Residuals), xlab="Return residuals", - col=colorset, main=paste("Density estimate of Residuals:",i), ...) - rug(Residuals) + ## Non-parametric density of residuals with normal overlaid + ymax <- ceiling(max(0,den$y,den.norm)) + plot(den, xlab="Return residuals", lwd=lwd, col=colorset[1], + ylim=c(0,ymax), main=paste("Density of residuals:",i), ...) + rug(Residuals, col="dimgray") + lines(xval, den.norm, col=colorset[2], lwd=lwd, lty="dashed") + legend(x=legend.loc, lty=c("solid","dashed"), col=c(colorset[1:2]), + lwd=lwd, bty="n", legend=c("KDE","Normal")) }, "12L" = { - ## histogram of residuals with normal curve overlayed + ## Non-parametric density of residuals with skew-t overlaid + ymax <- ceiling(max(0,den$y,den.st)) + plot(den, xlab="Return residuals", lwd=lwd, col=colorset[1], [TRUNCATED] To get the complete diff run: svnlook diff /svnroot/returnanalytics -r 3629 From noreply at r-forge.r-project.org Wed Apr 15 20:27:14 2015 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Wed, 15 Apr 2015 20:27:14 +0200 (CEST) Subject: [Returnanalytics-commits] r3630 - pkg/PerformanceAnalytics/R Message-ID: <20150415182714.13E2E18791F@r-forge.r-project.org> Author: kylebalkissoon Date: 2015-04-15 20:27:13 +0200 (Wed, 15 Apr 2015) New Revision: 3630 Added: pkg/PerformanceAnalytics/R/chart.TimeSeries.base.R Modified: pkg/PerformanceAnalytics/R/chart.TimeSeries.R Log: Added dygraph support see chart.TimeSeries.R and kept original code in chart.TimeSeries.base.R Modified: pkg/PerformanceAnalytics/R/chart.TimeSeries.R =================================================================== --- pkg/PerformanceAnalytics/R/chart.TimeSeries.R 2015-04-15 00:10:21 UTC (rev 3629) +++ pkg/PerformanceAnalytics/R/chart.TimeSeries.R 2015-04-15 18:27:13 UTC (rev 3630) @@ -1,375 +1,323 @@ -#' Creates a time series chart with some extensions. -#' -#' Draws a line chart and labels the x-axis with the appropriate dates. This -#' is really a "primitive", since it extends the base \code{\link{plot}} and -#' standardizes the elements of a chart. Adds attributes for shading areas of -#' the timeline or aligning vertical lines along the timeline. This function is -#' intended to be used inside other charting functions. -#' -#' -#' @param R an xts, vector, matrix, data frame, timeSeries or zoo object of -#' asset returns -#' @param auto.grid if true, draws a grid aligned with the points on the x and -#' y axes -#' @param grid.color sets the color for the reference grid -#' @param grid.lty defines the line type for the grid -#' @param xaxis if true, draws the x axis -#' @param yaxis if true, draws the y axis -#' @param yaxis.right if true, draws the y axis on the right-hand side of the -#' plot -#' @param type set the chart type, same as in \code{\link{plot}} -#' @param lty set the line type, same as in \code{\link{plot}} -#' @param lwd set the line width, same as in \code{\link{plot}} -#' @param las set the axis label rotation, same as in \code{\link{plot}} -#' @param main set the chart title, same as in \code{\link{plot}} -#' @param ylab set the y-axis label, same as in \code{\link{plot}} -#' @param xlab set the x-axis label, same as in \code{\link{plot}} -#' @param date.format re-format the dates for the xaxis; the default is "\%m/\%y" -#' @param xlim set the x-axis limit, same as in \code{\link{plot}} -#' @param ylim set the y-axis limit, same as in \code{\link{plot}} -#' @param event.lines If not null, vertical lines will be drawn to indicate -#' that an event happened during that time period. \code{event.lines} should -#' be a list of dates (e.g., \code{c("09/03","05/06"))} formatted the same as -#' date.format. This function matches the re-formatted row names (dates) with -#' the events.list, so to get a match the formatting needs to be correct. -#' @param event.labels if not null and event.lines is not null, this will apply -#' a list of text labels (e.g., \code{c("This Event", "That Event")} to the -#' vertical lines drawn. See the example below. -#' @param period.areas these are shaded areas described by start and end dates -#' in a vector of xts date rangees, e.g., -#' \code{c("1926-10::1927-11","1929-08::1933-03")} See the examples below. -#' @param event.color draws the event described in \code{event.labels} in the -#' color specified -#' @param period.color draws the shaded region described by \code{period.areas} -#' in the color specified -#' @param colorset color palette to use, set by default to rational choices -#' @param pch symbols to use, see also \code{\link{plot}} -#' @param element.color provides the color for drawing chart elements, such as -#' the box lines, axis lines, etc. Default is "darkgray" -#' @param legend.loc places a legend into one of nine locations on the chart: -#' bottomright, bottom, bottomleft, left, topleft, top, topright, right, or -#' center. -#' @param ylog TRUE/FALSE set the y-axis to logarithmic scale, similar to -#' \code{\link{plot}}, default FALSE -#' @param date.format.in allows specification of other date formats in the data -#' object, defaults to "\%Y-\%m-\%d" -#' @param cex.axis The magnification to be used for axis annotation relative to -#' the current setting of 'cex', same as in \code{\link{plot}}. -#' @param cex.legend The magnification to be used for sizing the legend -#' relative to the current setting of 'cex'. -#' @param cex.labels The magnification to be used for event line labels -#' relative to the current setting of 'cex'. -#' @param cex.lab The magnification to be used for x- and y-axis labels -#' relative to the current setting of 'cex'. -#' @param cex.main The magnification to be used for the chart title relative to -#' the current setting of 'cex'. -#' @param major.ticks Should major tickmarks be drawn and labeled, default -#' 'auto' -#' @param minor.ticks Should minor tickmarks be drawn, default TRUE -#' @param xaxis.labels Allows for non-date labeling of date axes, default is -#' NULL -#' @param space default 0 -#' @param \dots any other passthru parameters -#' @author Peter Carl -#' @seealso \code{\link{plot}}, \code{\link{par}}, -#' \code{\link[xts]{axTicksByTime}} -###keywords ts multivariate distribution models hplot -#' @examples -#' -#' -#' # These are start and end dates, formatted as xts ranges. -#' ## http://www.nber.org-cycles.html -#' cycles.dates<-c("1857-06/1858-12", -#' "1860-10/1861-06", -#' "1865-04/1867-12", -#' "1869-06/1870-12", -#' "1873-10/1879-03", -#' "1882-03/1885-05", -#' "1887-03/1888-04", -#' "1890-07/1891-05", -#' "1893-01/1894-06", -#' "1895-12/1897-06", -#' "1899-06/1900-12", -#' "1902-09/1904-08", -#' "1907-05/1908-06", -#' "1910-01/1912-01", -#' "1913-01/1914-12", -#' "1918-08/1919-03", -#' "1920-01/1921-07", -#' "1923-05/1924-07", -#' "1926-10/1927-11", -#' "1929-08/1933-03", -#' "1937-05/1938-06", -#' "1945-02/1945-10", -#' "1948-11/1949-10", -#' "1953-07/1954-05", -#' "1957-08/1958-04", -#' "1960-04/1961-02", -#' "1969-12/1970-11", -#' "1973-11/1975-03", -#' "1980-01/1980-07", -#' "1981-07/1982-11", -#' "1990-07/1991-03", -#' "2001-03/2001-11", -#' "2007-12/2009-06" -#' ) -#' # Event lists - FOR BEST RESULTS, KEEP THESE DATES IN ORDER -#' risk.dates = c( -#' "Oct 87", -#' "Feb 94", -#' "Jul 97", -#' "Aug 98", -#' "Oct 98", -#' "Jul 00", -#' "Sep 01") -#' risk.labels = c( -#' "Black Monday", -#' "Bond Crash", -#' "Asian Crisis", -#' "Russian Crisis", -#' "LTCM", -#' "Tech Bubble", -#' "Sept 11") -#' data(edhec) -#' -#' R=edhec[,"Funds of Funds",drop=FALSE] -#' Return.cumulative = cumprod(1+R) - 1 -#' chart.TimeSeries(Return.cumulative) -#' chart.TimeSeries(Return.cumulative, colorset = "darkblue", -#' legend.loc = "bottomright", -#' period.areas = cycles.dates, -#' period.color = "lightblue", -#' event.lines = risk.dates, -#' event.labels = risk.labels, -#' event.color = "red", lwd = 2) -#' -#' @export -chart.TimeSeries <- -function (R, - auto.grid=TRUE, - xaxis = TRUE, - yaxis = TRUE, - yaxis.right = FALSE, - type = "l", - lty = 1, - lwd = 2, - las = par("las"), - main = NULL, - ylab=NULL, - xlab="", - date.format.in="%Y-%m-%d", - date.format = NULL, - xlim = NULL, - ylim = NULL, - element.color="darkgray", - event.lines = NULL, - event.labels = NULL, - period.areas = NULL, - event.color = "darkgray", - period.color = "aliceblue", colorset = (1:12), - pch = (1:12), - legend.loc = NULL, - ylog = FALSE, - cex.axis=0.8, - cex.legend = 0.8, - cex.lab = 1, - cex.labels = 0.8, - cex.main = 1, - major.ticks='auto', - minor.ticks=TRUE, - grid.color="lightgray", - grid.lty="dotted", - xaxis.labels = NULL, ...) -{ # @author Peter Carl, Brian Peterson - - # DESCRIPTION: - # Draws a line chart and labels the x-axis with the appropriate dates. - # This is really a "primitive", since it constructs the elements of a plot - # to provide lines for each column of data provided. - - # Inputs: - # R = assumes that data is a regular time series, not irregular. Can take - # any type of object, whether a matrix, data frame, or timeSeries. - # date.format: allows passing of a date format for the xaxis - # legend.loc = use this to locate the legend, e.g., "topright" - # colorset = use the name of any of the palattes above - # reference.grid = if true, draws a grid aligned with the points on the - # x and y axes. - # xaxis = if true, draws the x axis. - # event.lines = if not null, will draw vertical lines indicating that an - # event happened during that time period. event.lines should be a list - # of dates (e.g., c("09/03","05/06")) formatted the same as date.format. - # This function matches the re-formatted row names (dates) with the - # events.list, so to get a match the formatting needs to be correct. - # event.labels = if not null and event.lines is not null, this will apply - # labels to the vertical lines drawn. - - # All other inputs are the same as "plot" and are principally included - # so that some sensible defaults could be set. - - # Output: - # Draws a timeseries graph of type "line" with some sensible defaults. - - # FUNCTION: - - y = checkData(R) - - # Set up dimensions and labels - columns = ncol(y) - rows = nrow(y) - columnnames = colnames(y) - - if (is.null(date.format)){ - freq = periodicity(y) - yr_eq <- ifelse(format(index(first(y)),format="%Y")==format(index(last(y)),format="%Y"),TRUE,FALSE) - switch(freq$scale, - seconds = { date.format = "%H:%M"}, - minute = { date.format = "%H:%M"}, - hourly = {date.format = "%d %H"}, - daily = {if (yr_eq) date.format = "%b %d" else date.format = "%Y-%m-%d"}, - weekly = {if (yr_eq) date.format = "%b %d" else date.format = "%Y-%m-%d"}, - monthly = {if (yr_eq) date.format = "%b" else date.format = "%b %y"}, - quarterly = {if (yr_eq) date.format = "%b" else date.format = "%b %y"}, - yearly = {date.format = "%Y"} - ) - } - # Needed for finding aligned dates for event lines and period areas - rownames = as.Date(time(y)) - rownames = format(strptime(rownames,format = date.format.in), date.format) - - time.scale = periodicity(y)$scale - ep = axTicksByTime(y,major.ticks, format.labels = date.format) - - # If the Y-axis is ln - logaxis = "" - if(ylog) { - logaxis = "y" - } - - plot.new() - - if(is.null(xlim[1])) # is.na or is.null? - xlim = c(1,rows) - if(is.null(ylim[1])){ - ylim = as.numeric(range(y, na.rm=TRUE)) - } - plot.window(xlim, ylim, xaxs = "r", log = logaxis) - - # par("usr"): A vector of the form 'c(x1, x2, y1, y2)' giving the extremes - # of the user coordinates of the plotting region. When a - # logarithmic scale is in use (i.e., 'par("xlog")' is true, see - # below), then the x-limits will be '10 ^ par("usr")[1:2]'. - # Similarly for the y-axis. - - if(is.null(ylab)) { - if(ylog) - ylab = "ln(Value)" - - else - ylab = "Value" - } - - if(ylog) - dimensions=10^par("usr") - else - dimensions = par("usr") - - # Draw any areas in the background - if(!is.null(period.areas)) { - # build a list of specific dates to find from xts ranges given - period.dat = lapply(period.areas,function(x,y) c(first(index(y[x])),last(index(y[x]))),y=y) - period.ind = NULL - for(period in 1:length(period.dat)){ - if(!is.na(period.dat[[period]][1])){ - period.ind = list(grep(period.dat[[period]][1], index(y)), grep(period.dat[[period]][2], index(y))) - rect(period.ind[1], dimensions[3], period.ind[2], dimensions[4], col = period.color, border=NA) - } - } - } - - # Draw the grid - if(auto.grid) { - abline(v=ep, col=grid.color, lty=grid.lty) - grid(NA, NULL, col = grid.color) - } - - # Draw a solid reference line at zero - abline(h = 0, col = element.color) - - # Add event.lines before drawing the data - # This only labels the dates it finds - if(!is.null(event.lines)) { - event.ind = NULL - for(event in 1:length(event.lines)){ - event.ind = c(event.ind, grep(event.lines[event], rownames)) - } - number.event.labels = ((length(event.labels)-length(event.ind) + 1):length(event.labels)) - - abline(v = event.ind, col = event.color, lty = 2) - if(!is.null(event.labels)) { - text(x=event.ind,y=ylim[2], label = event.labels[number.event.labels], offset = .2, pos = 2, cex = cex.labels, srt=90, col = event.color) - } - } - - # Expand the attributes to #columns if fewer values are passed in - # (e.g., only one), to allow the user to pass in line, type, or - # symbol variations. - if(length(lwd) < columns) - lwd = rep(lwd,columns) - if(length(lty) < columns) - lty = rep(lty,columns) - if(length(pch) < columns) - pch = rep(pch,columns) - - for(column in columns:1) { - lines(1:rows, y[,column], col = colorset[column], lwd = lwd[column], pch = pch[column], lty = lty[column], type = type, ...) - } - - if (xaxis) { - if(minor.ticks) - axis(1, at=1:NROW(y), labels=FALSE, col='#BBBBBB', las=las) - label.height = cex.axis *(.5 + apply(t(names(ep)),1, function(X) max(strheight(X, units="in")/par('cin')[2]) )) - if(is.null(xaxis.labels)) - xaxis.labels = names(ep) - else - ep = 1:length(xaxis.labels) - axis(1, at=ep, labels=xaxis.labels, las=1, lwd=1, mgp=c(3,label.height,0), cex.axis = cex.axis, las=las) -# axis(1, at=ep, labels=xaxis.labels, las=1, lwd=1, mgp=c(3,2,0), cex.axis = cex.axis) - #axis(1, at = lab.ind, lab=rownames[lab.ind], cex.axis = cex.axis, col = elementcolor) - title(xlab = xlab, cex = cex.lab) - # use axis(..., las=3) for vertical labels. - } - - # set up y-axis - if (yaxis) - if(yaxis.right) - axis(4, cex.axis = cex.axis, col=element.color, ylog=ylog, las=las) - else - axis(2, cex.axis = cex.axis, col=element.color, ylog=ylog, las=las) - box(col = element.color) - - if(!is.null(legend.loc)){ - # There's no good place to put this automatically, except under the graph. - # That requires a different solution, but here's the quick fix - legend(legend.loc, inset = 0.02, text.col = colorset, col = colorset, cex = cex.legend, border.col = element.color, lty = lty, lwd = 2, bg = "white", legend = columnnames, pch=pch) - } - - # Add the other titles - if(is.null(main)) - main=columnnames[1] - title(ylab = ylab, cex.lab = cex.lab) - title(main = main, cex.main = cex.main) - -} - -############################################################################### -# R (http://r-project.org/) Econometrics for Performance and Risk Analysis -# -# Copyright (c) 2004-2015 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$ -# -############################################################################### +#' Creates a time series chart with some extensions. +#' +#' Draws a line chart and labels the x-axis with the appropriate dates. This +#' is really a "primitive", since it extends the base \code{\link{plot}} and +#' standardizes the elements of a chart. Adds attributes for shading areas of +#' the timeline or aligning vertical lines along the timeline. This function is +#' intended to be used inside other charting functions. +#' +#' +#' @param R an xts, vector, matrix, data frame, timeSeries or zoo object of +#' asset returns +#' @param auto.grid if true, draws a grid aligned with the points on the x and +#' y axes +#' @param grid.color sets the color for the reference grid +#' @param grid.lty defines the line type for the grid +#' @param xaxis if true, draws the x axis +#' @param yaxis if true, draws the y axis +#' @param yaxis.right if true, draws the y axis on the right-hand side of the +#' plot +#' @param type set the chart type, same as in \code{\link{plot}} +#' @param lty set the line type, same as in \code{\link{plot}} +#' @param lwd set the line width, same as in \code{\link{plot}} +#' @param las set the axis label rotation, same as in \code{\link{plot}} +#' @param main set the chart title, same as in \code{\link{plot}} +#' @param ylab set the y-axis label, same as in \code{\link{plot}} +#' @param xlab set the x-axis label, same as in \code{\link{plot}} +#' @param date.format re-format the dates for the xaxis; the default is "\%m/\%y" +#' @param xlim set the x-axis limit, same as in \code{\link{plot}} +#' @param ylim set the y-axis limit, same as in \code{\link{plot}} +#' @param event.lines If not null, vertical lines will be drawn to indicate +#' that an event happened during that time period. \code{event.lines} should +#' be a list of dates (e.g., \code{c("09/03","05/06"))} formatted the same as +#' date.format. This function matches the re-formatted row names (dates) with +#' the events.list, so to get a match the formatting needs to be correct. +#' @param event.labels if not null and event.lines is not null, this will apply +#' a list of text labels (e.g., \code{c("This Event", "That Event")} to the +#' vertical lines drawn. See the example below. +#' @param period.areas these are shaded areas described by start and end dates +#' in a vector of xts date rangees, e.g., +#' \code{c("1926-10::1927-11","1929-08::1933-03")} See the examples below. +#' @param event.color draws the event described in \code{event.labels} in the +#' color specified +#' @param period.color draws the shaded region described by \code{period.areas} +#' in the color specified +#' @param colorset color palette to use, set by default to rational choices +#' @param pch symbols to use, see also \code{\link{plot}} +#' @param element.color provides the color for drawing chart elements, such as +#' the box lines, axis lines, etc. Default is "darkgray" +#' @param legend.loc places a legend into one of nine locations on the chart: +#' bottomright, bottom, bottomleft, left, topleft, top, topright, right, or +#' center. +#' @param ylog TRUE/FALSE set the y-axis to logarithmic scale, similar to +#' \code{\link{plot}}, default FALSE +#' @param date.format.in allows specification of other date formats in the data +#' object, defaults to "\%Y-\%m-\%d" +#' @param cex.axis The magnification to be used for axis annotation relative to +#' the current setting of 'cex', same as in \code{\link{plot}}. +#' @param cex.legend The magnification to be used for sizing the legend +#' relative to the current setting of 'cex'. +#' @param cex.labels The magnification to be used for event line labels +#' relative to the current setting of 'cex'. +#' @param cex.lab The magnification to be used for x- and y-axis labels +#' relative to the current setting of 'cex'. +#' @param cex.main The magnification to be used for the chart title relative to +#' the current setting of 'cex'. +#' @param major.ticks Should major tickmarks be drawn and labeled, default +#' 'auto' +#' @param minor.ticks Should minor tickmarks be drawn, default TRUE +#' @param xaxis.labels Allows for non-date labeling of date axes, default is +#' NULL +#' @param space default 0 +#' @param dygraphPlot Plot using dygraphs default FALSE +#' @param \dots any other passthru parameters +#' @author Peter Carl +#' @seealso \code{\link{plot}}, \code{\link{par}}, +#' \code{\link[xts]{axTicksByTime}} +###keywords ts multivariate distribution models hplot +#' @examples +#' +#' +#' # These are start and end dates, formatted as xts ranges. +#' ## http://www.nber.org-cycles.html +#' cycles.dates<-c("1857-06/1858-12", +#' "1860-10/1861-06", +#' "1865-04/1867-12", +#' "1869-06/1870-12", +#' "1873-10/1879-03", +#' "1882-03/1885-05", +#' "1887-03/1888-04", +#' "1890-07/1891-05", +#' "1893-01/1894-06", +#' "1895-12/1897-06", +#' "1899-06/1900-12", +#' "1902-09/1904-08", +#' "1907-05/1908-06", +#' "1910-01/1912-01", +#' "1913-01/1914-12", +#' "1918-08/1919-03", +#' "1920-01/1921-07", +#' "1923-05/1924-07", +#' "1926-10/1927-11", +#' "1929-08/1933-03", +#' "1937-05/1938-06", +#' "1945-02/1945-10", +#' "1948-11/1949-10", +#' "1953-07/1954-05", +#' "1957-08/1958-04", +#' "1960-04/1961-02", +#' "1969-12/1970-11", +#' "1973-11/1975-03", +#' "1980-01/1980-07", +#' "1981-07/1982-11", +#' "1990-07/1991-03", +#' "2001-03/2001-11", +#' "2007-12/2009-06" +#' ) +#' # Event lists - FOR BEST RESULTS, KEEP THESE DATES IN ORDER +#' risk.dates = c( +#' "Oct 87", +#' "Feb 94", +#' "Jul 97", +#' "Aug 98", +#' "Oct 98", +#' "Jul 00", +#' "Sep 01") +#' risk.labels = c( +#' "Black Monday", +#' "Bond Crash", +#' "Asian Crisis", +#' "Russian Crisis", +#' "LTCM", +#' "Tech Bubble", +#' "Sept 11") +#' data(edhec) +#' +#' R=edhec[,"Funds of Funds",drop=FALSE] +#' Return.cumulative = cumprod(1+R) - 1 +#' chart.TimeSeries(Return.cumulative) +#' chart.TimeSeries(Return.cumulative, colorset = "darkblue", +#' legend.loc = "bottomright", +#' period.areas = cycles.dates, +#' period.color = "lightblue", +#' event.lines = risk.dates, +#' event.labels = risk.labels, +#' event.color = "red", lwd = 2) +#' +#' @export +chart.TimeSeries <- +function (R, + auto.grid=TRUE, + xaxis = TRUE, + yaxis = TRUE, + yaxis.right = FALSE, + type = "l", + lty = 1, + lwd = 2, + las = par("las"), + main = NULL, + ylab=NULL, + xlab="", + date.format.in="%Y-%m-%d", + date.format = NULL, + xlim = NULL, + ylim = NULL, + element.color="darkgray", + event.lines = NULL, + event.labels = NULL, + period.areas = NULL, + event.color = "darkgray", + period.color = "aliceblue", colorset = (1:12), + pch = (1:12), + legend.loc = NULL, + ylog = FALSE, + cex.axis=0.8, + cex.legend = 0.8, + cex.lab = 1, + cex.labels = 0.8, + cex.main = 1, + major.ticks='auto', + minor.ticks=TRUE, + grid.color="lightgray", + grid.lty="dotted", + xaxis.labels = NULL, + dygraphPlot=FALSE,...) +{ # @author Peter Carl, Brian Peterson + + # DESCRIPTION: + # Draws a line chart and labels the x-axis with the appropriate dates. + # This is really a "primitive", since it constructs the elements of a plot + # to provide lines for each column of data provided. + + # Inputs: + # R = assumes that data is a regular time series, not irregular. Can take + # any type of object, whether a matrix, data frame, or timeSeries. + # date.format: allows passing of a date format for the xaxis + # legend.loc = use this to locate the legend, e.g., "topright" + # colorset = use the name of any of the palattes above + # reference.grid = if true, draws a grid aligned with the points on the + # x and y axes. + # xaxis = if true, draws the x axis. + # event.lines = if not null, will draw vertical lines indicating that an + # event happened during that time period. event.lines should be a list + # of dates (e.g., c("09/03","05/06")) formatted the same as date.format. + # This function matches the re-formatted row names (dates) with the + # events.list, so to get a match the formatting needs to be correct. + # event.labels = if not null and event.lines is not null, this will apply + # labels to the vertical lines drawn. + + # All other inputs are the same as "plot" and are principally included + # so that some sensible defaults could be set. + + # Output: + # Draws a timeseries graph of type "line" with some sensible defaults. + + # FUNCTION: + + y = checkData(R) + + # Set up dimensions and labels + columns = ncol(y) + rows = nrow(y) + columnnames = colnames(y) + + if (is.null(date.format)){ + freq = periodicity(y) + yr_eq <- ifelse(format(index(first(y)),format="%Y")==format(index(last(y)),format="%Y"),TRUE,FALSE) + switch(freq$scale, + seconds = { date.format = "%H:%M"}, + minute = { date.format = "%H:%M"}, + hourly = {date.format = "%d %H"}, + daily = {if (yr_eq) date.format = "%b %d" else date.format = "%Y-%m-%d"}, + weekly = {if (yr_eq) date.format = "%b %d" else date.format = "%Y-%m-%d"}, + monthly = {if (yr_eq) date.format = "%b" else date.format = "%b %y"}, + quarterly = {if (yr_eq) date.format = "%b" else date.format = "%b %y"}, + yearly = {date.format = "%Y"} + ) + } + # Needed for finding aligned dates for event lines and period areas + rownames = as.Date(time(y)) + rownames = format(strptime(rownames,format = date.format.in), date.format) + + time.scale = periodicity(y)$scale + ep = axTicksByTime(y,major.ticks, format.labels = date.format) + + # If the Y-axis is ln + logaxis = "" + if(ylog) { + logaxis = "y" + } + + + if(dygraphPlot==FALSE){ + chart.TimeSeries.base(R, + auto.grid, + xaxis, + yaxis, + yaxis.right, + type, + lty, + lwd , + las , + main , + ylab, + xlab, + date.format.in, + date.format , + xlim , + ylim , + element.color, + event.lines, + event.labels, + period.areas, + event.color , + period.color , colorset , + pch, + legend.loc , + ylog , + cex.axis, + cex.legend , + cex.lab , + cex.labels, + cex.main , + major.ticks, + minor.ticks, + grid.color, + grid.lty, + xaxis.labels,...) + + + + + }else{ + if(is.null(main)) + main=columnnames[1] + + if(is.null(ylab)) { + if(ylog) + ylab = "ln(Value)" + + else + ylab = "Value" + } + + ##@TODO Get all the graphical parameters integrated with these two + dyRangeSelector(dygraph(y,main = main, + xlab = xlab, + ylab = ylab)) + + } + +} + +############################################################################### +# R (http://r-project.org/) Econometrics for Performance and Risk Analysis +# +# Copyright (c) 2004-2015 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$ +# +############################################################################### Added: pkg/PerformanceAnalytics/R/chart.TimeSeries.base.R =================================================================== --- pkg/PerformanceAnalytics/R/chart.TimeSeries.base.R (rev 0) +++ pkg/PerformanceAnalytics/R/chart.TimeSeries.base.R 2015-04-15 18:27:13 UTC (rev 3630) @@ -0,0 +1,375 @@ +#' Creates a time series chart with some extensions. +#' +#' Draws a line chart and labels the x-axis with the appropriate dates. This +#' is really a "primitive", since it extends the base \code{\link{plot}} and +#' standardizes the elements of a chart. Adds attributes for shading areas of +#' the timeline or aligning vertical lines along the timeline. This function is +#' intended to be used inside other charting functions. +#' +#' +#' @param R an xts, vector, matrix, data frame, timeSeries or zoo object of +#' asset returns +#' @param auto.grid if true, draws a grid aligned with the points on the x and +#' y axes +#' @param grid.color sets the color for the reference grid +#' @param grid.lty defines the line type for the grid +#' @param xaxis if true, draws the x axis +#' @param yaxis if true, draws the y axis +#' @param yaxis.right if true, draws the y axis on the right-hand side of the +#' plot +#' @param type set the chart type, same as in \code{\link{plot}} +#' @param lty set the line type, same as in \code{\link{plot}} +#' @param lwd set the line width, same as in \code{\link{plot}} +#' @param las set the axis label rotation, same as in \code{\link{plot}} +#' @param main set the chart title, same as in \code{\link{plot}} +#' @param ylab set the y-axis label, same as in \code{\link{plot}} +#' @param xlab set the x-axis label, same as in \code{\link{plot}} +#' @param date.format re-format the dates for the xaxis; the default is "\%m/\%y" +#' @param xlim set the x-axis limit, same as in \code{\link{plot}} +#' @param ylim set the y-axis limit, same as in \code{\link{plot}} +#' @param event.lines If not null, vertical lines will be drawn to indicate +#' that an event happened during that time period. \code{event.lines} should +#' be a list of dates (e.g., \code{c("09/03","05/06"))} formatted the same as +#' date.format. This function matches the re-formatted row names (dates) with +#' the events.list, so to get a match the formatting needs to be correct. +#' @param event.labels if not null and event.lines is not null, this will apply +#' a list of text labels (e.g., \code{c("This Event", "That Event")} to the +#' vertical lines drawn. See the example below. +#' @param period.areas these are shaded areas described by start and end dates +#' in a vector of xts date rangees, e.g., +#' \code{c("1926-10::1927-11","1929-08::1933-03")} See the examples below. +#' @param event.color draws the event described in \code{event.labels} in the +#' color specified +#' @param period.color draws the shaded region described by \code{period.areas} +#' in the color specified +#' @param colorset color palette to use, set by default to rational choices +#' @param pch symbols to use, see also \code{\link{plot}} +#' @param element.color provides the color for drawing chart elements, such as +#' the box lines, axis lines, etc. Default is "darkgray" +#' @param legend.loc places a legend into one of nine locations on the chart: +#' bottomright, bottom, bottomleft, left, topleft, top, topright, right, or +#' center. +#' @param ylog TRUE/FALSE set the y-axis to logarithmic scale, similar to +#' \code{\link{plot}}, default FALSE +#' @param date.format.in allows specification of other date formats in the data +#' object, defaults to "\%Y-\%m-\%d" +#' @param cex.axis The magnification to be used for axis annotation relative to +#' the current setting of 'cex', same as in \code{\link{plot}}. +#' @param cex.legend The magnification to be used for sizing the legend +#' relative to the current setting of 'cex'. +#' @param cex.labels The magnification to be used for event line labels +#' relative to the current setting of 'cex'. +#' @param cex.lab The magnification to be used for x- and y-axis labels +#' relative to the current setting of 'cex'. +#' @param cex.main The magnification to be used for the chart title relative to +#' the current setting of 'cex'. +#' @param major.ticks Should major tickmarks be drawn and labeled, default +#' 'auto' +#' @param minor.ticks Should minor tickmarks be drawn, default TRUE +#' @param xaxis.labels Allows for non-date labeling of date axes, default is +#' NULL +#' @param space default 0 +#' @param \dots any other passthru parameters +#' @author Peter Carl +#' @seealso \code{\link{plot}}, \code{\link{par}}, +#' \code{\link[xts]{axTicksByTime}} +###keywords ts multivariate distribution models hplot +#' @examples +#' +#' +#' # These are start and end dates, formatted as xts ranges. +#' ## http://www.nber.org-cycles.html +#' cycles.dates<-c("1857-06/1858-12", [TRUNCATED] To get the complete diff run: svnlook diff /svnroot/returnanalytics -r 3630 From noreply at r-forge.r-project.org Fri Apr 17 02:32:48 2015 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Fri, 17 Apr 2015 02:32:48 +0200 (CEST) Subject: [Returnanalytics-commits] r3631 - in pkg/FactorAnalytics: R man tests Message-ID: <20150417003248.BDA451874D1@r-forge.r-project.org> Author: pragnya Date: 2015-04-17 02:32:48 +0200 (Fri, 17 Apr 2015) New Revision: 3631 Added: pkg/FactorAnalytics/tests/FactorAnalytics_04_16_15.pdf Removed: pkg/FactorAnalytics/tests/FactorAnalytics.pdf Modified: pkg/FactorAnalytics/R/fitTsfm.R pkg/FactorAnalytics/R/fitTsfmMT.r pkg/FactorAnalytics/man/fitTsfm.Rd pkg/FactorAnalytics/man/fitTsfmMT.Rd pkg/FactorAnalytics/man/plot.tsfm.Rd Log: Updated package manual, edits to documentation Modified: pkg/FactorAnalytics/R/fitTsfm.R =================================================================== --- pkg/FactorAnalytics/R/fitTsfm.R 2015-04-15 18:27:13 UTC (rev 3630) +++ pkg/FactorAnalytics/R/fitTsfm.R 2015-04-17 00:32:48 UTC (rev 3631) @@ -66,12 +66,11 @@ #' @param variable.selection the variable selection method, one of "none", #' "stepwise","subsets","lars". See details. Default is "none". #' \code{mkt.name} is required if any of these options are to be implemented. -#' @param control list of control parameters. The default is constructed by -#' the function \code{\link{fitTsfm.control}}. See the documentation for +#' @param control list of control parameters. Refer to #' \code{\link{fitTsfm.control}} for details. #' @param ... arguments passed to \code{\link{fitTsfm.control}} #' -#' @return fitTsfm returns an object of class \code{"tsfm"} for which +#' @return \code{fitTsfm} returns an object of class \code{"tsfm"} for which #' \code{print}, \code{plot}, \code{predict} and \code{summary} methods exist. #' #' The generic accessor functions \code{coef}, \code{fitted} and @@ -114,13 +113,6 @@ #' Tibshirani, R. (2009). The elements of statistical learning (Vol. 2, No. 1). #' New York: Springer. #' -#' Henriksson, R. D., & Merton, R. C. (1981). On market timing and investment -#' performance. II. Statistical procedures for evaluating forecasting skills. -#' Journal of business, 513-533. -#' -#' Treynor, J., & Mazuy, K. (1966). Can mutual funds outguess the market. -#' Harvard business review, 44(4), 131-136. -#' #' @seealso The \code{tsfm} methods for generic functions: #' \code{\link{plot.tsfm}}, \code{\link{predict.tsfm}}, #' \code{\link{print.tsfm}} and \code{\link{summary.tsfm}}. Modified: pkg/FactorAnalytics/R/fitTsfmMT.r =================================================================== --- pkg/FactorAnalytics/R/fitTsfmMT.r 2015-04-15 18:27:13 UTC (rev 3630) +++ pkg/FactorAnalytics/R/fitTsfmMT.r 2015-04-17 00:32:48 UTC (rev 3631) @@ -1,40 +1,39 @@ -#' @title Fit a time serie market timing factor model using time series regression +#' @title Fit a market timing time series factor model #' -#' @description This is a wrapper function to fits a time series market timing factor model for one -#' or more asset returns or excess returns using time series regression. -#' Users can choose between ordinary least squares-LS, discounted least -#' squares-DLS (or) robust regression. An object of class +#' @description This is a wrapper function to fit a market timing time series +#' factor model for one or more asset returns or excess returns using time +#' series regression. Users can choose between ordinary least squares-LS, +#' discounted least squares-DLS (or) robust regression. An object of class #' \code{"tsfm"} is returned. #' #' @details -#' The Market timing accounts for the price movement of the general stock market relative to fixed income -#' securities. It includes down.market = max(0, R_f-R_m) as a factor, following Henriksson & Merton -#' (1981). The coefficient of this down-market factor can be interpreted as the -#' number of "free" put options on the market provided by the manager's market-timings kills. +#' Market timing accounts for the price movement of the general stock market +#' relative to fixed income securities. A market-timing factor is added to the +#' time series regression, following Henriksson & Merton (1981). Here, we use +#' down.market = max(0, R_f-R_m), where Rm is the (excess) return on the market. +#' The coefficient of this down-market factor can be interpreted as the number +#' of "free" put options on the market provided by the manager's market-timings +#' skills. #' -#' -#' #' @param asset.names vector containing names of assets, whose returns or #' excess returns are the dependent variable. -#' @param mkt.name name of the column for market returns; It -#' is required for a market timing model. +#' @param mkt.name name of the column for market returns (required). #' @param rf.name name of the column of risk free rate variable to calculate -#' excess returns for all assets (in \code{asset.names}) and the market factor (in -#' \code{mkt.name}).Default is NULL, and no action is taken. +#' excess returns for all assets (in \code{asset.names}) and the market factor +#' (in \code{mkt.name}). Default is NULL, and no action is taken. #' @param data vector, matrix, data.frame, xts, timeSeries or zoo object #' containing column(s) named in \code{asset.names}, \code{factor.names} and #' optionally, \code{mkt.name} and \code{rf.name}. #' @param fit.method the estimation method, one of "LS", "DLS" or "Robust". #' See details. Default is "LS". -#' @param control list of control parameters. The default is constructed by -#' the function \code{\link{fitTsfm.control}}. See the documentation for -#' \code{\link{fitTsfm.control}} for details. +#' @param control list of control parameters passed to \code{\link{fitTsfm}}. +#' Refer to \code{\link{fitTsfm.control}} for details. #' @param ... arguments passed to \code{\link{fitTsfm.control}} #' -#' @return \code{fitTsfmMT} also returns an object of class \code{"tsfm"} like -#' \code{fitTsfm}. The generic function such as \code{print}, \code{plot}, \code{predict} -#' and \code{summary} methods exist. Also, the generic accessor functions \code{coef}, -#' \code{fitted}, \code{residuals} and \code{fmCov} can be applied as well. +#' @return Similar to \code{fitTsfm}, \code{fitTsfmMT} also returns an object +#' of class \code{"tsfm"}, for which \code{print}, \code{plot}, \code{predict} +#' and \code{summary} methods exist. The generic accessor functions \code{coef}, +#' \code{fitted}, \code{residuals} and \code{fmCov} can be applied as well. #' #' An object of class \code{"tsfm"} is a list containing the following #' components: @@ -46,47 +45,50 @@ #' \item{r2}{length-N vector of R-squared values.} #' \item{resid.sd}{length-N vector of residual standard deviations.} #' \item{call}{the matched function call.} -#' \item{data}{xts data object containing the assets and factors.} +#' \item{data}{xts data object containing the asset(s) and factor(s) returns.} #' \item{asset.names}{asset.names as input.} +#' \item{factor.names}{vector containing the names of the market-timing factor +#' and the market factor} +#' \item{mkt.name}{mkt.name as input} #' \item{fit.method}{fit.method as input.} -#' Where N is the number of assets and T is the -#' number of time periods. +#' Where N is the number of assets and T is the number of time periods. #' -#' @author Yi-An Chen. +#' @author Yi-An Chen, Sangeetha Srinivasan. #' #' @references +#' Christopherson, J. A., Carino, D. R., & Ferson, W. E. (2009). Portfolio +#' performance measurement and benchmarking. McGraw Hill Professional. pp.127-133 +#' #' Henriksson, R. D., & Merton, R. C. (1981). On market timing and investment #' performance. II. Statistical procedures for evaluating forecasting skills. #' Journal of business, 513-533. #' -#' #' Christopherson, J. A., Carino, D. R., & Ferson, W. E. (2009). Portfolio -#' performance measurement and benchmarking. McGraw Hill Professional. pp.127-133 +#' Treynor, J., & Mazuy, K. (1966). Can mutual funds outguess the market. +#' Harvard business review, 44(4), 131-136. #' #' @seealso -#' The original time series function \code{\link{fitTsfm}} and its generic functions -#' application. +#' The original time series factor model fitting function \code{\link{fitTsfm}} +#' and related methods. #' #' @examples #' # load data from the database #' data(managers) #' -#' # example: Market-timing factors with LS fit -#' fit <- fitTsfmMT(asset.names=colnames(managers[,(1:6)]), -#' mkt.name="SP500.TR",rf.name="US.3m.TR",data=managers) +#' # example: Market-timing time series factor model with LS fit +#' fit <- fitTsfmMT(asset.names=colnames(managers[,(1:6)]), mkt.name="SP500.TR", +#' rf.name="US.3m.TR", data=managers) #' summary(fit) #' #' @importFrom PerformanceAnalytics checkData -#' @importFrom robust lmRob step.lmRob -#' @importFrom leaps regsubsets -#' @importFrom lars lars cv.lars #' #' @export -fitTsfmMT <- function(asset.names,mkt.name, rf.name=NULL, - data=data, fit.method=c("LS","DLS","Robust"), - control=fitTsfm.control(...),...) { +fitTsfmMT <- function(asset.names, mkt.name, rf.name=NULL, data=data, + fit.method=c("LS","DLS","Robust"), + control=fitTsfm.control(...), ...) { + if (is.null(mkt.name)){ - stop("Missing argument: mkt.name has to be specified for market timing model.") + stop("Missing argument: mkt.name is required for market timing models.") } # convert data into an xts object and hereafter work with xts objects @@ -104,23 +106,24 @@ FUN.VALUE = numeric(nrow(dat.xts)))) } - # mkt-timing factors: down.market=max(0,Rf-Rm), market.sqd=(Rm-Rf)^2 - - down.market <- dat.xts[,mkt.name] - down.market[down.market < 0 ] <- 0 - dat.xts <- merge.xts(dat.xts,down.market) - colnames(dat.xts)[dim(dat.xts)[2]] <- "down.market" - factor.names <- c(mkt.name,"down.market") + # mkt-timing factors: down.market=max(0,Rf-Rm), market.sqd=(Rm-Rf)^2 -# if("TM" %in% mkt.timing) { -# market.sqd <- data.xts[,mkt.name]^2 -# dat.xts <- merge(dat.xts, market.sqd) -# colnames(dat.xts)[dim(dat.xts)[2]] <- "market.sqd" -# factor.names <- c(factor.names, "market.sqd") -# } + down.market <- dat.xts[,mkt.name] + down.market[down.market < 0 ] <- 0 + dat.xts <- merge.xts(dat.xts,down.market) + colnames(dat.xts)[dim(dat.xts)[2]] <- "down.market" + factor.names <- c(mkt.name,"down.market") - fit.Timing <- fitTsfm(asset.names=asset.names,factor.names=factor.names,rf.name=NULL, - data=dat.xts,fit.method=fit.method,variable.selection="none",control=control) - -return(fit.Timing) + # if("TM" %in% mkt.timing) { + # market.sqd <- data.xts[,mkt.name]^2 + # dat.xts <- merge(dat.xts, market.sqd) + # colnames(dat.xts)[dim(dat.xts)[2]] <- "market.sqd" + # factor.names <- c(factor.names, "market.sqd") + # } + + fit.MktTiming <- fitTsfm(asset.names=asset.names, factor.names=factor.names, + rf.name=NULL, data=dat.xts, fit.method=fit.method, + variable.selection="none", control=control) + + return(fit.MktTiming) } Modified: pkg/FactorAnalytics/man/fitTsfm.Rd =================================================================== --- pkg/FactorAnalytics/man/fitTsfm.Rd 2015-04-15 18:27:13 UTC (rev 3630) +++ pkg/FactorAnalytics/man/fitTsfm.Rd 2015-04-17 00:32:48 UTC (rev 3631) @@ -41,8 +41,7 @@ "stepwise","subsets","lars". See details. Default is "none". \code{mkt.name} is required if any of these options are to be implemented.} -\item{control}{list of control parameters. The default is constructed by -the function \code{\link{fitTsfm.control}}. See the documentation for +\item{control}{list of control parameters. Refer to \code{\link{fitTsfm.control}} for details.} \item{...}{arguments passed to \code{\link{fitTsfm.control}}} @@ -51,7 +50,7 @@ \code{fitTsfm}} } \value{ -fitTsfm returns an object of class \code{"tsfm"} for which +\code{fitTsfm} returns an object of class \code{"tsfm"} for which \code{print}, \code{plot}, \code{predict} and \code{summary} methods exist. The generic accessor functions \code{coef}, \code{fitted} and @@ -171,13 +170,6 @@ Hastie, T., Tibshirani, R., Friedman, J., Hastie, T., Friedman, J., & Tibshirani, R. (2009). The elements of statistical learning (Vol. 2, No. 1). New York: Springer. - -Henriksson, R. D., & Merton, R. C. (1981). On market timing and investment -performance. II. Statistical procedures for evaluating forecasting skills. -Journal of business, 513-533. - -Treynor, J., & Mazuy, K. (1966). Can mutual funds outguess the market. -Harvard business review, 44(4), 131-136. } \seealso{ The \code{tsfm} methods for generic functions: Modified: pkg/FactorAnalytics/man/fitTsfmMT.Rd =================================================================== --- pkg/FactorAnalytics/man/fitTsfmMT.Rd 2015-04-15 18:27:13 UTC (rev 3630) +++ pkg/FactorAnalytics/man/fitTsfmMT.Rd 2015-04-17 00:32:48 UTC (rev 3631) @@ -2,7 +2,7 @@ % Please edit documentation in R/fitTsfmMT.r \name{fitTsfmMT} \alias{fitTsfmMT} -\title{Fit a time serie market timing factor model using time series regression} +\title{Fit a market timing time series factor model} \usage{ fitTsfmMT(asset.names, mkt.name, rf.name = NULL, data = data, fit.method = c("LS", "DLS", "Robust"), control = fitTsfm.control(...), @@ -12,12 +12,11 @@ \item{asset.names}{vector containing names of assets, whose returns or excess returns are the dependent variable.} -\item{mkt.name}{name of the column for market returns; It -is required for a market timing model.} +\item{mkt.name}{name of the column for market returns (required).} \item{rf.name}{name of the column of risk free rate variable to calculate -excess returns for all assets (in \code{asset.names}) and the market factor (in -\code{mkt.name}).Default is NULL, and no action is taken.} +excess returns for all assets (in \code{asset.names}) and the market factor +(in \code{mkt.name}). Default is NULL, and no action is taken.} \item{data}{vector, matrix, data.frame, xts, timeSeries or zoo object containing column(s) named in \code{asset.names}, \code{factor.names} and @@ -26,17 +25,16 @@ \item{fit.method}{the estimation method, one of "LS", "DLS" or "Robust". See details. Default is "LS".} -\item{control}{list of control parameters. The default is constructed by -the function \code{\link{fitTsfm.control}}. See the documentation for -\code{\link{fitTsfm.control}} for details.} +\item{control}{list of control parameters passed to \code{\link{fitTsfm}}. +Refer to \code{\link{fitTsfm.control}} for details.} \item{...}{arguments passed to \code{\link{fitTsfm.control}}} } \value{ -\code{fitTsfmMT} also returns an object of class \code{"tsfm"} like -\code{fitTsfm}. The generic function such as \code{print}, \code{plot}, \code{predict} -and \code{summary} methods exist. Also, the generic accessor functions \code{coef}, -\code{fitted}, \code{residuals} and \code{fmCov} can be applied as well. +Similar to \code{fitTsfm}, \code{fitTsfmMT} also returns an object +of class \code{"tsfm"}, for which \code{print}, \code{plot}, \code{predict} +and \code{summary} methods exist. The generic accessor functions \code{coef}, +\code{fitted}, \code{residuals} and \code{fmCov} can be applied as well. An object of class \code{"tsfm"} is a list containing the following components: @@ -48,47 +46,55 @@ \item{r2}{length-N vector of R-squared values.} \item{resid.sd}{length-N vector of residual standard deviations.} \item{call}{the matched function call.} -\item{data}{xts data object containing the assets and factors.} +\item{data}{xts data object containing the asset(s) and factor(s) returns.} \item{asset.names}{asset.names as input.} +\item{factor.names}{vector containing the names of the market-timing factor +and the market factor} +\item{mkt.name}{mkt.name as input} \item{fit.method}{fit.method as input.} -Where N is the number of assets and T is the -number of time periods. +Where N is the number of assets and T is the number of time periods. } \description{ -This is a wrapper function to fits a time series market timing factor model for one -or more asset returns or excess returns using time series regression. -Users can choose between ordinary least squares-LS, discounted least -squares-DLS (or) robust regression. An object of class +This is a wrapper function to fit a market timing time series +factor model for one or more asset returns or excess returns using time +series regression. Users can choose between ordinary least squares-LS, +discounted least squares-DLS (or) robust regression. An object of class \code{"tsfm"} is returned. } \details{ -The Market timing accounts for the price movement of the general stock market relative to fixed income -securities. It includes down.market = max(0, R_f-R_m) as a factor, following Henriksson & Merton -(1981). The coefficient of this down-market factor can be interpreted as the -number of "free" put options on the market provided by the manager's market-timings kills. +Market timing accounts for the price movement of the general stock market +relative to fixed income securities. A market-timing factor is added to the +time series regression, following Henriksson & Merton (1981). Here, we use +down.market = max(0, R_f-R_m), where Rm is the (excess) return on the market. +The coefficient of this down-market factor can be interpreted as the number +of "free" put options on the market provided by the manager's market-timings +skills. } \examples{ # load data from the database data(managers) -# example: Market-timing factors with LS fit -fit <- fitTsfmMT(asset.names=colnames(managers[,(1:6)]), - mkt.name="SP500.TR",rf.name="US.3m.TR",data=managers) +# example: Market-timing time series factor model with LS fit +fit <- fitTsfmMT(asset.names=colnames(managers[,(1:6)]), mkt.name="SP500.TR", + rf.name="US.3m.TR", data=managers) summary(fit) } \author{ -Yi-An Chen. +Yi-An Chen, Sangeetha Srinivasan. } \references{ +Christopherson, J. A., Carino, D. R., & Ferson, W. E. (2009). Portfolio +performance measurement and benchmarking. McGraw Hill Professional. pp.127-133 + Henriksson, R. D., & Merton, R. C. (1981). On market timing and investment performance. II. Statistical procedures for evaluating forecasting skills. Journal of business, 513-533. -#' Christopherson, J. A., Carino, D. R., & Ferson, W. E. (2009). Portfolio -performance measurement and benchmarking. McGraw Hill Professional. pp.127-133 +Treynor, J., & Mazuy, K. (1966). Can mutual funds outguess the market. +Harvard business review, 44(4), 131-136. } \seealso{ -The original time series function \code{\link{fitTsfm}} and its generic functions - application. +The original time series factor model fitting function \code{\link{fitTsfm}} +and related methods. } Modified: pkg/FactorAnalytics/man/plot.tsfm.Rd =================================================================== --- pkg/FactorAnalytics/man/plot.tsfm.Rd 2015-04-15 18:27:13 UTC (rev 3630) +++ pkg/FactorAnalytics/man/plot.tsfm.Rd 2015-04-17 00:32:48 UTC (rev 3631) @@ -140,7 +140,7 @@ Eric Zivot, Sangeetha Srinivasan and Yi-An Chen } \seealso{ -\code{\link{fitTsfm}}, \code{\link{resduals.tsfm}}, +\code{\link{fitTsfm}}, \code{\link{residuals.tsfm}}, \code{\link{fitted.tsfm}}, \code{\link{fmCov.tsfm}} and \code{\link{summary.tsfm}} for time series factor model fitting and related S3 methods. Refer to \code{\link{fmSdDecomp}}, \code{\link{fmEsDecomp}}, @@ -155,7 +155,7 @@ I(13) - \code{\link[PerformanceAnalytics]{chart.Histogram}}, I(14) - \code{\link[PerformanceAnalytics]{chart.QQPlot}}, I(15,16,17) - \code{\link[strucchange]{plot.efp}}, -I(18) - \code{\link[xts]{plot.zoo}}, +I(18) - \code{\link[zoo]{plot.zoo}}, G(1,2) - \code{\link[graphics]{barplot}}, G(4,5,9,10,11) - \code{\link[lattice]{barchart}}, G(6) - \code{\link[PerformanceAnalytics]{chart.Correlation}} and Deleted: pkg/FactorAnalytics/tests/FactorAnalytics.pdf =================================================================== (Binary files differ) Added: pkg/FactorAnalytics/tests/FactorAnalytics_04_16_15.pdf =================================================================== (Binary files differ) Property changes on: pkg/FactorAnalytics/tests/FactorAnalytics_04_16_15.pdf ___________________________________________________________________ Added: svn:mime-type + application/octet-stream From noreply at r-forge.r-project.org Fri Apr 17 18:38:40 2015 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Fri, 17 Apr 2015 18:38:40 +0200 (CEST) Subject: [Returnanalytics-commits] r3632 - in pkg/PortfolioAnalytics: . R man vignettes Message-ID: <20150417163840.BE03D187525@r-forge.r-project.org> Author: rossbennett34 Date: 2015-04-17 18:38:40 +0200 (Fri, 17 Apr 2015) New Revision: 3632 Added: pkg/PortfolioAnalytics/R/zzz.R Removed: pkg/PortfolioAnalytics/man/pHist.Rd Modified: pkg/PortfolioAnalytics/DESCRIPTION pkg/PortfolioAnalytics/NAMESPACE pkg/PortfolioAnalytics/R/EntropyProg.R pkg/PortfolioAnalytics/R/constrained_objective.R pkg/PortfolioAnalytics/R/extract.efficient.frontier.R pkg/PortfolioAnalytics/R/extractstats.R pkg/PortfolioAnalytics/R/moment.functions.R pkg/PortfolioAnalytics/R/optFUN.R pkg/PortfolioAnalytics/R/optimize.portfolio.R pkg/PortfolioAnalytics/R/random_portfolios.R pkg/PortfolioAnalytics/man/BlackLittermanFormula.Rd pkg/PortfolioAnalytics/man/CCCgarch.MM.Rd pkg/PortfolioAnalytics/man/EntropyProg.Rd pkg/PortfolioAnalytics/man/HHI.Rd pkg/PortfolioAnalytics/man/ac.ranking.Rd pkg/PortfolioAnalytics/man/add.constraint.Rd pkg/PortfolioAnalytics/man/add.objective.Rd pkg/PortfolioAnalytics/man/add.sub.portfolio.Rd pkg/PortfolioAnalytics/man/applyFUN.Rd pkg/PortfolioAnalytics/man/barplotGroupWeights.Rd pkg/PortfolioAnalytics/man/black.litterman.Rd pkg/PortfolioAnalytics/man/box_constraint.Rd pkg/PortfolioAnalytics/man/center.Rd pkg/PortfolioAnalytics/man/centroid.buckets.Rd pkg/PortfolioAnalytics/man/centroid.complete.mc.Rd pkg/PortfolioAnalytics/man/centroid.sectors.Rd pkg/PortfolioAnalytics/man/centroid.sign.Rd pkg/PortfolioAnalytics/man/chart.Concentration.Rd pkg/PortfolioAnalytics/man/chart.EF.Weights.Rd pkg/PortfolioAnalytics/man/chart.EfficientFrontier.Rd pkg/PortfolioAnalytics/man/chart.EfficientFrontierOverlay.Rd pkg/PortfolioAnalytics/man/chart.GroupWeights.Rd pkg/PortfolioAnalytics/man/chart.RiskBudget.Rd pkg/PortfolioAnalytics/man/chart.RiskReward.Rd pkg/PortfolioAnalytics/man/chart.Weights.Rd pkg/PortfolioAnalytics/man/check_constraints.Rd pkg/PortfolioAnalytics/man/cokurtosisMF.Rd pkg/PortfolioAnalytics/man/cokurtosisSF.Rd pkg/PortfolioAnalytics/man/combine.optimizations.Rd pkg/PortfolioAnalytics/man/combine.portfolios.Rd pkg/PortfolioAnalytics/man/constrained_objective.Rd pkg/PortfolioAnalytics/man/constraint.Rd pkg/PortfolioAnalytics/man/constraint_ROI.Rd pkg/PortfolioAnalytics/man/constraint_v2.Rd pkg/PortfolioAnalytics/man/coskewnessMF.Rd pkg/PortfolioAnalytics/man/coskewnessSF.Rd pkg/PortfolioAnalytics/man/covarianceMF.Rd pkg/PortfolioAnalytics/man/covarianceSF.Rd pkg/PortfolioAnalytics/man/create.EfficientFrontier.Rd pkg/PortfolioAnalytics/man/diversification.Rd pkg/PortfolioAnalytics/man/diversification_constraint.Rd pkg/PortfolioAnalytics/man/equal.weight.Rd pkg/PortfolioAnalytics/man/etl_milp_opt.Rd pkg/PortfolioAnalytics/man/etl_opt.Rd pkg/PortfolioAnalytics/man/extractCokurtosis.Rd pkg/PortfolioAnalytics/man/extractCoskewness.Rd pkg/PortfolioAnalytics/man/extractCovariance.Rd pkg/PortfolioAnalytics/man/extractEfficientFrontier.Rd pkg/PortfolioAnalytics/man/extractGroups.Rd pkg/PortfolioAnalytics/man/extractObjectiveMeasures.Rd pkg/PortfolioAnalytics/man/extractStats.Rd pkg/PortfolioAnalytics/man/extractWeights.Rd pkg/PortfolioAnalytics/man/factor_exposure_constraint.Rd pkg/PortfolioAnalytics/man/fn_map.Rd pkg/PortfolioAnalytics/man/generatesequence.Rd pkg/PortfolioAnalytics/man/get_constraints.Rd pkg/PortfolioAnalytics/man/gmv_opt.Rd pkg/PortfolioAnalytics/man/gmv_opt_leverage.Rd pkg/PortfolioAnalytics/man/gmv_opt_ptc.Rd pkg/PortfolioAnalytics/man/gmv_opt_toc.Rd pkg/PortfolioAnalytics/man/group_constraint.Rd pkg/PortfolioAnalytics/man/group_fail.Rd pkg/PortfolioAnalytics/man/insert_constraints.Rd pkg/PortfolioAnalytics/man/insert_objectives.Rd pkg/PortfolioAnalytics/man/inverse.volatility.weight.Rd pkg/PortfolioAnalytics/man/is.constraint.Rd pkg/PortfolioAnalytics/man/is.objective.Rd pkg/PortfolioAnalytics/man/is.portfolio.Rd pkg/PortfolioAnalytics/man/leverage_exposure_constraint.Rd pkg/PortfolioAnalytics/man/maxret_milp_opt.Rd pkg/PortfolioAnalytics/man/maxret_opt.Rd pkg/PortfolioAnalytics/man/meanetl.efficient.frontier.Rd pkg/PortfolioAnalytics/man/meanvar.efficient.frontier.Rd pkg/PortfolioAnalytics/man/meucci.moments.Rd pkg/PortfolioAnalytics/man/meucci.ranking.Rd pkg/PortfolioAnalytics/man/minmax_objective.Rd pkg/PortfolioAnalytics/man/mult.portfolio.spec.Rd pkg/PortfolioAnalytics/man/name.replace.Rd pkg/PortfolioAnalytics/man/objective.Rd pkg/PortfolioAnalytics/man/optimize.portfolio.Rd pkg/PortfolioAnalytics/man/optimize.portfolio.parallel.Rd pkg/PortfolioAnalytics/man/optimize.portfolio.rebalancing.Rd pkg/PortfolioAnalytics/man/plot.Rd pkg/PortfolioAnalytics/man/portfolio.moments.bl.Rd pkg/PortfolioAnalytics/man/portfolio.moments.boudt.Rd pkg/PortfolioAnalytics/man/portfolio.spec.Rd pkg/PortfolioAnalytics/man/portfolio_risk_objective.Rd pkg/PortfolioAnalytics/man/pos_limit_fail.Rd pkg/PortfolioAnalytics/man/position_limit_constraint.Rd pkg/PortfolioAnalytics/man/print.constraint.Rd pkg/PortfolioAnalytics/man/print.efficient.frontier.Rd pkg/PortfolioAnalytics/man/print.optimize.portfolio.Rd pkg/PortfolioAnalytics/man/print.optimize.portfolio.rebalancing.Rd pkg/PortfolioAnalytics/man/print.portfolio.Rd pkg/PortfolioAnalytics/man/print.summary.optimize.portfolio.Rd pkg/PortfolioAnalytics/man/print.summary.optimize.portfolio.rebalancing.Rd pkg/PortfolioAnalytics/man/quadratic_utility_objective.Rd pkg/PortfolioAnalytics/man/random_portfolios.Rd pkg/PortfolioAnalytics/man/random_portfolios_v1.Rd pkg/PortfolioAnalytics/man/random_walk_portfolios.Rd pkg/PortfolioAnalytics/man/randomize_portfolio.Rd pkg/PortfolioAnalytics/man/randomize_portfolio_v1.Rd pkg/PortfolioAnalytics/man/regime.portfolios.Rd pkg/PortfolioAnalytics/man/return_constraint.Rd pkg/PortfolioAnalytics/man/return_objective.Rd pkg/PortfolioAnalytics/man/risk_budget_objective.Rd pkg/PortfolioAnalytics/man/rp_grid.Rd pkg/PortfolioAnalytics/man/rp_sample.Rd pkg/PortfolioAnalytics/man/rp_simplex.Rd pkg/PortfolioAnalytics/man/rp_transform.Rd pkg/PortfolioAnalytics/man/scatterFUN.Rd pkg/PortfolioAnalytics/man/set.portfolio.moments.Rd pkg/PortfolioAnalytics/man/set.portfolio.moments_v1.Rd pkg/PortfolioAnalytics/man/statistical.factor.model.Rd pkg/PortfolioAnalytics/man/summary.efficient.frontier.Rd pkg/PortfolioAnalytics/man/summary.optimize.portfolio.Rd pkg/PortfolioAnalytics/man/summary.optimize.portfolio.rebalancing.Rd pkg/PortfolioAnalytics/man/summary.portfolio.Rd pkg/PortfolioAnalytics/man/trailingFUN.Rd pkg/PortfolioAnalytics/man/transaction_cost_constraint.Rd pkg/PortfolioAnalytics/man/turnover.Rd pkg/PortfolioAnalytics/man/turnover_constraint.Rd pkg/PortfolioAnalytics/man/turnover_objective.Rd pkg/PortfolioAnalytics/man/update.constraint.Rd pkg/PortfolioAnalytics/man/update_constraint_v1tov2.Rd pkg/PortfolioAnalytics/man/var.portfolio.Rd pkg/PortfolioAnalytics/man/weight_concentration_objective.Rd pkg/PortfolioAnalytics/man/weight_sum_constraint.Rd pkg/PortfolioAnalytics/vignettes/ROI_vignette.Rnw pkg/PortfolioAnalytics/vignettes/custom_moments_objectives.Rnw pkg/PortfolioAnalytics/vignettes/risk_budget_optimization.Rnw Log: Code and documentation cleanup for R CMD check --as-cran Modified: pkg/PortfolioAnalytics/DESCRIPTION =================================================================== --- pkg/PortfolioAnalytics/DESCRIPTION 2015-04-17 00:32:48 UTC (rev 3631) +++ pkg/PortfolioAnalytics/DESCRIPTION 2015-04-17 16:38:40 UTC (rev 3632) @@ -3,27 +3,28 @@ Title: Portfolio Analysis, including Numerical Methods for Optimization of Portfolios Authors at R: c( - person(given=c("Brian","G."),family="Peterson",role=c("cre","aut","cph"), email="brian at braverock.com") - , person(given="Peter",family="Carl",role=c("aut","cph"), email="peter at braverock.com") - , person(given="Kris",family="Boudt",role=c("ctb","cph")) - , person(given="Ross",family="Bennett",role=c("ctb","cph")) - , person(given="Hezky",family="Varon",role="ctb") - , person(given="Guy",family="Yollin",role="ctb") - , person(given="R. Douglas",family="Martin",role="ctb") - ) + person(given=c("Brian","G."),family="Peterson",role=c("cre","aut","cph"), + email="brian at braverock.com") , + person(given="Peter",family="Carl",role=c("aut","cph"), + email="peter at braverock.com") , + person(given="Kris",family="Boudt",role=c("ctb","cph")) , + person(given="Ross",family="Bennett",role=c("ctb","cph")) , + person(given="Hezky",family="Varon",role="ctb") , + person(given="Guy",family="Yollin",role="ctb") , + person(given="R. Douglas",family="Martin",role="ctb") ) Version: 0.9.3625 Date: $Date$ -Maintainer: Brian G. Peterson +Maintainer: Ross Bennett Description: Portfolio optimization and analysis routines and graphics. Depends: R (>= 2.14.0), zoo, xts (>= 0.8), + foreach, PerformanceAnalytics (>= 1.1.0) Suggests: quantmod, DEoptim(>= 2.2.1), - foreach, iterators, fGarch, Rglpk, @@ -36,6 +37,8 @@ GenSA, corpcor, testthat, - nloptr (>= 1.0.0) + nloptr (>= 1.0.0), + MASS, + robustbase License: GPL Copyright: (c) 2004-2015 Modified: pkg/PortfolioAnalytics/NAMESPACE =================================================================== --- pkg/PortfolioAnalytics/NAMESPACE 2015-04-17 00:32:48 UTC (rev 3631) +++ pkg/PortfolioAnalytics/NAMESPACE 2015-04-17 16:38:40 UTC (rev 3632) @@ -1,5 +1,7 @@ -# Generated by roxygen2 (4.1.0): do not edit by hand +# Generated by roxygen2 (4.0.1): do not edit by hand +S3method(chart.EF.Weights,efficient.frontier) +S3method(chart.EF.Weights,optimize.portfolio) S3method(chart.EfficientFrontier,efficient.frontier) S3method(chart.EfficientFrontier,optimize.portfolio) S3method(chart.EfficientFrontier,optimize.portfolio.ROI) @@ -19,8 +21,6 @@ S3method(chart.Weights,optimize.portfolio.pso) S3method(chart.Weights,optimize.portfolio.random) S3method(chart.Weights,optimize.portfolio.rebalancing) -S3method(chart.EF.Weights,efficient.frontier) -S3method(chart.EF.Weights,optimize.portfolio) S3method(extractObjectiveMeasures,opt.list) S3method(extractObjectiveMeasures,opt.rebal.list) S3method(extractObjectiveMeasures,optimize.portfolio) @@ -88,13 +88,13 @@ export(centroid.sectors) export(centroid.sign) export(chart.Concentration) +export(chart.EF.Weights) export(chart.EfficientFrontier) export(chart.EfficientFrontierOverlay) export(chart.GroupWeights) export(chart.RiskBudget) export(chart.RiskReward) export(chart.Weights) -export(chart.EF.Weights) export(combine.optimizations) export(combine.portfolios) export(constrained_objective) @@ -169,4 +169,8 @@ export(var.portfolio) export(weight_concentration_objective) export(weight_sum_constraint) +import(PerformanceAnalytics) +import(foreach) +import(xts) +import(zoo) useDynLib("PortfolioAnalytics") Modified: pkg/PortfolioAnalytics/R/EntropyProg.R =================================================================== --- pkg/PortfolioAnalytics/R/EntropyProg.R 2015-04-17 00:32:48 UTC (rev 3631) +++ pkg/PortfolioAnalytics/R/EntropyProg.R 2015-04-17 16:38:40 UTC (rev 3632) @@ -49,7 +49,7 @@ #' @export EntropyProg = function( p , A = NULL , b = NULL , Aeq , beq, verbose=FALSE ) { - stopifnot("package:nloptr" %in% search() || require("nloptr",quietly = TRUE) ) + stopifnot("package:nloptr" %in% search() || requireNamespace("nloptr",quietly = TRUE) ) if( is.vector(b) ) b = matrix(b, nrow=length(b)) if( is.vector(beq) ) beq = matrix(beq, nrow=length(beq)) @@ -119,7 +119,7 @@ check_derivatives_print = check_derivatives_print , print_level = print_level , maxeval = 1000 ) - optimResult = nloptr(x0 = x0, eval_f = eval_f_list , opts = opts ) + optimResult = nloptr::nloptr(x0 = x0, eval_f = eval_f_list , opts = opts ) end = Sys.time() if(verbose){ @@ -189,7 +189,7 @@ eval_f = nestedfunC , eval_g_ineq = InqConstraint , eval_jac_g_ineq = jacobian_constraint ) - optimResult = nloptr( x0 = x0 , + optimResult = nloptr::nloptr( x0 = x0 , eval_f = nestedfunC , eval_g_ineq = InqConstraint , eval_jac_g_ineq = jacobian_constraint , Modified: pkg/PortfolioAnalytics/R/constrained_objective.R =================================================================== --- pkg/PortfolioAnalytics/R/constrained_objective.R 2015-04-17 00:32:48 UTC (rev 3631) +++ pkg/PortfolioAnalytics/R/constrained_objective.R 2015-04-17 16:38:40 UTC (rev 3632) @@ -382,7 +382,7 @@ store_output <- try(get('.objectivestorage',envir=.storage), silent=TRUE) if(inherits(store_output,"try-error")) { storage <- FALSE - warning("could not get .objectivestorage") + # warning("could not get .objectivestorage") } else { storage <- TRUE } Modified: pkg/PortfolioAnalytics/R/extract.efficient.frontier.R =================================================================== --- pkg/PortfolioAnalytics/R/extract.efficient.frontier.R 2015-04-17 00:32:48 UTC (rev 3631) +++ pkg/PortfolioAnalytics/R/extract.efficient.frontier.R 2015-04-17 16:38:40 UTC (rev 3632) @@ -31,10 +31,10 @@ columnnames=colnames(xtract) # optimal portfolio stats from xtract opt <- xtract[which.min(xtract[, "out"]),] - #if("package:multicore" %in% search() || require("multicore",quietly = TRUE)){ + #if("package:multicore" %in% search() || requireNamespace("multicore",quietly = TRUE)){ # mclapply #} - stopifnot("package:foreach" %in% search() || require("foreach",quietly = TRUE)) + stopifnot("package:foreach" %in% search() || requireNamespace("foreach",quietly = TRUE)) # rtc = pmatch(return.col,columnnames) # if(is.na(rtc)) { # rtc = pmatch(paste(return.col,return.col,sep='.'),columnnames) @@ -61,7 +61,7 @@ set<-cbind(quantmod::Lag(set,1),as.matrix(set))[-1,] i <- 1 - result <- foreach(i=1:nrow(set),.inorder=TRUE, .combine=rbind, .errorhandling='remove') %do% { + result <- foreach::foreach(i=1:nrow(set),.inorder=TRUE, .combine=rbind, .errorhandling='remove') %do% { tmp<-xtract[which(xtract[,mtc]>=set[i,1] & xtract[,mtc] Author: arorar Date: 2015-04-17 21:57:45 +0200 (Fri, 17 Apr 2015) New Revision: 3633 Modified: pkg/FactorAnalytics/R/fmmc.R pkg/FactorAnalytics/man/fmmc.Rd Log: Fixed calculation of estimates and se when se is set to false. Modified: pkg/FactorAnalytics/R/fmmc.R =================================================================== --- pkg/FactorAnalytics/R/fmmc.R 2015-04-17 16:38:40 UTC (rev 3632) +++ pkg/FactorAnalytics/R/fmmc.R 2015-04-17 19:57:45 UTC (rev 3633) @@ -303,8 +303,8 @@ #' time series with different starting dates are merged together. It then #' computes FMMC objects as described in Jiang and Martin (2013) #' -#' @param R matrix of returns -#' @param factors matrix of factor returns +#' @param R matrix of returns in xts format +#' @param factors matrix of factor returns in xts format #' @param parallel flag to utilize multiplecores on the cpu. All cores are used. #' @param ... Arguments that must be passed to fitTsfm #' @@ -318,6 +318,10 @@ #' #' @return returns an list of fmmc objects #' +#' @references +#' Yindeng Jiang and Richard Doug Martin. Better Risk and Performance +#' Estimates with Factor Model Monte Carlo. SSRN Electronic Journal, July 2013. +#' #' @author Rohit Arora #' @export #' @@ -364,8 +368,7 @@ fmmc.estimate.se <- function(fmmcObjs, fun=NULL, se=FALSE, nboot=100, parallel = FALSE) { - est <- se.est <- rep(NA, length(fmmcObjs)) - result <- cbind(est, se.est); colnames(result) <- c("estimate","se") + result <- as.matrix(rep(NA, length(fmmcObjs))); colnames(result) <- "estimate" rownames(result) <- unlist(lapply(fmmcObjs, function(obj) colnames(obj$data$R))) if(is.null(fun)) return(result) @@ -377,8 +380,12 @@ } result[,1] <- unlist(lapply(fmmcObjs, function(obj) fun(obj$bootdist$returns))) - result[,2] <- if(se) unlist( - lapply(fmmcObjs, function(obj) .fmmc.se(obj, nboot, fun, cl))) + if(se) { + serr <- unlist( + lapply(fmmcObjs, function(obj) .fmmc.se(obj, nboot, fun, cl))) + result <- cbind(result, serr) + colnames(result) <- c("estimate", "se") + } if(parallel) stopCluster(cl) Modified: pkg/FactorAnalytics/man/fmmc.Rd =================================================================== --- pkg/FactorAnalytics/man/fmmc.Rd 2015-04-17 16:38:40 UTC (rev 3632) +++ pkg/FactorAnalytics/man/fmmc.Rd 2015-04-17 19:57:45 UTC (rev 3633) @@ -1,34 +1,38 @@ -% Generated by roxygen2 (4.1.0): do not edit by hand -% Please edit documentation in R/fmmc.R -\name{fmmc} -\alias{fmmc} -\title{Compute fmmc objects that can be used for calcuation of estimates and their -standard errors} -\usage{ -fmmc(R, factors, parallel = FALSE, ...) -} -\arguments{ -\item{R}{matrix of returns} - -\item{factors}{matrix of factor returns} - -\item{parallel}{flag to utilize multiplecores on the cpu. All cores are used.} - -\item{...}{Arguments that must be passed to fitTsfm} -} -\value{ -returns an list of fmmc objects -} -\description{ -Compute fmmc objects that can be used for calcuation of estimates and their -standard errors -} -\details{ -This method takes in data and factors as xts objects where multiple -time series with different starting dates are merged together. It then -computes FMMC objects as described in Jiang and Martin (2013) -} -\author{ -Rohit Arora -} - +% Generated by roxygen2 (4.1.0): do not edit by hand +% Please edit documentation in R/fmmc.R +\name{fmmc} +\alias{fmmc} +\title{Compute fmmc objects that can be used for calcuation of estimates and their +standard errors} +\usage{ +fmmc(R, factors, parallel = FALSE, ...) +} +\arguments{ +\item{R}{matrix of returns in xts format} + +\item{factors}{matrix of factor returns in xts format} + +\item{parallel}{flag to utilize multiplecores on the cpu. All cores are used.} + +\item{...}{Arguments that must be passed to fitTsfm} +} +\value{ +returns an list of fmmc objects +} +\description{ +Compute fmmc objects that can be used for calcuation of estimates and their +standard errors +} +\details{ +This method takes in data and factors as xts objects where multiple +time series with different starting dates are merged together. It then +computes FMMC objects as described in Jiang and Martin (2013) +} +\author{ +Rohit Arora +} +\references{ +Yindeng Jiang and Richard Doug Martin. Better Risk and Performance +Estimates with Factor Model Monte Carlo. SSRN Electronic Journal, July 2013. +} + From noreply at r-forge.r-project.org Sat Apr 18 14:25:57 2015 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Sat, 18 Apr 2015 14:25:57 +0200 (CEST) Subject: [Returnanalytics-commits] r3634 - in pkg/PortfolioAnalytics: . man Message-ID: <20150418122557.780701879BE@r-forge.r-project.org> Author: rossbennett34 Date: 2015-04-18 14:25:57 +0200 (Sat, 18 Apr 2015) New Revision: 3634 Modified: pkg/PortfolioAnalytics/DESCRIPTION pkg/PortfolioAnalytics/man/add.constraint.Rd pkg/PortfolioAnalytics/man/box_constraint.Rd pkg/PortfolioAnalytics/man/constraint.Rd pkg/PortfolioAnalytics/man/random_portfolios_v1.Rd Log: Minor fixes for R CMD check - use title case for Title field in Description - fix line widths in man files - bump version Modified: pkg/PortfolioAnalytics/DESCRIPTION =================================================================== --- pkg/PortfolioAnalytics/DESCRIPTION 2015-04-17 19:57:45 UTC (rev 3633) +++ pkg/PortfolioAnalytics/DESCRIPTION 2015-04-18 12:25:57 UTC (rev 3634) @@ -1,6 +1,6 @@ Package: PortfolioAnalytics Type: Package -Title: Portfolio Analysis, including Numerical Methods for Optimization +Title: Portfolio Analysis, Including Numerical Methods for Optimization of Portfolios Authors at R: c( person(given=c("Brian","G."),family="Peterson",role=c("cre","aut","cph"), @@ -12,7 +12,7 @@ person(given="Hezky",family="Varon",role="ctb") , person(given="Guy",family="Yollin",role="ctb") , person(given="R. Douglas",family="Martin",role="ctb") ) -Version: 0.9.3625 +Version: 0.9.3633 Date: $Date$ Maintainer: Ross Bennett Description: Portfolio optimization and analysis routines and graphics. Modified: pkg/PortfolioAnalytics/man/add.constraint.Rd =================================================================== --- pkg/PortfolioAnalytics/man/add.constraint.Rd 2015-04-17 19:57:45 UTC (rev 3633) +++ pkg/PortfolioAnalytics/man/add.constraint.Rd 2015-04-18 12:25:57 UTC (rev 3634) @@ -58,16 +58,20 @@ pspec <- add.constraint(portfolio=pspec, type="box", min=0.05, max=0.4) # min and max can also be specified per asset -pspec <- add.constraint(portfolio=pspec, type="box", min=c(0.05, 0, 0.08, 0.1), max=c(0.4, 0.3, 0.7, 0.55)) +pspec <- add.constraint(portfolio=pspec, type="box", min=c(0.05, 0, 0.08, 0.1), +max=c(0.4, 0.3, 0.7, 0.55)) # A special case of box constraints is long only where min=0 and max=1 # The default action is long only if min and max are not specified pspec <- add.constraint(portfolio=pspec, type="box") pspec <- add.constraint(portfolio=pspec, type="long_only") # Add group constraints -pspec <- add.constraint(portfolio=pspec, type="group", groups=list(c(1, 2, 1), 4), group_min=c(0.1, 0.15), group_max=c(0.85, 0.55), group_labels=c("GroupA", "GroupB"), group_pos=c(2, 1)) +pspec <- add.constraint(portfolio=pspec, type="group", groups=list(c(1, 2, 1), 4), +group_min=c(0.1, 0.15), group_max=c(0.85, 0.55), group_labels=c("GroupA", "GroupB"), +group_pos=c(2, 1)) -# Add position limit constraint such that we have a maximum number of three assets with non-zero weights. +# Add position limit constraint such that we have a maximum number of three +# assets with non-zero weights. pspec <- add.constraint(portfolio=pspec, type="position_limit", max_pos=3) # Add diversification constraint Modified: pkg/PortfolioAnalytics/man/box_constraint.Rd =================================================================== --- pkg/PortfolioAnalytics/man/box_constraint.Rd 2015-04-17 19:57:45 UTC (rev 3633) +++ pkg/PortfolioAnalytics/man/box_constraint.Rd 2015-04-18 12:25:57 UTC (rev 3634) @@ -45,7 +45,8 @@ pspec <- add.constraint(pspec, type="box", min=0.05, max=0.45) # specify box constraints per asset -pspec <- add.constraint(pspec, type="box", min=c(0.05, 0.10, 0.08, 0.06), max=c(0.45, 0.55, 0.35, 0.65)) +pspec <- add.constraint(pspec, type="box", min=c(0.05, 0.10, 0.08, 0.06), +max=c(0.45, 0.55, 0.35, 0.65)) } \author{ Ross Bennett Modified: pkg/PortfolioAnalytics/man/constraint.Rd =================================================================== --- pkg/PortfolioAnalytics/man/constraint.Rd 2015-04-17 19:57:45 UTC (rev 3633) +++ pkg/PortfolioAnalytics/man/constraint.Rd 2015-04-18 12:25:57 UTC (rev 3634) @@ -29,7 +29,8 @@ This function is the constructor for the \code{v1_constraint} object for backwards compatibility. } \examples{ -exconstr <- constraint(assets=10, min_sum=1, max_sum=1, min=.01, max=.35, weight_seq=generatesequence()) +exconstr <- constraint(assets=10, min_sum=1, max_sum=1, min=.01, max=.35, +weight_seq=generatesequence()) } \author{ Peter Carl, Brian G. Peterson Modified: pkg/PortfolioAnalytics/man/random_portfolios_v1.Rd =================================================================== --- pkg/PortfolioAnalytics/man/random_portfolios_v1.Rd 2015-04-17 19:57:45 UTC (rev 3633) +++ pkg/PortfolioAnalytics/man/random_portfolios_v1.Rd 2015-04-18 12:25:57 UTC (rev 3634) @@ -20,7 +20,8 @@ arbitrary number of constrained random portfolios. } \examples{ -rpconstraint<-constraint(assets=10, min_mult=-Inf, max_mult=Inf, min_sum=.99, max_sum=1.01, min=.01, max=.4, weight_seq=generatesequence()) +rpconstraint<-constraint(assets=10, min_mult=-Inf, max_mult=Inf, min_sum=.99, +max_sum=1.01, min=.01, max=.4, weight_seq=generatesequence()) rp<- random_portfolios_v1(rpconstraints=rpconstraint,permutations=1000) head(rp) } From noreply at r-forge.r-project.org Sat Apr 18 14:28:12 2015 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Sat, 18 Apr 2015 14:28:12 +0200 (CEST) Subject: [Returnanalytics-commits] r3635 - in pkg/PortfolioAnalytics: . R Message-ID: <20150418122812.E320F1879BF@r-forge.r-project.org> Author: rossbennett34 Date: 2015-04-18 14:28:12 +0200 (Sat, 18 Apr 2015) New Revision: 3635 Modified: pkg/PortfolioAnalytics/DESCRIPTION pkg/PortfolioAnalytics/R/constraint_fn_map.R Log: fix typo bug in rp_transform and bump version Modified: pkg/PortfolioAnalytics/DESCRIPTION =================================================================== --- pkg/PortfolioAnalytics/DESCRIPTION 2015-04-18 12:25:57 UTC (rev 3634) +++ pkg/PortfolioAnalytics/DESCRIPTION 2015-04-18 12:28:12 UTC (rev 3635) @@ -12,7 +12,7 @@ person(given="Hezky",family="Varon",role="ctb") , person(given="Guy",family="Yollin",role="ctb") , person(given="R. Douglas",family="Martin",role="ctb") ) -Version: 0.9.3633 +Version: 0.9.3635 Date: $Date$ Maintainer: Ross Bennett Description: Portfolio optimization and analysis routines and graphics. Modified: pkg/PortfolioAnalytics/R/constraint_fn_map.R =================================================================== --- pkg/PortfolioAnalytics/R/constraint_fn_map.R 2015-04-18 12:25:57 UTC (rev 3634) +++ pkg/PortfolioAnalytics/R/constraint_fn_map.R 2015-04-18 12:28:12 UTC (rev 3635) @@ -564,7 +564,7 @@ } # end final walk towards the edges portfolio <- tmp_w - colnames(portfolio) <- colnames(weights) + colnames(portfolio) <- colnames(w) # checks for infeasible portfolio # Stop execution and return an error if an infeasible portfolio is created @@ -572,7 +572,7 @@ # action (try again with more permutations, relax constraints, different # method to normalize, etc.) if (sum(portfolio) < min_sum | sum(portfolio) > max_sum){ - portfolio <- weights + portfolio <- w stop("Infeasible portfolio created, perhaps increase max_permutations and/or adjust your parameters.") } return(portfolio) From noreply at r-forge.r-project.org Sat Apr 18 18:44:11 2015 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Sat, 18 Apr 2015 18:44:11 +0200 (CEST) Subject: [Returnanalytics-commits] r3636 - pkg/PortfolioAnalytics Message-ID: <20150418164411.25925184624@r-forge.r-project.org> Author: rossbennett34 Date: 2015-04-18 18:44:10 +0200 (Sat, 18 Apr 2015) New Revision: 3636 Modified: pkg/PortfolioAnalytics/DESCRIPTION Log: - switch maintainer back to Brian - Date in ISO 8601 yyyy-mm-dd format - bump version Modified: pkg/PortfolioAnalytics/DESCRIPTION =================================================================== --- pkg/PortfolioAnalytics/DESCRIPTION 2015-04-18 12:28:12 UTC (rev 3635) +++ pkg/PortfolioAnalytics/DESCRIPTION 2015-04-18 16:44:10 UTC (rev 3636) @@ -12,9 +12,9 @@ person(given="Hezky",family="Varon",role="ctb") , person(given="Guy",family="Yollin",role="ctb") , person(given="R. Douglas",family="Martin",role="ctb") ) -Version: 0.9.3635 -Date: $Date$ -Maintainer: Ross Bennett +Version: 1.0.3636 +Date: 2015-04-18 +Maintainer: Brian G. Peterson Description: Portfolio optimization and analysis routines and graphics. Depends: R (>= 2.14.0), From noreply at r-forge.r-project.org Wed Apr 22 06:49:26 2015 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Wed, 22 Apr 2015 06:49:26 +0200 (CEST) Subject: [Returnanalytics-commits] r3637 - in pkg/FactorAnalytics: . R man tests vignettes Message-ID: <20150422044926.3969618788C@r-forge.r-project.org> Author: pragnya Date: 2015-04-22 06:49:25 +0200 (Wed, 22 Apr 2015) New Revision: 3637 Added: pkg/FactorAnalytics/tests/FactorAnalytics_04_21_15.pdf Removed: pkg/FactorAnalytics/tests/FactorAnalytics_04_16_15.pdf Modified: pkg/FactorAnalytics/DESCRIPTION pkg/FactorAnalytics/NAMESPACE pkg/FactorAnalytics/R/fitSfm.R pkg/FactorAnalytics/R/fitTsfm.R pkg/FactorAnalytics/R/plot.sfm.r pkg/FactorAnalytics/R/plot.tsfm.r pkg/FactorAnalytics/man/CornishFisher.Rd pkg/FactorAnalytics/man/fitSfm.Rd pkg/FactorAnalytics/man/fitTsfm.Rd pkg/FactorAnalytics/man/fitTsfm.control.Rd pkg/FactorAnalytics/man/fitTsfmLagBeta.Rd pkg/FactorAnalytics/man/fitTsfmMT.Rd pkg/FactorAnalytics/man/fitTsfmUpDn.Rd pkg/FactorAnalytics/man/fmCov.Rd pkg/FactorAnalytics/man/fmEsDecomp.Rd pkg/FactorAnalytics/man/fmSdDecomp.Rd pkg/FactorAnalytics/man/fmVaRDecomp.Rd pkg/FactorAnalytics/man/fmmc.Rd pkg/FactorAnalytics/man/fmmc.estimate.se.Rd pkg/FactorAnalytics/man/paFm.Rd pkg/FactorAnalytics/man/plot.pafm.Rd pkg/FactorAnalytics/man/plot.sfm.Rd pkg/FactorAnalytics/man/plot.tsfm.Rd pkg/FactorAnalytics/man/plot.tsfmUpDn.Rd pkg/FactorAnalytics/man/predict.sfm.Rd pkg/FactorAnalytics/man/predict.tsfm.Rd pkg/FactorAnalytics/man/predict.tsfmUpDn.Rd pkg/FactorAnalytics/man/print.pafm.Rd pkg/FactorAnalytics/man/print.sfm.Rd pkg/FactorAnalytics/man/print.tsfm.Rd pkg/FactorAnalytics/man/print.tsfmUpDn.Rd pkg/FactorAnalytics/man/summary.pafm.Rd pkg/FactorAnalytics/man/summary.sfm.Rd pkg/FactorAnalytics/man/summary.tsfm.Rd pkg/FactorAnalytics/man/summary.tsfmUpDn.Rd pkg/FactorAnalytics/vignettes/fitSfm_vignette.R pkg/FactorAnalytics/vignettes/fitSfm_vignette.Rnw pkg/FactorAnalytics/vignettes/fitSfm_vignette.pdf pkg/FactorAnalytics/vignettes/fitTsfm_vignette.R pkg/FactorAnalytics/vignettes/fitTsfm_vignette.Rnw pkg/FactorAnalytics/vignettes/fitTsfm_vignette.pdf pkg/FactorAnalytics/vignettes/fmmc_vignette.Rnw Log: Improved plot.sfm options and formatting. Updated Roxygen package for documentation. Modified: pkg/FactorAnalytics/DESCRIPTION =================================================================== --- pkg/FactorAnalytics/DESCRIPTION 2015-04-18 16:44:10 UTC (rev 3636) +++ pkg/FactorAnalytics/DESCRIPTION 2015-04-22 04:49:25 UTC (rev 3637) @@ -1,8 +1,8 @@ Package: factorAnalytics Type: Package Title: Factor Analytics -Version:2.0.17 -Date:2015-04-14 +Version:2.0.18 +Date:2015-04-21 Author: Eric Zivot, Sangeetha Srinivasan and Yi-An Chen Maintainer: Sangeetha Srinivasan Description: An R package for the estimation and risk analysis of linear factor Modified: pkg/FactorAnalytics/NAMESPACE =================================================================== --- pkg/FactorAnalytics/NAMESPACE 2015-04-18 16:44:10 UTC (rev 3636) +++ pkg/FactorAnalytics/NAMESPACE 2015-04-22 04:49:25 UTC (rev 3637) @@ -1,4 +1,4 @@ -# Generated by roxygen2 (4.1.0): do not edit by hand +# Generated by roxygen2 (4.1.1): do not edit by hand S3method(coef,sfm) S3method(coef,tsfm) @@ -60,7 +60,6 @@ importFrom(RCurl,merge.list) importFrom(bestglm,bestglm) importFrom(boot,boot) -importFrom(corrplot,corrplot) importFrom(corrplot,corrplot.mixed) importFrom(doSNOW,registerDoSNOW) importFrom(foreach,foreach) Modified: pkg/FactorAnalytics/R/fitSfm.R =================================================================== --- pkg/FactorAnalytics/R/fitSfm.R 2015-04-18 16:44:10 UTC (rev 3636) +++ pkg/FactorAnalytics/R/fitSfm.R 2015-04-22 04:49:25 UTC (rev 3637) @@ -15,19 +15,20 @@ #' #' Let \code{N} be the number of columns or assets and \code{T} be the number #' of rows or observations. When \code{N < T}, Principal Component Analysis -#' (PCA) is performed. Otherwise, Asymptotic Principal Component Analysis -#' (APCA) is performed. In either case, any number of factors less than -#' \code{min(N,T)} can be chosen via argument \code{k}. Default is 1. Refer to -#' Zivot and Wang (2007) for more details and references. +#' (PCA) is performed. Any number of factors less than \code{min(N,T)} can be +#' chosen via argument \code{k}. Default is 1. Refer to Zivot and Wang (2007) +#' for more details and references. #' -#' Alternately, for APCA, a method to determine the number of factors can be -#' specified: \code{k="bn"} corresponds to Bai and Ng (2002) and \code{k="ck"} -#' corresponds to Connor and Korajczyk (1993). User can specify the maximum -#' number of factors, \code{max.k} to consider with these methods. If not, it -#' is assumed to be either 10 or $T-1$, whichever is smaller. +#' When \code{N >= T}, Asymptotic Principal Component Analysis (APCA) is +#' performed. The user can directly specify \code{k} similar to PCA above, or a +#' method to automatically determine the number of factors can be specified: +#' \code{k="bn"} corresponds to Bai and Ng (2002) and \code{k="ck"} corresponds +#' to Connor and Korajczyk (1993). Users can choose the maximum number of +#' factors, \code{max.k}, to consider with these methods. The default for +#' \code{max.k} is set to be 10 or $T-1$, whichever is smaller. #' #' \code{refine} specifies whether a refinement of the APCA procedure from -#' Connor and Korajczyk (1988) that may improve efficiency is to be used. +#' Connor and Korajczyk (1988), that may improve efficiency, is to be used. #' #' When \code{corr=TRUE}, the correlation matrix of returns are used for #' finding the principal components instead of the covariance matrix. This is @@ -44,8 +45,8 @@ #' #' @param data vector, matrix, data.frame, xts, timeSeries or zoo object with #' asset returns. See details. -#' @param k number of factors; a number (or) a method for determining the -#' optimal number of factors, one of "bn" or "ck". See details. Default is 1. +#' @param k number of factors (or) a method for determining the optimal number +#' of factors, one of "bn" or "ck". See details. Default is 1. #' @param max.k scalar; the maximum number of factors to be considered for #' methods "bn" or "ck". Default is \code{NULL}. See details. #' @param refine logical; whether to use the Connor-Korajczyk refinement for Modified: pkg/FactorAnalytics/R/fitTsfm.R =================================================================== --- pkg/FactorAnalytics/R/fitTsfm.R 2015-04-18 16:44:10 UTC (rev 3636) +++ pkg/FactorAnalytics/R/fitTsfm.R 2015-04-22 04:49:25 UTC (rev 3637) @@ -84,8 +84,8 @@ #' class \code{lm} if \code{fit.method="LS" or "DLS"}, class \code{lmRob} if #' the \code{fit.method="Robust"}, or class \code{lars} if #' \code{variable.selection="lars"}.} -#' \item{alpha}{length-N vector of estimated alphas.} -#' \item{beta}{N x K matrix of estimated betas.} +#' \item{alpha}{N x 1 data.frame of estimated alphas.} +#' \item{beta}{N x K data.frame of estimated betas.} #' \item{r2}{length-N vector of R-squared values.} #' \item{resid.sd}{length-N vector of residual standard deviations.} #' \item{fitted}{xts data object of fitted values; iff @@ -246,10 +246,10 @@ } # extract coefficients from fitted factor models returned above - coef.mat <- makePaddedDataFrame(lapply(reg.list, coef)) - alpha <- coef.mat[, 1, drop=FALSE] - # to get alpha of class numeric, do: aplha <- coef.mat[,1] - beta <- coef.mat[, -1, drop=FALSE] + coef.df <- makePaddedDataFrame(lapply(reg.list, coef)) + alpha <- coef.df[, 1, drop=FALSE] + # to get alpha of class numeric, do: aplha <- coef.df[,1] + beta <- coef.df[, -1, drop=FALSE] # reorder and expand columns of beta to match factor.names tmp <- matrix(NA, length(asset.names), length(factor.names)) colnames(tmp) <- factor.names @@ -478,10 +478,10 @@ coef.tsfm <- function(object, ...) { # cbind alpha and beta; works for all fit and var selection methods - coef.mat <- cbind(object$alpha, object$beta) + coef.df <- cbind(object$alpha, object$beta) # name for alpha/intercept column - colnames(coef.mat)[1] <- "(Intercept)" - return(coef.mat) + colnames(coef.df)[1] <- "(Intercept)" + return(coef.df) } #' @rdname fitTsfm Modified: pkg/FactorAnalytics/R/plot.sfm.r =================================================================== --- pkg/FactorAnalytics/R/plot.sfm.r 2015-04-18 16:44:10 UTC (rev 3636) +++ pkg/FactorAnalytics/R/plot.sfm.r 2015-04-22 04:49:25 UTC (rev 3637) @@ -4,74 +4,82 @@ #' Plots chosen characteristic(s) for one or more assets. #' #' @details -#' If the plot type argument is not specified, a menu prompts for user input -#' and the corresponding plot is output. And, the menu is repeated for -#' user convenience in plotting multiple characteristics. Selecting '0' from -#' the menu exits the current \code{plot.sfm} call. Alternately, setting -#' \code{loop=FALSE} will exit after plotting any one chosen characteristic -#' without the need for menu selection. +#' The function can be used for group plots and individual plots. User can +#' select the type of plot either from the menu prompt (default) or directly +#' via argument \code{which}. #' -#' Group plots are the default. The variables in \code{asset.subset} and factors -#' in \code{asset.subset} are plotted depending on the characteristic chosen. -#' The default is to show the first 4 factors and first 5 assets. +#' In case multiple plots are needed, the menu is repeated after each plot +#' (enter 0 to exit). User can also input a numeric vector of plot options via +#' \code{which}. #' -#' Individual asset plots are selected by specifying \code{plot.single=TRUE}. -#' In which case, \code{asset.name} is necessary if multiple assets -#' were modeled in \code{x}. However, if the \code{fitSfm} object contains only -#' one asset's factor model fit, \code{plot.sfm} can infer this automatically, -#' without user input. +#' Group plots are the default. The selected assets in \code{a.sub} and +#' selected factors in \code{f.sub} are plotted depending on the +#' characteristic chosen. The default is to show the first 2 factors and first +#' 6 assets. #' +#' Setting \code{plot.single=TRUE} enables individual plots. If there is more +#' than one asset fit by \code{x}, \code{asset.name} should be specified. +#' In case the \code{tsfm} object \code{x} contains only a single asset fit, +#' plot.tsfm can infer \code{asset.name} without user input. +#' #' @param x an object of class \code{sfm} produced by \code{fitSfm}. -#' @param which.plot.group a number to indicate the type of group plot for -#' multiple assets. If \code{NULL} (default), the following menu appears: \cr +#' @param which a number to indicate the type of plot. If a subset of the plots +#' is required, specify a subset of the numbers 1:13 for group plots and 1:18 +#' for individual plots. If \code{which=NULL} (default), the following menu +#' appears: \cr \cr +#' For plots of a group of assets: \cr #' 1 = Screeplot of eigenvalues, \cr #' 2 = Time series plot of estimated factors, \cr #' 3 = Estimated factor loadings, \cr #' 4 = Histogram of R-squared, \cr #' 5 = Histogram of residual volatility,\cr -#' 6 = Factor model residual correlation \cr -#' 7 = Factor model correlation,\cr -#' 8 = Factor contribution to SD,\cr -#' 9 = Factor contribution to ES,\cr -#' 10 = Factor contribution to VaR, \cr -#' 11 = Factor mimicking portfolio weights - top long and short positions in each factor, \cr -#' 12 = Asset correlations - top long and short positions in each factor -#' @param factor.subset vector of names/indices of factors to show for group -#' plots. Default is 1:4. -#' @param asset.subset vector of names/indices of assets to show for group -#' plots. Default is 1:5. +#' 6 = Factor model residuals scatterplot matrix, with histograms, density overlays, correlations and significance stars, \cr +#' 7 = Factor model residual correlation \cr +#' 8 = Factor model return correlation,\cr +#' 9 = Factor contribution to SD,\cr +#' 10 = Factor contribution to ES,\cr +#' 11 = Factor contribution to VaR, \cr +#' 12 = Factor mimicking portfolio weights - top long and short positions in each factor, \cr +#' 13 = Asset correlations - top long and short positions in each factor \cr \cr +#' For individual asset plots:\cr +#' 1 = Actual and fitted,\cr +#' 2 = Actual vs fitted,\cr +#' 3 = Residuals vs fitted, \cr +#' 4 = Sqrt. of modified residuals vs fitted, \cr +#' 5 = Residuals with standard error bands, \cr +#' 6 = Time series of squared residuals, \cr +#' 7 = Time series of absolute residuals,\cr +#' 8 = SACF and PACF of residuals,\cr +#' 9 = SACF and PACF of squared residuals,\cr +#' 10 = SACF and PACF of absolute residuals,\cr +#' 11 = Non-parametric density of residuals with normal overlaid, \cr +#' 12 = Non-parametric density of residuals with skew-t overlaid, \cr +#' 13 = Histogram of residuals with non-parametric density and normal overlaid,\cr +#' 14 = QQ-plot of residuals,\cr +#' 15 = CUSUM test-Recursive residuals,\cr +#' 16 = CUSUM test-LS residuals,\cr +#' 17 = Recursive estimates (RE) test of LS regression coefficients,\cr +#' 18 = Rolling regression over a 24-period observation window +#' @param f.sub vector of indexes of factors to show for group plots. Default is 1:2. +#' @param a.sub vector of indexes of assets to show for group plots. Default is 1:6. #' @param n.top scalar; number of largest and smallest weights to display for #' each factor mimicking portfolio. Default is 3. #' @param plot.single logical; If \code{TRUE} plots the characteristics of an #' individual asset's factor model. The type of plot is given by -#' \code{which.plot.single}. Default is \code{FALSE}. +#' \code{which}. Default is \code{FALSE}. #' @param asset.name name of the individual asset to be plotted. Is necessary #' if \code{x} contains multiple asset fits and \code{plot.single=TRUE}. -#' @param which.plot.single a number to indicate the type of group plot for an -#' individual asset. If \code{NULL} (default), the following menu appears: \cr -#' 1 = Time series plot of actual and fitted asset returns,\cr -#' 2 = Time series plot of residuals with standard error bands, \cr -#' 3 = Time series plot of squared residuals, \cr -#' 4 = Time series plot of absolute residuals,\cr -#' 5 = SACF and PACF of residuals,\cr -#' 6 = SACF and PACF of squared residuals,\cr -#' 7 = SACF and PACF of absolute residuals,\cr -#' 8 = Histogram of residuals with normal curve overlayed,\cr -#' 9 = Normal qq-plot of residuals,\cr -#' 10 = CUSUM test-Recursive residuals,\cr -#' 11 = CUSUM test-LS residuals,\cr -#' 12 = Recursive estimates (RE) test of LS regression coefficients,\cr -#' 13 = Rolling estimates over a 24-period observation window -#' @param colorset color palette to use for all the plots. Default is -#' \code{c(1:12)}. The 1st element will be used for individual time series -#' plots or the 1st series plotted, the 2nd element for the 2nd object in the -#' plot and so on. +#' @param colorset color palette to use for all the plots. The 1st element will +#' be used for individual time series plots or the 1st object plotted, the 2nd +#' element for the 2nd object in the plot and so on. #' @param legend.loc places a legend into one of nine locations on the chart: #' "bottomright", "bottom", "bottomleft", "left", "topleft", "top", "topright", #' "right", or "center". Default is "bottomright". Use \code{legend.loc=NULL} #' to suppress the legend. #' @param las one of {0, 1, 2, 3} to set the direction of axis labels, same as -#' in \code{plot}. Default here is 1. +#' in \code{plot}. Default is 1. +#' @param lwd set the line width, same as in \code{\link{plot}}. Default is 2. +#' @param maxlag optional number of lags to be calculated for ACF. Default is 15. #' @param VaR.method a method for computing VaR; one of "modified", "gaussian", #' "historical" or "kernel". VaR is computed using #' \code{\link[PerformanceAnalytics]{VaR}}. Default is "historical". @@ -80,29 +88,32 @@ #' @param cum.var logical; If \code{TRUE}, the cumulative fraction of the #' variance is printed above each bar in the screeplot of eigenvalues. Default #' is \code{TRUE}. -#' @param loop logical to indicate if the plot menu should be repeated. Default -#' is \code{TRUE}. #' @param ... further arguments to be passed to other plotting functions. #' #' @author Eric Zivot, Sangeetha Srinivasan and Yi-An Chen #' -#' @seealso \code{\link{fitSfm}} and \code{\link{summary.sfm}} for details -#' about the time series factor model fit, extractor functions and summary -#' statistics. +#' @seealso \code{\link{fitSfm}}, \code{\link{residuals.sfm}}, +#' \code{\link{fitted.sfm}}, \code{\link{fmCov.sfm}} and +#' \code{\link{summary.sfm}} for statistical factor model fitting and related +#' S3 methods. Refer to \code{\link{fmSdDecomp}}, \code{\link{fmEsDecomp}}, +#' \code{\link{fmVaRDecomp}} for factor model risk measures. #' -#' \code{\link[strucchange]{efp}} for CUSUM tests. +#' Here is a list of plotting functions used. (I=individual, G=Group) +#' I(1,5,6,7) - \code{\link[PerformanceAnalytics]{chart.TimeSeries}}, +#' I(2,3,4) - \code{\link[graphics]{plot.default}}, +#' I(3,4) - \code{\link[graphics]{panel.smooth}}, +#' I(8,9,10) - \code{\link[PerformanceAnalytics]{chart.ACFplus}}, +#' I(11,12) - \code{\link[stats]{plot.density}}, +#' I(13), G(4,5) - \code{\link[PerformanceAnalytics]{chart.Histogram}}, +#' I(14) - \code{\link[PerformanceAnalytics]{chart.QQPlot}}, +#' I(15,16,17) - \code{\link[strucchange]{plot.efp}}, +#' I(18) - \code{\link[zoo]{plot.zoo}}, +#' G(1,12) - \code{\link[graphics]{barplot}}, +#' G(2) - \code{\link[lattice]{xyplot}}, +#' G(3,9,10,11) - \code{\link[lattice]{barchart}}, +#' G(6) - \code{\link[PerformanceAnalytics]{chart.Correlation}} and +#' G(7,8,13) - \code{\link[corrplot]{corrplot.mixed}}. #' -#' \code{\link[xts]{plot.xts}}, -#' \code{\link[PerformanceAnalytics]{chart.TimeSeries}}, -#' \code{\link[PerformanceAnalytics]{chart.ACFplus}}, -#' \code{\link[PerformanceAnalytics]{chart.Histogram}}, -#' \code{\link[PerformanceAnalytics]{chart.QQPlot}}, -#' \code{\link[graphics]{barplot}}, \code{\link[lattice]{barchart}} and -#' \code{\link[corrplot]{corrplot}} for plotting methods used. -#' -#' \code{\link{fmSdDecomp}}, \code{\link{fmEsDecomp}}, -#' \code{\link{fmVaRDecomp}} for factor model risk measures. -#' #' @examples #' #' # load data from the database @@ -111,37 +122,43 @@ #' # APCA with number of factors, k=15 #' fit.apca <- fitSfm(r.W, k=15, refine=TRUE) #' -#' # group plot(default); select type from menu prompt -#' # menu is auto-looped to get multiple types of plots based on the same fit +#' # for group plots (default), user can select plot option from menu prompt +#' # menu is repeated to get multiple types of plots based on the same fit #' # plot(fit.apca) #' -#' # plot the factor betas of 1st 4 assets fitted above -#' # loop disabled to get one type of plot without interative menu -#' plot(fit.apca, asset.subset=1:4, which.plot.group=3, loop=FALSE) +#' # choose specific plot option(s) using which +#' # plot the first 4 factor betas of the first 4 assets fitted above +#' plot(fit.apca, f.sub=1:4, a.sub=1:4, which=3) #' -#' # plot factor model return correlation; angular order of the eigenvectors -#' plot(fit.apca, which.plot.group=7, loop=FALSE, -#' order="AOE", method="ellipse", tl.pos = "d") +#' # plot factor model residuals scatterplot matrix, with histograms, density +#' # overlays, correlations and significance stars +#' plot(fit.apca, which=6) #' +#' # for individual plots: set plot.single=TRUE and specify asset.name #' # histogram of residuals from an individual asset's factor model fit -#' plot(fit.apca, plot.single=TRUE, asset.name="AFL", which.plot.single=8, -#' loop=FALSE) +#' plot(fit.apca, plot.single=TRUE, asset.name="AFL", which=13) #' #' @importFrom PerformanceAnalytics chart.TimeSeries chart.ACFplus -#' chart.Histogram chart.QQPlot +#' chart.Histogram chart.QQPlot chart.Correlation #' @importFrom lattice barchart xyplot panel.barchart panel.grid -#' @importFrom corrplot corrplot +#' @importFrom corrplot corrplot.mixed #' @importFrom strucchange efp +#' @importFrom sn dst st.mple #' #' @method plot sfm #' @export -plot.sfm <- function(x, which.plot.group=NULL, factor.subset=1:4, - asset.subset=1:5, n.top=3, plot.single=FALSE, asset.name, - which.plot.single=NULL, colorset=(1:12), - legend.loc="topleft", las=1, VaR.method="historical", - cum.var=TRUE, eig.max=0.9, loop=TRUE, ...) { +plot.sfm <- function(x, which=NULL, f.sub=1:2, a.sub=1:6, n.top=3, + plot.single=FALSE, asset.name, + colorset=c("royalblue","dimgray","olivedrab","firebrick", + "goldenrod","mediumorchid","deepskyblue", + "chocolate","darkslategray"), + legend.loc="topleft", las=1, lwd=2, maxlag=15, + VaR.method="historical", eig.max=0.9, cum.var=TRUE, ...) { + which.vec <- which + which <- which[1] + if (plot.single==TRUE) { if (missing(asset.name) && length(x$asset.names)>1) { @@ -153,24 +170,35 @@ i <- asset.name } # extract info from the fitSfm object - plotData <- merge.xts(x$data[,i], fitted(x)[,i]) - colnames(plotData) <- c("Actual","Fitted") - Residuals <- residuals(x)[,i] - fit <- lm(x$data[,i] ~ x$factors) + plotData <- merge.xts(x$data[,i], fitted(x)[,i], residuals(x)[,i]) + colnames(plotData) <- c("Actual","Fitted","Residuals") + Residuals <- na.omit(plotData[,"Residuals"]) + fitData <- merge(x$data[,i], x$factors) + fit <- lm(as.formula(paste(i," ~ .")), data=fitData) + resid.sd <- x$resid.sd[i] + den <- density(Residuals) + xval <- den$x + den.norm <- dnorm(xval, mean=mean(Residuals), sd=resid.sd) + den.st <- dst(xval, dp=st.mple(x=matrix(1,nrow(Residuals)), y=as.vector(Residuals))$dp) # plot selection repeat { - if (is.null(which.plot.single)) { - which.plot.single <- - menu(c("Time series plot of actual and fitted asset returns", - "Time series plot of residuals with standard error bands", - "Time series plot of squared residuals", - "Time series plot of absolute residuals", + if (is.null(which)) { + which <- + menu(c("Actual and fitted asset returns", + "Actual vs fitted asset returns", + "Residuals vs fitted asset returns", + "Sqrt. of modified residuals vs fitted", + "Residuals with standard error bands", + "Time series of squared residuals", + "Time series of absolute residuals", "SACF and PACF of residuals", "SACF and PACF of squared residuals", "SACF and PACF of absolute residuals", - "Histogram of residuals with normal curve overlayed", - "Normal qq-plot of residuals", + "Non-parametric density of residuals with normal overlaid", + "Non-parametric density of residuals with skew-t overlaid", + "Histogram of residuals with non-parametric density and normal overlaid", + "QQ-plot of residuals", "CUSUM test-Recursive residuals", "CUSUM test-LS residuals", "Recursive estimates (RE) test of LS regression coefficients", @@ -180,104 +208,163 @@ par(las=las) # default horizontal axis labels - switch(which.plot.single, + switch(which, "1L" = { - ## time series plot of actual and fitted asset returns - chart.TimeSeries(plotData, main=paste("Returns:",i), - colorset=colorset, xlab="", - ylab="Actual and fitted asset returns", + ## Time series plot of actual and fitted asset returns + chart.TimeSeries(plotData[,1:2], main=paste("Actual and fitted:",i), + colorset=colorset, xlab="", ylab="Returns", lwd=lwd, legend.loc=legend.loc, pch=NULL, las=las, ...) }, "2L" = { - ## time series plot of residuals with standard error bands + ## Actual vs fitted asset returns + plot(x=coredata(plotData[,2]), y=coredata(plotData[,1]), + xlab="Fitted", ylab="Actual", col=colorset[1], + main=paste("Actual vs fitted:",i), las=las, ...) + abline(0, 1, col="dimgray",lty="dotted", lwd=lwd) + }, "3L" = { + ## Residuals vs fitted asset returns + plot(x=coredata(plotData[,2]), y=coredata(plotData[,3]), + xlab="Fitted", ylab="Residuals", col=colorset[1], + main=paste("Residuals vs fitted:",i), las=las, ...) + panel.smooth(x=coredata(plotData[,2]), y=coredata(plotData[,3]), + col=colorset[1], col.smooth=colorset[2], lwd=lwd) + }, "4L" = { + ## Square root of absolute modified residuals vs fitted asset returns + yval <- sqrt(abs(Residuals/sqrt(1-hatvalues(fit)))) + plot(x=coredata(na.omit(plotData[,2])), y=yval, xlab="Fitted", + ylab=expression(sqrt(abs("Modified Residuals"))), col=colorset[1], + main=paste("Sqrt. modified residuals vs fitted:",i), las=las, ...) + panel.smooth(x=coredata(na.omit(plotData[,2])), y=yval, + col=colorset[1], col.smooth=colorset[2], lwd=lwd) + }, "5L" = { + ## Time series plot of residuals with standard error bands chart.TimeSeries(Residuals, main=paste("Residuals:",i), colorset=colorset, xlab="", ylab="Residuals", - lwd=2, lty="solid", las=las, ...) - abline(h=1.96*x$resid.sd[i], lwd=2, lty="dotted", col="red") - abline(h=-1.96*x$resid.sd[i], lwd=2, lty="dotted", col="red") - legend(x=legend.loc, lty=c("solid","dotted"), - col=c(colorset[1],"red"), lwd=2, - legend=c("Residuals",expression("\u00b1 1.96"*sigma))) - }, "3L" = { - ## time series plot of squared residuals + lwd=lwd, lty="solid", las=las, ...) + abline(h=1.96*x$resid.sd[i], lwd=lwd, lty="dotted", col=colorset[2]) + abline(h=-1.96*x$resid.sd[i], lwd=lwd, lty="dotted", col=colorset[2]) + legend(x=legend.loc, lty=c("solid","dotted"), col=c(colorset[1:2]), + lwd=lwd, bty="n", legend=c("Residuals",expression("\u00b1 1.96 "*sigma))) + }, "6L" = { + ## Time series plot of squared residuals chart.TimeSeries(Residuals^2, colorset=colorset, xlab="", - ylab=" Squared Residuals", + ylab=" Squared Residuals", lwd=lwd, main=paste("Squared Residuals:",i), - legend.loc=legend.loc, pch=NULL, las=las, ...) - }, "4L" = { + legend.loc=NULL, pch=NULL, las=las, ...) + }, "7L" = { ## time series plot of absolute residuals chart.TimeSeries(abs(Residuals), colorset=colorset, xlab="", - ylab="Absolute Residuals", + ylab="Absolute Residuals", lwd=lwd, main=paste("Absolute Residuals:",i), - legend.loc=legend.loc, pch=NULL, las=las, ...) - }, "5L" = { + legend.loc=NULL, pch=NULL, las=las, ...) + }, "8L" = { ## SACF and PACF of residuals - chart.ACFplus(Residuals, col=colorset[1], + chart.ACFplus(Residuals, maxlag=maxlag, main=paste("SACF & PACF - Residuals:",i), ...) - }, "6L" = { + }, "9L" = { ## SACF and PACF of squared residuals - chart.ACFplus(Residuals^2, col=colorset[1], ..., - main=paste("SACF & PACF - Squared residuals:",i)) - }, "7L" = { + chart.ACFplus(Residuals^2, maxlag=maxlag, + main=paste("SACF & PACF - Squared residuals:",i), ...) + }, "10L" = { ## SACF and PACF of absolute residuals chart.ACFplus(abs(Residuals), col=colorset[1], ..., main=paste("SACF & PACF - Absolute Residuals:",i)) - }, "8L" = { - ## histogram of residuals with normal curve overlayed + }, "11L" = { + ## Non-parametric density of residuals with normal overlaid + ymax <- ceiling(max(0,den$y,den.norm)) + plot(den, xlab="Return residuals", lwd=lwd, col=colorset[1], + ylim=c(0,ymax), main=paste("Density of residuals:",i), ...) + rug(Residuals, col="dimgray") + lines(xval, den.norm, col=colorset[2], lwd=lwd, lty="dashed") + legend(x=legend.loc, lty=c("solid","dashed"), col=c(colorset[1:2]), + lwd=lwd, bty="n", legend=c("KDE","Normal")) + }, "12L" = { + ## Non-parametric density of residuals with skew-t overlaid + ymax <- ceiling(max(0,den$y,den.st)) + plot(den, xlab="Return residuals", lwd=lwd, col=colorset[1], + ylim=c(0,ymax), main=paste("Density of residuals:",i), ...) + rug(Residuals, col="dimgray") + lines(xval, den.st, col=colorset[2], lty="dashed", lwd=lwd) + legend(x=legend.loc, lty=c("solid","dashed"), col=c(colorset[1:2]), + lwd=lwd, bty="n", legend=c("KDE","Skew-t")) + }, "13L" = { + ## Histogram of residuals with non-parametric density and normal overlaid methods <- c("add.density","add.normal","add.rug") - chart.Histogram(Residuals, xlab="Return residuals", - methods=methods, colorset=colorset, - main=paste("Histogram of Residuals:",i), ...) - }, "9L" = { - ## normal qq-plot of residuals - chart.QQPlot(Residuals, envelope=0.95, col=colorset, + chart.Histogram(Residuals, xlab="Return residuals", methods=methods, + colorset=colorset[c(1,2,3)], + lwd=lwd, main=paste("Histogram of residuals:",i), ...) + legend(x=legend.loc, col=colorset[c(2,3)], lwd=lwd, bty="n", + legend=c("KDE","Normal")) + }, "14L" = { + ## QQ-plot of residuals + chart.QQPlot(Residuals, envelope=0.95, col=colorset[1:2], lwd=lwd, main=paste("QQ-plot of Residuals:",i), ...) - legend(x=legend.loc, col="red", lty="dotted", lwd=1, - legend=c("0.95 confidence envelope")) - }, "10L" = { + legend(x=legend.loc, col=colorset[2], lty="dashed", lwd=1, bty="n", + legend=c("0.95 C.Env.")) + }, "15L" = { ## Recursive CUSUM test cusum.rec <- efp(formula(fit), type="Rec-CUSUM", data=fit$model) plot(cusum.rec, main=paste("Recursive CUSUM test:",i), las=las, - col=colorset, ...) - }, "11L" = { + col=colorset, lwd=lwd, ...) + }, "16L" = { ## LS-based CUSUM test - cusum.ols <- efp(formula(fit), type="LS-CUSUM", data=fit$model) + cusum.ols <- efp(formula(fit), type="OLS-CUSUM", data=fit$model) plot(cusum.ols, main=paste("LS-based CUSUM test:",i), las=las, - col=colorset, ...) - }, "12L" = { - ## Recursive estimates (RE) test of LS regression coefficients + col=colorset, lwd=lwd, ...) + }, "17L" = { + ## Recursive estimates (RE) test of LS regression coefficients + if (x$k > 9) { + stop("Plotting limit: This option is not available when K > 9.") + } cusum.est <- efp(formula(fit), type="RE", data=fit$model) - plot(cusum.est, functional=NULL, col=colorset, las=0, + plot(cusum.est, functional=NULL, col=colorset, las=0, cex.lab=0.7, main=paste("RE test (Recursive estimates test):",i), ...) - }, "13L" = { + par(las=las, cex.lab=1) + }, "18L" = { ## Rolling estimates over 24-period observation window - rollReg <- function(data.z, formula) { - coef(lm(formula, data=as.data.frame(data.z))) - } reg.z <- zoo(fit$model, as.Date(rownames(fit$model))) - rollReg.z <- rollapply(reg.z, FUN=rollReg, formula(fit), - width=24, by.column=FALSE, align="right") + rollReg.z <- rollapply(reg.z, width=24, by.column=FALSE, align="right", + FUN = function(z) coef(lm(formula(fit), data=as.data.frame(z)))) par(las=0) - plot(rollReg.z, ..., las=las, - main=paste("Rolling estimates (24-period obs window):",i)) - par(las=las) + plot(rollReg.z, las=las, cex=0.8, lwd=lwd, col=colorset[1], ..., + main=paste("Rolling regression (24-period obs window):",i)) + par(las=las, cex=1) }, invisible() ) # repeat menu if user didn't choose to exit from the plot options - if (which.plot.single==0 || loop==FALSE) {break} - else {which.plot.single=NULL} + if (which==0 || length(which.vec)==1) {break} + if (length(which.vec)>1) { + which.vec <- which.vec[-1] + which <- which.vec[1] + par(ask=TRUE) + } else {which=NULL} } } else { # start of group asset plots + n <- length(x$asset.names) + if (n<=1) { + stop("Error: Two or more assets required for group plots.") + } + k <- x$k + f.names <- paste("F", 1:k, sep = ".") + + if (!(all(f.sub %in% f.names) || all(f.sub %in% 1:k))) { + stop("Invalid argument: f.sub is not a valid subset of factor names.") + } + if (!(all(a.sub %in% x$asset.names) || all(a.sub %in% 1:n))) { + stop("Invalid argument: a.sub is not a valid subset of asset names.") + } + # plot selection repeat { - if (is.null(which.plot.group)) { - which.plot.group <- + if (is.null(which)) { + which <- menu(c("Screeplot of eigenvalues", [TRUNCATED] To get the complete diff run: svnlook diff /svnroot/returnanalytics -r 3637 From noreply at r-forge.r-project.org Fri Apr 24 19:40:40 2015 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Fri, 24 Apr 2015 19:40:40 +0200 (CEST) Subject: [Returnanalytics-commits] r3638 - in pkg/FactorAnalytics: R inst/tests man vignettes Message-ID: <20150424174040.49A281866B9@r-forge.r-project.org> Author: pragnya Date: 2015-04-24 19:40:39 +0200 (Fri, 24 Apr 2015) New Revision: 3638 Added: pkg/FactorAnalytics/inst/tests/test-fitTsfm.r Removed: pkg/FactorAnalytics/inst/tests/test-fitTSFM.r Modified: pkg/FactorAnalytics/R/plot.sfm.r pkg/FactorAnalytics/R/plot.tsfm.r pkg/FactorAnalytics/man/plot.sfm.Rd pkg/FactorAnalytics/man/plot.tsfm.Rd pkg/FactorAnalytics/vignettes/fitSfm_vignette.R pkg/FactorAnalytics/vignettes/fitSfm_vignette.Rnw Log: Fixed minor bug in group plot factor selection using f.sub. Modified: pkg/FactorAnalytics/R/plot.sfm.r =================================================================== --- pkg/FactorAnalytics/R/plot.sfm.r 2015-04-22 04:49:25 UTC (rev 3637) +++ pkg/FactorAnalytics/R/plot.sfm.r 2015-04-24 17:40:39 UTC (rev 3638) @@ -60,8 +60,10 @@ #' 16 = CUSUM test-LS residuals,\cr #' 17 = Recursive estimates (RE) test of LS regression coefficients,\cr #' 18 = Rolling regression over a 24-period observation window -#' @param f.sub vector of indexes of factors to show for group plots. Default is 1:2. -#' @param a.sub vector of indexes of assets to show for group plots. Default is 1:6. +#' @param f.sub numeric/character vector; subset of indexes/names of factors to +#' include for group plots. Default is 1:2. +#' @param a.sub numeric/character vector; subset of indexes/names of assets to +#' include for group plots. At least 2 assets must be selected. Default is 1:6. #' @param n.top scalar; number of largest and smallest weights to display for #' each factor mimicking portfolio. Default is 3. #' @param plot.single logical; If \code{TRUE} plots the characteristics of an @@ -342,18 +344,17 @@ } else { # start of group asset plots n <- length(x$asset.names) - if (n<=1) { + if (n<=1 || length(a.sub) < 2) { stop("Error: Two or more assets required for group plots.") } + if (!(all(a.sub %in% x$asset.names)) && !(all(a.sub %in% 1:n))) { + stop("Invalid argument: a.sub is not a valid subset of asset names.") + } k <- x$k f.names <- paste("F", 1:k, sep = ".") - - if (!(all(f.sub %in% f.names) || all(f.sub %in% 1:k))) { + if (!(all(f.sub %in% f.names)) && !(all(f.sub %in% 1:k))) { stop("Invalid argument: f.sub is not a valid subset of factor names.") } - if (!(all(a.sub %in% x$asset.names) || all(a.sub %in% 1:n))) { - stop("Invalid argument: a.sub is not a valid subset of asset names.") - } # plot selection repeat { @@ -400,10 +401,10 @@ }, "3L" = { ## Estimated factor loadings - C <- coef(x)[a.sub,] + C <- x$loadings[a.sub,f.sub,drop=FALSE] Y <- row(C, as.factor=T) - X <- as.vector(C[,(f.sub+1)]) - Z <- col(C[,(f.sub+1)], as.factor=T) + X <- as.vector(as.matrix(C[,,drop=FALSE])) + Z <- col(C, as.factor=T) plot( barchart(Y~X|Z, main="Factor Loadings \n", xlab="", as.table=TRUE, origin=0, col=colorset[1], scales=list(relation="free"), ...) @@ -485,13 +486,17 @@ }, "12L" = { ## Factor mimicking portfolio weights - top long and short positions in each factor - par(mfrow=c(ceiling(length(f.sub)/2),2)) + if (length(f.sub) < 2) { + par(mfrow=c(1,1)) + } else { + par(mfrow=c(ceiling(length(f.sub)/2),2)) + } for (i in f.sub) { main=paste("Largest & smallest weights (%): ", colnames(x$loadings)[i]) s <- summary(x, n.top=n.top)$mimic.sum[[i]] top <- 100*stack(s[,c(2,4)])$values names.arg <- stack(s[,c(1,3)])$values - barplot(top, main=main, names.arg=names.arg, col=colorset[1], las=2, ...) + barplot(top, main=main, names.arg=names.arg, col=colorset[1], las=2, cex.main=0.9, ...) abline(h=0, lwd=1, lty=1, col=1) } par(mfrow=c(1,1)) Modified: pkg/FactorAnalytics/R/plot.tsfm.r =================================================================== --- pkg/FactorAnalytics/R/plot.tsfm.r 2015-04-22 04:49:25 UTC (rev 3637) +++ pkg/FactorAnalytics/R/plot.tsfm.r 2015-04-24 17:40:39 UTC (rev 3638) @@ -72,10 +72,10 @@ #' 17 = Recursive estimates (RE) test of LS regression coefficients,\cr #' 18 = Rolling regression over a 24-period observation window, \cr #' 19 = Asset returns vs factor returns (single factor model) -#' @param f.sub subset of indexes of factors to show for group plots. -#' Default is 1:2. -#' @param a.sub vector of indexes of assets to show for group plots. -#' Default is 1:6. +#' @param f.sub numeric/character vector; subset of indexes/names of factors to +#' include for group plots. Default is 1:2. +#' @param a.sub numeric/character vector; subset of indexes/names of assets to +#' include for group plots. At least 2 assets must be selected. Default is 1:6. #' @param plot.single logical; If \code{TRUE} plots the characteristics of an #' individual asset's factor model. The type of plot is given by #' \code{which}. Default is \code{FALSE}. @@ -397,16 +397,17 @@ } else { # start of group asset plots n <- length(x$asset.names) - if (n<=1) { + if (n<=1 || length(a.sub) < 2) { stop("Error: Two or more assets required for group plots.") } - if (!(all(a.sub %in% 1:n)) || length(a.sub) < 2) { - stop("Invalid argument: a.sub is not a valid subset.") + if (!(all(a.sub %in% x$asset.names)) && !(all(a.sub %in% 1:n))) { + stop("Invalid argument: a.sub is not a valid subset of asset names.") } - k <- ncol(coef(x))-1 - if (!(all(f.sub %in% 1:k))) { - stop("Invalid argument: f.sub is not a valid subset.") + k <- ncol(x$beta) + if (!(all(f.sub %in% x$factor.names)) && !(all(f.sub %in% 1:k))) { + stop("Invalid argument: f.sub is not a valid subset of factor names.") } + # plot selection repeat { if (is.null(which)) { @@ -434,32 +435,36 @@ plot( barchart(as.matrix(x$alpha)[a.sub,], main="Factor model Alpha (Intercept)", xlab="", col=colorset[1], ...) ) -# barplot(coef(x)[a.sub,1], main="Factor model Alpha (Intercept)", -# names.arg=rownames(coef(x))[a.sub], col=colorset[1], las=2, ...) -# abline(h=0, lwd=1, lty=1, col=1) + # barplot(coef(x)[a.sub,1], main="Factor model Alpha (Intercept)", + # names.arg=rownames(coef(x))[a.sub], col=colorset[1], las=2, ...) + # abline(h=0, lwd=1, lty=1, col=1) }, "2L" = { ## Factor model coefficients: Betas - C <- coef(x)[a.sub,] + C <- x$beta[a.sub,f.sub,drop=FALSE] Y <- row(C, as.factor=T) - X <- as.vector(as.matrix(C[,(f.sub+1)])) - Z <- col(C[,(f.sub+1)], as.factor=T) + X <- as.vector(as.matrix(C[,,drop=FALSE])) + Z <- col(C, as.factor=T) plot( - barchart(Y~X|Z, main="Factor model Betas \n", xlab="", as.table=TRUE, - origin=0, col=colorset[1], scales=list(relation="free"), ...) + barchart(Y~X|Z, main="Factor model Betas \n", xlab="", as.table=TRUE, + origin=0, col=colorset[1], scales=list(relation="free"), ...) ) -# par(mfrow=c(ceiling(length(f.sub)/2),2)) -# for (i in f.sub) { -# main=paste(colnames(coef(x))[i+1], "factor Betas") -# barplot(coef(x)[,i+1], main=main, names.arg=rownames(coef(x)), -# col=colorset[1], las=2, ...) -# abline(h=0, lwd=1, lty=1, col=1) -# } -# par(mfrow=c(1,1)) + # par(mfrow=c(ceiling(length(f.sub)/2),2)) + # for (i in f.sub) { + # main=paste(colnames(coef(x))[i+1], "factor Betas") + # barplot(coef(x)[,i+1], main=main, names.arg=rownames(coef(x)), + # col=colorset[1], las=2, ...) + # abline(h=0, lwd=1, lty=1, col=1) + # } + # par(mfrow=c(1,1)) }, "3L" = { ## Actual and fitted asset returns - par(mfrow=c(ceiling(length(a.sub)/2),2)) + if (length(a.sub) < 5) { + par(mfrow=c(length(a.sub),1)) + } else { + par(mfrow=c(ceiling(length(a.sub)/2),2)) + } for (i in a.sub) { asset <- x$asset.names[i] plotData <- merge.xts(x$data[,asset], fitted(x)[,asset]) @@ -537,7 +542,11 @@ if (length(x$factor.names)>1) { stop("Error: This option is only for single factor models.") } - par(mfrow=c(ceiling(length(a.sub)/2),2)) + if (length(a.sub) < 5) { + par(mfrow=c(length(a.sub),1)) + } else { + par(mfrow=c(ceiling(length(a.sub)/2),2)) + } for (i in a.sub) { fit <- x$asset.fit[[i]] asset <- x$asset.names[i] Deleted: pkg/FactorAnalytics/inst/tests/test-fitTSFM.r =================================================================== --- pkg/FactorAnalytics/inst/tests/test-fitTSFM.r 2015-04-22 04:49:25 UTC (rev 3637) +++ pkg/FactorAnalytics/inst/tests/test-fitTSFM.r 2015-04-24 17:40:39 UTC (rev 3638) @@ -1,33 +0,0 @@ -context("Test fitTsfm") - -test_that("fitTsfm is as expected", { - - fpath <- system.file("extdata", "timeSeriesReturns.csv", - package="factorAnalytics") - returns.z <- read.zoo(file=fpath, header=TRUE, sep=",", as.is=TRUE, - FUN=as.yearmon) - returns.z <- window(returns.z, start="2008-01-01", end="2012-12-31") - assets <- names(returns.z)[1:30] - ex.rets <- returns.z[,assets]-returns.z$rf - carhart <- returns.z[,c("mktrf","smb","hml","umd")] - - # fit Carhart 4-factor model using lm - ff4 <- lm(ex.rets ~ carhart) - sum4 = summary(ff4) - rsq4 <- as.numeric(sapply(X = sum4, FUN = "[", "r.squared")) - Sigma.F <- var(carhart) - beta.hat <- coef(ff4)[-1,] - Sigma.eps <- diag(as.numeric(sapply(X = sum4, FUN = "[", "sigma"))) - Sigma.R <- t(beta.hat) %*% Sigma.F %*% beta.hat + Sigma.eps^2 - - # fit Carhart 4-factor mode via fitTsfm - ff.mod <- fitTsfm(asset.names=assets, - factor.names=c("mktrf","smb","hml","umd"), - data=cbind(ex.rets,carhart)) - - # compare beta and r2 - expect_that(as.matrix(ff.mod$beta),is_equivalent_to(t(coef(ff4)[-1,]))) - expect_that(as.numeric(ff.mod$r2), - equals(as.numeric(sapply(X=sum4, FUN="[", "r.squared")))) - -}) Added: pkg/FactorAnalytics/inst/tests/test-fitTsfm.r =================================================================== --- pkg/FactorAnalytics/inst/tests/test-fitTsfm.r (rev 0) +++ pkg/FactorAnalytics/inst/tests/test-fitTsfm.r 2015-04-24 17:40:39 UTC (rev 3638) @@ -0,0 +1,33 @@ +context("Test fitTsfm") + +test_that("fitTsfm is as expected", { + + fpath <- system.file("extdata", "timeSeriesReturns.csv", + package="factorAnalytics") + returns.z <- read.zoo(file=fpath, header=TRUE, sep=",", as.is=TRUE, + FUN=as.yearmon) + returns.z <- window(returns.z, start="2008-01-01", end="2012-12-31") + assets <- names(returns.z)[1:30] + ex.rets <- returns.z[,assets]-returns.z$rf + carhart <- returns.z[,c("mktrf","smb","hml","umd")] + + # fit Carhart 4-factor model using lm + ff4 <- lm(ex.rets ~ carhart) + sum4 = summary(ff4) + rsq4 <- as.numeric(sapply(X = sum4, FUN = "[", "r.squared")) + Sigma.F <- var(carhart) + beta.hat <- coef(ff4)[-1,] + Sigma.eps <- diag(as.numeric(sapply(X = sum4, FUN = "[", "sigma"))) + Sigma.R <- t(beta.hat) %*% Sigma.F %*% beta.hat + Sigma.eps^2 + + # fit Carhart 4-factor mode via fitTsfm + ff.mod <- fitTsfm(asset.names=assets, + factor.names=c("mktrf","smb","hml","umd"), + data=cbind(ex.rets,carhart)) + + # compare beta and r2 + expect_that(as.matrix(ff.mod$beta),is_equivalent_to(t(coef(ff4)[-1,]))) + expect_that(as.numeric(ff.mod$r2), + equals(as.numeric(sapply(X=sum4, FUN="[", "r.squared")))) + +}) \ No newline at end of file Modified: pkg/FactorAnalytics/man/plot.sfm.Rd =================================================================== --- pkg/FactorAnalytics/man/plot.sfm.Rd 2015-04-22 04:49:25 UTC (rev 3637) +++ pkg/FactorAnalytics/man/plot.sfm.Rd 2015-04-24 17:40:39 UTC (rev 3638) @@ -52,9 +52,11 @@ 17 = Recursive estimates (RE) test of LS regression coefficients,\cr 18 = Rolling regression over a 24-period observation window} -\item{f.sub}{vector of indexes of factors to show for group plots. Default is 1:2.} +\item{f.sub}{numeric/character vector; subset of indexes/names of factors to +include for group plots. Default is 1:2.} -\item{a.sub}{vector of indexes of assets to show for group plots. Default is 1:6.} +\item{a.sub}{numeric/character vector; subset of indexes/names of assets to +include for group plots. At least 2 assets must be selected. Default is 1:6.} \item{n.top}{scalar; number of largest and smallest weights to display for each factor mimicking portfolio. Default is 3.} Modified: pkg/FactorAnalytics/man/plot.tsfm.Rd =================================================================== --- pkg/FactorAnalytics/man/plot.tsfm.Rd 2015-04-22 04:49:25 UTC (rev 3637) +++ pkg/FactorAnalytics/man/plot.tsfm.Rd 2015-04-24 17:40:39 UTC (rev 3638) @@ -51,11 +51,11 @@ 18 = Rolling regression over a 24-period observation window, \cr 19 = Asset returns vs factor returns (single factor model)} -\item{f.sub}{subset of indexes of factors to show for group plots. -Default is 1:2.} +\item{f.sub}{numeric/character vector; subset of indexes/names of factors to +include for group plots. Default is 1:2.} -\item{a.sub}{vector of indexes of assets to show for group plots. -Default is 1:6.} +\item{a.sub}{numeric/character vector; subset of indexes/names of assets to +include for group plots. At least 2 assets must be selected. Default is 1:6.} \item{plot.single}{logical; If \code{TRUE} plots the characteristics of an individual asset's factor model. The type of plot is given by Modified: pkg/FactorAnalytics/vignettes/fitSfm_vignette.R =================================================================== --- pkg/FactorAnalytics/vignettes/fitSfm_vignette.R 2015-04-22 04:49:25 UTC (rev 3637) +++ pkg/FactorAnalytics/vignettes/fitSfm_vignette.R 2015-04-24 17:40:39 UTC (rev 3638) @@ -48,7 +48,7 @@ ## ----fig.cap="Top 3 largest and smallest weights in the factor mimicking portfolios", fig.width=7, fig.height=4.5, fig.show='asis'---- # Factor mimicking portfolio weights from PCA fit t(fit.pca$mimic) -plot(fit.pca, which=12, n.top=3, cex.main=0.9) +plot(fit.pca, which=12, n.top=3) ## ----fig.cap="Correlations between assets with the top 3 largest and smallest positions in the F.1's factor mimicking portfolio", fig.width=5, fig.height=5, fig.show='asis'---- plot(fit.pca, which=13, f.sub=1, n.top=3) Modified: pkg/FactorAnalytics/vignettes/fitSfm_vignette.Rnw =================================================================== --- pkg/FactorAnalytics/vignettes/fitSfm_vignette.Rnw 2015-04-22 04:49:25 UTC (rev 3637) +++ pkg/FactorAnalytics/vignettes/fitSfm_vignette.Rnw 2015-04-24 17:40:39 UTC (rev 3638) @@ -186,7 +186,7 @@ <>= # Factor mimicking portfolio weights from PCA fit t(fit.pca$mimic) -plot(fit.pca, which=12, n.top=3, cex.main=0.9) +plot(fit.pca, which=12, n.top=3) @ \newpage From noreply at r-forge.r-project.org Sat Apr 25 14:49:00 2015 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Sat, 25 Apr 2015 14:49:00 +0200 (CEST) Subject: [Returnanalytics-commits] r3639 - in pkg/PerformanceAnalytics: . R man Message-ID: <20150425124900.813E0185C80@r-forge.r-project.org> Author: braverock Date: 2015-04-25 14:49:00 +0200 (Sat, 25 Apr 2015) New Revision: 3639 Modified: pkg/PerformanceAnalytics/DESCRIPTION pkg/PerformanceAnalytics/NAMESPACE pkg/PerformanceAnalytics/R/Drawdowns.R pkg/PerformanceAnalytics/R/chart.Drawdown.R pkg/PerformanceAnalytics/R/table.Drawdowns.R pkg/PerformanceAnalytics/man/ActivePremium.Rd pkg/PerformanceAnalytics/man/AdjustedSharpeRatio.Rd pkg/PerformanceAnalytics/man/AppraisalRatio.Rd pkg/PerformanceAnalytics/man/AverageDrawdown.Rd pkg/PerformanceAnalytics/man/BernardoLedoitRatio.Rd pkg/PerformanceAnalytics/man/BetaCoMoments.Rd pkg/PerformanceAnalytics/man/BurkeRatio.Rd pkg/PerformanceAnalytics/man/CAPM.RiskPremium.Rd pkg/PerformanceAnalytics/man/CAPM.alpha.Rd pkg/PerformanceAnalytics/man/CAPM.beta.Rd pkg/PerformanceAnalytics/man/CAPM.dynamic.Rd pkg/PerformanceAnalytics/man/CAPM.epsilon.Rd pkg/PerformanceAnalytics/man/CAPM.jensenAlpha.Rd pkg/PerformanceAnalytics/man/CDD.Rd pkg/PerformanceAnalytics/man/CalmarRatio.Rd pkg/PerformanceAnalytics/man/CoMoments.Rd pkg/PerformanceAnalytics/man/DRatio.Rd pkg/PerformanceAnalytics/man/DownsideDeviation.Rd pkg/PerformanceAnalytics/man/DownsideFrequency.Rd pkg/PerformanceAnalytics/man/DrawdownDeviation.Rd pkg/PerformanceAnalytics/man/DrawdownPeak.Rd pkg/PerformanceAnalytics/man/ES.Rd pkg/PerformanceAnalytics/man/FamaBeta.Rd pkg/PerformanceAnalytics/man/Frequency.Rd pkg/PerformanceAnalytics/man/HurstIndex.Rd pkg/PerformanceAnalytics/man/InformationRatio.Rd pkg/PerformanceAnalytics/man/Kappa.Rd pkg/PerformanceAnalytics/man/KellyRatio.Rd pkg/PerformanceAnalytics/man/M2Sortino.Rd pkg/PerformanceAnalytics/man/MSquared.Rd pkg/PerformanceAnalytics/man/MSquaredExcess.Rd pkg/PerformanceAnalytics/man/MarketTiming.Rd pkg/PerformanceAnalytics/man/MartinRatio.Rd pkg/PerformanceAnalytics/man/MeanAbsoluteDeviation.Rd pkg/PerformanceAnalytics/man/Modigliani.Rd pkg/PerformanceAnalytics/man/NetSelectivity.Rd pkg/PerformanceAnalytics/man/Omega.Rd pkg/PerformanceAnalytics/man/OmegaExcessReturn.Rd pkg/PerformanceAnalytics/man/OmegaSharpeRatio.Rd pkg/PerformanceAnalytics/man/PainIndex.Rd pkg/PerformanceAnalytics/man/PainRatio.Rd pkg/PerformanceAnalytics/man/ProspectRatio.Rd pkg/PerformanceAnalytics/man/Return.Geltner.Rd pkg/PerformanceAnalytics/man/Return.annualized.Rd pkg/PerformanceAnalytics/man/Return.annualized.excess.Rd pkg/PerformanceAnalytics/man/Return.calculate.Rd pkg/PerformanceAnalytics/man/Return.clean.Rd pkg/PerformanceAnalytics/man/Return.cumulative.Rd pkg/PerformanceAnalytics/man/Return.excess.Rd pkg/PerformanceAnalytics/man/Return.portfolio.Rd pkg/PerformanceAnalytics/man/Return.read.Rd pkg/PerformanceAnalytics/man/Return.relative.Rd pkg/PerformanceAnalytics/man/Selectivity.Rd pkg/PerformanceAnalytics/man/SharpeRatio.Rd pkg/PerformanceAnalytics/man/SharpeRatio.annualized.Rd pkg/PerformanceAnalytics/man/SkewnessKurtosisRatio.Rd pkg/PerformanceAnalytics/man/SmoothingIndex.Rd pkg/PerformanceAnalytics/man/SortinoRatio.Rd pkg/PerformanceAnalytics/man/SpecificRisk.Rd pkg/PerformanceAnalytics/man/StdDev.Rd pkg/PerformanceAnalytics/man/StdDev.annualized.Rd pkg/PerformanceAnalytics/man/SystematicRisk.Rd pkg/PerformanceAnalytics/man/TotalRisk.Rd pkg/PerformanceAnalytics/man/TrackingError.Rd pkg/PerformanceAnalytics/man/TreynorRatio.Rd pkg/PerformanceAnalytics/man/UlcerIndex.Rd pkg/PerformanceAnalytics/man/UpDownRatios.Rd pkg/PerformanceAnalytics/man/UpsideFrequency.Rd pkg/PerformanceAnalytics/man/UpsidePotentialRatio.Rd pkg/PerformanceAnalytics/man/UpsideRisk.Rd pkg/PerformanceAnalytics/man/VaR.Rd pkg/PerformanceAnalytics/man/VolatilitySkewness.Rd pkg/PerformanceAnalytics/man/apply.fromstart.Rd pkg/PerformanceAnalytics/man/apply.rolling.Rd pkg/PerformanceAnalytics/man/centeredmoments.Rd pkg/PerformanceAnalytics/man/chart.ACF.Rd pkg/PerformanceAnalytics/man/chart.Bar.Rd pkg/PerformanceAnalytics/man/chart.BarVaR.Rd pkg/PerformanceAnalytics/man/chart.Boxplot.Rd pkg/PerformanceAnalytics/man/chart.CaptureRatios.Rd pkg/PerformanceAnalytics/man/chart.Correlation.Rd pkg/PerformanceAnalytics/man/chart.CumReturns.Rd pkg/PerformanceAnalytics/man/chart.Drawdown.Rd pkg/PerformanceAnalytics/man/chart.ECDF.Rd pkg/PerformanceAnalytics/man/chart.Events.Rd pkg/PerformanceAnalytics/man/chart.Histogram.Rd pkg/PerformanceAnalytics/man/chart.QQPlot.Rd pkg/PerformanceAnalytics/man/chart.Regression.Rd pkg/PerformanceAnalytics/man/chart.RelativePerformance.Rd pkg/PerformanceAnalytics/man/chart.RiskReturnScatter.Rd pkg/PerformanceAnalytics/man/chart.RollingCorrelation.Rd pkg/PerformanceAnalytics/man/chart.RollingMean.Rd pkg/PerformanceAnalytics/man/chart.RollingPerformance.Rd pkg/PerformanceAnalytics/man/chart.RollingRegression.Rd pkg/PerformanceAnalytics/man/chart.Scatter.Rd pkg/PerformanceAnalytics/man/chart.SnailTrail.Rd pkg/PerformanceAnalytics/man/chart.StackedBar.Rd pkg/PerformanceAnalytics/man/chart.TimeSeries.Rd pkg/PerformanceAnalytics/man/chart.VaRSensitivity.Rd pkg/PerformanceAnalytics/man/charts.PerformanceSummary.Rd pkg/PerformanceAnalytics/man/charts.RollingPerformance.Rd pkg/PerformanceAnalytics/man/checkData.Rd pkg/PerformanceAnalytics/man/clean.boudt.Rd pkg/PerformanceAnalytics/man/findDrawdowns.Rd pkg/PerformanceAnalytics/man/kurtosis.Rd pkg/PerformanceAnalytics/man/legend.Rd pkg/PerformanceAnalytics/man/lpm.Rd pkg/PerformanceAnalytics/man/maxDrawdown.Rd pkg/PerformanceAnalytics/man/mean.geometric.Rd pkg/PerformanceAnalytics/man/skewness.Rd pkg/PerformanceAnalytics/man/sortDrawdowns.Rd pkg/PerformanceAnalytics/man/table.AnnualizedReturns.Rd pkg/PerformanceAnalytics/man/table.Arbitrary.Rd pkg/PerformanceAnalytics/man/table.Autocorrelation.Rd pkg/PerformanceAnalytics/man/table.CAPM.Rd pkg/PerformanceAnalytics/man/table.CalendarReturns.Rd pkg/PerformanceAnalytics/man/table.CaptureRatios.Rd pkg/PerformanceAnalytics/man/table.Correlation.Rd pkg/PerformanceAnalytics/man/table.Distributions.Rd pkg/PerformanceAnalytics/man/table.DownsideRisk.Rd pkg/PerformanceAnalytics/man/table.DownsideRiskRatio.Rd pkg/PerformanceAnalytics/man/table.Drawdowns.Rd pkg/PerformanceAnalytics/man/table.DrawdownsRatio.Rd pkg/PerformanceAnalytics/man/table.HigherMoments.Rd pkg/PerformanceAnalytics/man/table.InformationRatio.Rd pkg/PerformanceAnalytics/man/table.MonthlyReturns.Rd pkg/PerformanceAnalytics/man/table.ProbOutPerformance.Rd pkg/PerformanceAnalytics/man/table.RollingPeriods.Rd pkg/PerformanceAnalytics/man/table.SpecificRisk.Rd pkg/PerformanceAnalytics/man/table.Variability.Rd pkg/PerformanceAnalytics/man/textplot.Rd pkg/PerformanceAnalytics/man/zerofill.Rd Log: - add geometric argument to table.Drawdowns, thanks to Alfred Kanzler for the request - update roxygen docs for R 3.2.0 and new roxygen - bump version 3639 Modified: pkg/PerformanceAnalytics/DESCRIPTION =================================================================== --- pkg/PerformanceAnalytics/DESCRIPTION 2015-04-24 17:40:39 UTC (rev 3638) +++ pkg/PerformanceAnalytics/DESCRIPTION 2015-04-25 12:49:00 UTC (rev 3639) @@ -1,6 +1,6 @@ Package: PerformanceAnalytics Type: Package -Title: Econometric tools for performance and risk analysis +Title: Econometric Tools for Performance and Risk Analysis Authors at R: c( person(given=c("Brian","G."),family="Peterson",role=c("cre","aut","cph"), email="brian at braverock.com") , person(given="Peter",family="Carl",role=c("aut","cph"), email="peter at braverock.com") @@ -12,7 +12,7 @@ , person(given="Kyle",family="Balkissoon",role="ctb") , person(given="Diethelm",family="Wuertz",role="ctb") ) -Version: 1.4.3579 +Version: 1.4.3639 Date: $Date$ Description: Collection of econometric functions for performance and risk analysis. This package aims to aid Modified: pkg/PerformanceAnalytics/NAMESPACE =================================================================== --- pkg/PerformanceAnalytics/NAMESPACE 2015-04-24 17:40:39 UTC (rev 3638) +++ pkg/PerformanceAnalytics/NAMESPACE 2015-04-25 12:49:00 UTC (rev 3639) @@ -1,4 +1,4 @@ -# Generated by roxygen2 (4.0.2): do not edit by hand +# Generated by roxygen2 (4.1.1): do not edit by hand S3method(textplot,character) S3method(textplot,data.frame) @@ -42,6 +42,7 @@ export(DownsidePotential) export(DrawdownDeviation) export(DrawdownPeak) +export(Drawdowns) export(ES) export(ETL) export(FamaBeta) @@ -144,6 +145,7 @@ export(chart.SnailTrail) export(chart.StackedBar) export(chart.TimeSeries) +export(chart.TimeSeries.base) export(chart.VaRSensitivity) export(charts.Bar) export(charts.BarVaR) Modified: pkg/PerformanceAnalytics/R/Drawdowns.R =================================================================== --- pkg/PerformanceAnalytics/R/Drawdowns.R 2015-04-24 17:40:39 UTC (rev 3638) +++ pkg/PerformanceAnalytics/R/Drawdowns.R 2015-04-25 12:49:00 UTC (rev 3639) @@ -1,5 +1,5 @@ #' @export - +#' @rdname chart.Drawdown Drawdowns <- function (R, geometric = TRUE, ...) { # @author Peter Carl Modified: pkg/PerformanceAnalytics/R/chart.Drawdown.R =================================================================== --- pkg/PerformanceAnalytics/R/chart.Drawdown.R 2015-04-24 17:40:39 UTC (rev 3638) +++ pkg/PerformanceAnalytics/R/chart.Drawdown.R 2015-04-25 12:49:00 UTC (rev 3639) @@ -25,7 +25,9 @@ #' \code{\link{maxDrawdown}} \cr #' \code{\link{table.Drawdowns}} \cr #' \code{\link{table.DownsideRisk}} -###keywords ts +#' +#' @references Bacon, C. \emph{Practical Portfolio Performance Measurement and +#' Attribution}. Wiley. 2004. p. 88 \cr #' @examples #' #' data(edhec) Modified: pkg/PerformanceAnalytics/R/table.Drawdowns.R =================================================================== --- pkg/PerformanceAnalytics/R/table.Drawdowns.R 2015-04-24 17:40:39 UTC (rev 3638) +++ pkg/PerformanceAnalytics/R/table.Drawdowns.R 2015-04-25 12:49:00 UTC (rev 3639) @@ -17,6 +17,10 @@ #' asset returns #' @param top the number of drawdowns to include #' @param digits number of digits to round results to +#' @param geometric utilize geometric chaining (TRUE) or simple/arithmetic +#' chaining (FALSE) to aggregate returns, default TRUE +#' @param \dots any other passthru parameters +#' #' @author Peter Carl #' @seealso #' \code{\link{DownsideDeviation}} \cr @@ -48,7 +52,7 @@ #' #' @export table.Drawdowns <- -function (R, top = 5, digits = 4) +function (R, top = 5, digits = 4, geometric=TRUE, ...) {# @author Peter Carl # DESCRIPTION @@ -65,7 +69,7 @@ R = checkData(R[,1,drop=FALSE]) R = na.omit(R) - x = sortDrawdowns(findDrawdowns(R)) + x = sortDrawdowns(findDrawdowns(R, geometric=geometric, ...)) ndrawdowns = sum(x$return < 0) if (ndrawdowns < top){ Modified: pkg/PerformanceAnalytics/man/ActivePremium.Rd =================================================================== --- pkg/PerformanceAnalytics/man/ActivePremium.Rd 2015-04-24 17:40:39 UTC (rev 3638) +++ pkg/PerformanceAnalytics/man/ActivePremium.Rd 2015-04-25 12:49:00 UTC (rev 3639) @@ -1,4 +1,5 @@ -% Generated by roxygen2 (4.0.2): do not edit by hand +% Generated by roxygen2 (4.1.1): do not edit by hand +% Please edit documentation in R/ActivePremium.R \name{ActiveReturn} \alias{ActivePremium} \alias{ActiveReturn} Modified: pkg/PerformanceAnalytics/man/AdjustedSharpeRatio.Rd =================================================================== --- pkg/PerformanceAnalytics/man/AdjustedSharpeRatio.Rd 2015-04-24 17:40:39 UTC (rev 3638) +++ pkg/PerformanceAnalytics/man/AdjustedSharpeRatio.Rd 2015-04-25 12:49:00 UTC (rev 3639) @@ -1,4 +1,5 @@ -% Generated by roxygen2 (4.0.2): do not edit by hand +% Generated by roxygen2 (4.1.1): do not edit by hand +% Please edit documentation in R/AdjustedSharpeRatio.R \name{AdjustedSharpeRatio} \alias{AdjustedSharpeRatio} \title{Adjusted Sharpe ratio of the return distribution} Modified: pkg/PerformanceAnalytics/man/AppraisalRatio.Rd =================================================================== --- pkg/PerformanceAnalytics/man/AppraisalRatio.Rd 2015-04-24 17:40:39 UTC (rev 3638) +++ pkg/PerformanceAnalytics/man/AppraisalRatio.Rd 2015-04-25 12:49:00 UTC (rev 3639) @@ -1,4 +1,5 @@ -% Generated by roxygen2 (4.0.2): do not edit by hand +% Generated by roxygen2 (4.1.1): do not edit by hand +% Please edit documentation in R/AppraisalRatio.R \name{AppraisalRatio} \alias{AppraisalRatio} \title{Appraisal ratio of the return distribution} Modified: pkg/PerformanceAnalytics/man/AverageDrawdown.Rd =================================================================== --- pkg/PerformanceAnalytics/man/AverageDrawdown.Rd 2015-04-24 17:40:39 UTC (rev 3638) +++ pkg/PerformanceAnalytics/man/AverageDrawdown.Rd 2015-04-25 12:49:00 UTC (rev 3639) @@ -1,4 +1,5 @@ -% Generated by roxygen2 (4.0.2): do not edit by hand +% Generated by roxygen2 (4.1.1): do not edit by hand +% Please edit documentation in R/maxDrawdown.R \name{AverageDrawdown} \alias{AverageDrawdown} \title{Calculates the average depth of the observed drawdowns.} Modified: pkg/PerformanceAnalytics/man/BernardoLedoitRatio.Rd =================================================================== --- pkg/PerformanceAnalytics/man/BernardoLedoitRatio.Rd 2015-04-24 17:40:39 UTC (rev 3638) +++ pkg/PerformanceAnalytics/man/BernardoLedoitRatio.Rd 2015-04-25 12:49:00 UTC (rev 3639) @@ -1,4 +1,5 @@ -% Generated by roxygen2 (4.0.2): do not edit by hand +% Generated by roxygen2 (4.1.1): do not edit by hand +% Please edit documentation in R/BernadoLedoitratio.R \name{BernardoLedoitRatio} \alias{BernardoLedoitRatio} \title{Bernardo and Ledoit ratio of the return distribution} Modified: pkg/PerformanceAnalytics/man/BetaCoMoments.Rd =================================================================== --- pkg/PerformanceAnalytics/man/BetaCoMoments.Rd 2015-04-24 17:40:39 UTC (rev 3638) +++ pkg/PerformanceAnalytics/man/BetaCoMoments.Rd 2015-04-25 12:49:00 UTC (rev 3639) @@ -1,4 +1,5 @@ -% Generated by roxygen2 (4.0.2): do not edit by hand +% Generated by roxygen2 (4.1.1): do not edit by hand +% Please edit documentation in R/CoMoments.R \name{BetaCoMoments} \alias{BetaCoKurtosis} \alias{BetaCoMoments} Modified: pkg/PerformanceAnalytics/man/BurkeRatio.Rd =================================================================== --- pkg/PerformanceAnalytics/man/BurkeRatio.Rd 2015-04-24 17:40:39 UTC (rev 3638) +++ pkg/PerformanceAnalytics/man/BurkeRatio.Rd 2015-04-25 12:49:00 UTC (rev 3639) @@ -1,4 +1,5 @@ -% Generated by roxygen2 (4.0.2): do not edit by hand +% Generated by roxygen2 (4.1.1): do not edit by hand +% Please edit documentation in R/BurkeRatio.R \name{BurkeRatio} \alias{BurkeRatio} \title{Burke ratio of the return distribution} Modified: pkg/PerformanceAnalytics/man/CAPM.RiskPremium.Rd =================================================================== --- pkg/PerformanceAnalytics/man/CAPM.RiskPremium.Rd 2015-04-24 17:40:39 UTC (rev 3638) +++ pkg/PerformanceAnalytics/man/CAPM.RiskPremium.Rd 2015-04-25 12:49:00 UTC (rev 3639) @@ -1,4 +1,5 @@ -% Generated by roxygen2 (4.0.2): do not edit by hand +% Generated by roxygen2 (4.1.1): do not edit by hand +% Please edit documentation in R/CAPM.utils.R \name{CAPM.CML.slope} \alias{CAPM.CML} \alias{CAPM.CML.slope} Modified: pkg/PerformanceAnalytics/man/CAPM.alpha.Rd =================================================================== --- pkg/PerformanceAnalytics/man/CAPM.alpha.Rd 2015-04-24 17:40:39 UTC (rev 3638) +++ pkg/PerformanceAnalytics/man/CAPM.alpha.Rd 2015-04-25 12:49:00 UTC (rev 3639) @@ -1,4 +1,5 @@ -% Generated by roxygen2 (4.0.2): do not edit by hand +% Generated by roxygen2 (4.1.1): do not edit by hand +% Please edit documentation in R/CAPM.alpha.R \name{CAPM.alpha} \alias{CAPM.alpha} \alias{SFM.alpha} Modified: pkg/PerformanceAnalytics/man/CAPM.beta.Rd =================================================================== --- pkg/PerformanceAnalytics/man/CAPM.beta.Rd 2015-04-24 17:40:39 UTC (rev 3638) +++ pkg/PerformanceAnalytics/man/CAPM.beta.Rd 2015-04-25 12:49:00 UTC (rev 3639) @@ -1,4 +1,5 @@ -% Generated by roxygen2 (4.0.2): do not edit by hand +% Generated by roxygen2 (4.1.1): do not edit by hand +% Please edit documentation in R/CAPM.beta.R \name{CAPM.beta} \alias{CAPM.beta} \alias{CAPM.beta.bear} Modified: pkg/PerformanceAnalytics/man/CAPM.dynamic.Rd =================================================================== --- pkg/PerformanceAnalytics/man/CAPM.dynamic.Rd 2015-04-24 17:40:39 UTC (rev 3638) +++ pkg/PerformanceAnalytics/man/CAPM.dynamic.Rd 2015-04-25 12:49:00 UTC (rev 3639) @@ -1,4 +1,5 @@ -% Generated by roxygen2 (4.0.2): do not edit by hand +% Generated by roxygen2 (4.1.1): do not edit by hand +% Please edit documentation in R/CAPM.dynamic.R \name{CAPM.dynamic} \alias{CAPM.dynamic} \alias{SFM.dynamic} Modified: pkg/PerformanceAnalytics/man/CAPM.epsilon.Rd =================================================================== --- pkg/PerformanceAnalytics/man/CAPM.epsilon.Rd 2015-04-24 17:40:39 UTC (rev 3638) +++ pkg/PerformanceAnalytics/man/CAPM.epsilon.Rd 2015-04-25 12:49:00 UTC (rev 3639) @@ -1,4 +1,5 @@ -% Generated by roxygen2 (4.0.2): do not edit by hand +% Generated by roxygen2 (4.1.1): do not edit by hand +% Please edit documentation in R/CAPM.epsilon.R \name{CAPM.epsilon} \alias{CAPM.epsilon} \alias{SFM.epsilon} Modified: pkg/PerformanceAnalytics/man/CAPM.jensenAlpha.Rd =================================================================== --- pkg/PerformanceAnalytics/man/CAPM.jensenAlpha.Rd 2015-04-24 17:40:39 UTC (rev 3638) +++ pkg/PerformanceAnalytics/man/CAPM.jensenAlpha.Rd 2015-04-25 12:49:00 UTC (rev 3639) @@ -1,4 +1,5 @@ -% Generated by roxygen2 (4.0.2): do not edit by hand +% Generated by roxygen2 (4.1.1): do not edit by hand +% Please edit documentation in R/CAPM.jensenAlpha.R \name{CAPM.jensenAlpha} \alias{CAPM.jensenAlpha} \alias{SFM.jensenAlpha} Modified: pkg/PerformanceAnalytics/man/CDD.Rd =================================================================== --- pkg/PerformanceAnalytics/man/CDD.Rd 2015-04-24 17:40:39 UTC (rev 3638) +++ pkg/PerformanceAnalytics/man/CDD.Rd 2015-04-25 12:49:00 UTC (rev 3639) @@ -1,4 +1,5 @@ -% Generated by roxygen2 (4.0.2): do not edit by hand +% Generated by roxygen2 (4.1.1): do not edit by hand +% Please edit documentation in R/maxDrawdown.R \name{CDD} \alias{CDD} \alias{CDaR} Modified: pkg/PerformanceAnalytics/man/CalmarRatio.Rd =================================================================== --- pkg/PerformanceAnalytics/man/CalmarRatio.Rd 2015-04-24 17:40:39 UTC (rev 3638) +++ pkg/PerformanceAnalytics/man/CalmarRatio.Rd 2015-04-25 12:49:00 UTC (rev 3639) @@ -1,4 +1,5 @@ -% Generated by roxygen2 (4.0.2): do not edit by hand +% Generated by roxygen2 (4.1.1): do not edit by hand +% Please edit documentation in R/CalmarRatio.R \name{CalmarRatio} \alias{CalmarRatio} \alias{SterlingRatio} Modified: pkg/PerformanceAnalytics/man/CoMoments.Rd =================================================================== --- pkg/PerformanceAnalytics/man/CoMoments.Rd 2015-04-24 17:40:39 UTC (rev 3638) +++ pkg/PerformanceAnalytics/man/CoMoments.Rd 2015-04-25 12:49:00 UTC (rev 3639) @@ -1,4 +1,5 @@ -% Generated by roxygen2 (4.0.2): do not edit by hand +% Generated by roxygen2 (4.1.1): do not edit by hand +% Please edit documentation in R/CoMoments.R, R/MultivariateMoments.R \name{CoMoments} \alias{CoKurtosis} \alias{CoKurtosisMatrix} Modified: pkg/PerformanceAnalytics/man/DRatio.Rd =================================================================== --- pkg/PerformanceAnalytics/man/DRatio.Rd 2015-04-24 17:40:39 UTC (rev 3638) +++ pkg/PerformanceAnalytics/man/DRatio.Rd 2015-04-25 12:49:00 UTC (rev 3639) @@ -1,4 +1,5 @@ -% Generated by roxygen2 (4.0.2): do not edit by hand +% Generated by roxygen2 (4.1.1): do not edit by hand +% Please edit documentation in R/DRatio.R \name{DRatio} \alias{DRatio} \title{d ratio of the return distribution} Modified: pkg/PerformanceAnalytics/man/DownsideDeviation.Rd =================================================================== --- pkg/PerformanceAnalytics/man/DownsideDeviation.Rd 2015-04-24 17:40:39 UTC (rev 3638) +++ pkg/PerformanceAnalytics/man/DownsideDeviation.Rd 2015-04-25 12:49:00 UTC (rev 3639) @@ -1,4 +1,5 @@ -% Generated by roxygen2 (4.0.2): do not edit by hand +% Generated by roxygen2 (4.1.1): do not edit by hand +% Please edit documentation in R/DownsideDeviation.R, R/SemiDeviation.R \name{DownsideDeviation} \alias{DownsideDeviation} \alias{DownsidePotential} Modified: pkg/PerformanceAnalytics/man/DownsideFrequency.Rd =================================================================== --- pkg/PerformanceAnalytics/man/DownsideFrequency.Rd 2015-04-24 17:40:39 UTC (rev 3638) +++ pkg/PerformanceAnalytics/man/DownsideFrequency.Rd 2015-04-25 12:49:00 UTC (rev 3639) @@ -1,4 +1,5 @@ -% Generated by roxygen2 (4.0.2): do not edit by hand +% Generated by roxygen2 (4.1.1): do not edit by hand +% Please edit documentation in R/DownsideFrequency.R \name{DownsideFrequency} \alias{DownsideFrequency} \title{downside frequency of the return distribution} Modified: pkg/PerformanceAnalytics/man/DrawdownDeviation.Rd =================================================================== --- pkg/PerformanceAnalytics/man/DrawdownDeviation.Rd 2015-04-24 17:40:39 UTC (rev 3638) +++ pkg/PerformanceAnalytics/man/DrawdownDeviation.Rd 2015-04-25 12:49:00 UTC (rev 3639) @@ -1,4 +1,5 @@ -% Generated by roxygen2 (4.0.2): do not edit by hand +% Generated by roxygen2 (4.1.1): do not edit by hand +% Please edit documentation in R/maxDrawdown.R \name{DrawdownDeviation} \alias{DrawdownDeviation} \title{Calculates a standard deviation-type statistic using individual drawdowns.} Modified: pkg/PerformanceAnalytics/man/DrawdownPeak.Rd =================================================================== --- pkg/PerformanceAnalytics/man/DrawdownPeak.Rd 2015-04-24 17:40:39 UTC (rev 3638) +++ pkg/PerformanceAnalytics/man/DrawdownPeak.Rd 2015-04-25 12:49:00 UTC (rev 3639) @@ -1,4 +1,5 @@ -% Generated by roxygen2 (4.0.2): do not edit by hand +% Generated by roxygen2 (4.1.1): do not edit by hand +% Please edit documentation in R/DrawdownPeak.R \name{DrawdownPeak} \alias{DrawdownPeak} \title{Drawdawn peak of the return distribution} @@ -16,5 +17,7 @@ } \author{ Matthieu Lestel + +### } Modified: pkg/PerformanceAnalytics/man/ES.Rd =================================================================== --- pkg/PerformanceAnalytics/man/ES.Rd 2015-04-24 17:40:39 UTC (rev 3638) +++ pkg/PerformanceAnalytics/man/ES.Rd 2015-04-25 12:49:00 UTC (rev 3639) @@ -1,4 +1,5 @@ -% Generated by roxygen2 (4.0.2): do not edit by hand +% Generated by roxygen2 (4.1.1): do not edit by hand +% Please edit documentation in R/ES.R \name{ETL} \alias{CVaR} \alias{ES} Modified: pkg/PerformanceAnalytics/man/FamaBeta.Rd =================================================================== --- pkg/PerformanceAnalytics/man/FamaBeta.Rd 2015-04-24 17:40:39 UTC (rev 3638) +++ pkg/PerformanceAnalytics/man/FamaBeta.Rd 2015-04-25 12:49:00 UTC (rev 3639) @@ -1,4 +1,5 @@ -% Generated by roxygen2 (4.0.2): do not edit by hand +% Generated by roxygen2 (4.1.1): do not edit by hand +% Please edit documentation in R/FamaBeta.R \name{FamaBeta} \alias{FamaBeta} \title{Fama beta of the return distribution} Modified: pkg/PerformanceAnalytics/man/Frequency.Rd =================================================================== --- pkg/PerformanceAnalytics/man/Frequency.Rd 2015-04-24 17:40:39 UTC (rev 3638) +++ pkg/PerformanceAnalytics/man/Frequency.Rd 2015-04-25 12:49:00 UTC (rev 3639) @@ -1,4 +1,5 @@ -% Generated by roxygen2 (4.0.2): do not edit by hand +% Generated by roxygen2 (4.1.1): do not edit by hand +% Please edit documentation in R/Frequency.R \name{Frequency} \alias{Frequency} \title{Frequency of the return distribution} Modified: pkg/PerformanceAnalytics/man/HurstIndex.Rd =================================================================== --- pkg/PerformanceAnalytics/man/HurstIndex.Rd 2015-04-24 17:40:39 UTC (rev 3638) +++ pkg/PerformanceAnalytics/man/HurstIndex.Rd 2015-04-25 12:49:00 UTC (rev 3639) @@ -1,4 +1,5 @@ -% Generated by roxygen2 (4.0.2): do not edit by hand +% Generated by roxygen2 (4.1.1): do not edit by hand +% Please edit documentation in R/HurstIndex.R \name{HurstIndex} \alias{HurstIndex} \title{calculate the Hurst Index Modified: pkg/PerformanceAnalytics/man/InformationRatio.Rd =================================================================== --- pkg/PerformanceAnalytics/man/InformationRatio.Rd 2015-04-24 17:40:39 UTC (rev 3638) +++ pkg/PerformanceAnalytics/man/InformationRatio.Rd 2015-04-25 12:49:00 UTC (rev 3639) @@ -1,4 +1,5 @@ -% Generated by roxygen2 (4.0.2): do not edit by hand +% Generated by roxygen2 (4.1.1): do not edit by hand +% Please edit documentation in R/InformationRatio.R \name{InformationRatio} \alias{InformationRatio} \title{InformationRatio = ActivePremium/TrackingError} Modified: pkg/PerformanceAnalytics/man/Kappa.Rd =================================================================== --- pkg/PerformanceAnalytics/man/Kappa.Rd 2015-04-24 17:40:39 UTC (rev 3638) +++ pkg/PerformanceAnalytics/man/Kappa.Rd 2015-04-25 12:49:00 UTC (rev 3639) @@ -1,4 +1,5 @@ -% Generated by roxygen2 (4.0.2): do not edit by hand +% Generated by roxygen2 (4.1.1): do not edit by hand +% Please edit documentation in R/Kappa.R \name{Kappa} \alias{Kappa} \title{Kappa of the return distribution} Modified: pkg/PerformanceAnalytics/man/KellyRatio.Rd =================================================================== --- pkg/PerformanceAnalytics/man/KellyRatio.Rd 2015-04-24 17:40:39 UTC (rev 3638) +++ pkg/PerformanceAnalytics/man/KellyRatio.Rd 2015-04-25 12:49:00 UTC (rev 3639) @@ -1,4 +1,5 @@ -% Generated by roxygen2 (4.0.2): do not edit by hand +% Generated by roxygen2 (4.1.1): do not edit by hand +% Please edit documentation in R/KellyRatio.R \name{KellyRatio} \alias{KellyRatio} \title{calculate Kelly criterion ratio (leverage or bet size) for a strategy} Modified: pkg/PerformanceAnalytics/man/M2Sortino.Rd =================================================================== --- pkg/PerformanceAnalytics/man/M2Sortino.Rd 2015-04-24 17:40:39 UTC (rev 3638) +++ pkg/PerformanceAnalytics/man/M2Sortino.Rd 2015-04-25 12:49:00 UTC (rev 3639) @@ -1,4 +1,5 @@ -% Generated by roxygen2 (4.0.2): do not edit by hand +% Generated by roxygen2 (4.1.1): do not edit by hand +% Please edit documentation in R/M2Sortino.R \name{M2Sortino} \alias{M2Sortino} \title{M squared for Sortino of the return distribution} Modified: pkg/PerformanceAnalytics/man/MSquared.Rd =================================================================== --- pkg/PerformanceAnalytics/man/MSquared.Rd 2015-04-24 17:40:39 UTC (rev 3638) +++ pkg/PerformanceAnalytics/man/MSquared.Rd 2015-04-25 12:49:00 UTC (rev 3639) @@ -1,4 +1,5 @@ -% Generated by roxygen2 (4.0.2): do not edit by hand +% Generated by roxygen2 (4.1.1): do not edit by hand +% Please edit documentation in R/MSquared.R \name{MSquared} \alias{MSquared} \title{M squared of the return distribution} Modified: pkg/PerformanceAnalytics/man/MSquaredExcess.Rd =================================================================== --- pkg/PerformanceAnalytics/man/MSquaredExcess.Rd 2015-04-24 17:40:39 UTC (rev 3638) +++ pkg/PerformanceAnalytics/man/MSquaredExcess.Rd 2015-04-25 12:49:00 UTC (rev 3639) @@ -1,4 +1,5 @@ -% Generated by roxygen2 (4.0.2): do not edit by hand +% Generated by roxygen2 (4.1.1): do not edit by hand +% Please edit documentation in R/MSquaredExcess.R \name{MSquaredExcess} \alias{MSquaredExcess} \title{M squared excess of the return distribution} Modified: pkg/PerformanceAnalytics/man/MarketTiming.Rd =================================================================== --- pkg/PerformanceAnalytics/man/MarketTiming.Rd 2015-04-24 17:40:39 UTC (rev 3638) +++ pkg/PerformanceAnalytics/man/MarketTiming.Rd 2015-04-25 12:49:00 UTC (rev 3639) @@ -1,4 +1,5 @@ -% Generated by roxygen2 (4.0.2): do not edit by hand +% Generated by roxygen2 (4.1.1): do not edit by hand +% Please edit documentation in R/MarketTiming.R \name{MarketTiming} \alias{MarketTiming} \title{Market timing models} Modified: pkg/PerformanceAnalytics/man/MartinRatio.Rd =================================================================== --- pkg/PerformanceAnalytics/man/MartinRatio.Rd 2015-04-24 17:40:39 UTC (rev 3638) +++ pkg/PerformanceAnalytics/man/MartinRatio.Rd 2015-04-25 12:49:00 UTC (rev 3639) @@ -1,4 +1,5 @@ -% Generated by roxygen2 (4.0.2): do not edit by hand +% Generated by roxygen2 (4.1.1): do not edit by hand +% Please edit documentation in R/MartinRatio.R \name{MartinRatio} \alias{MartinRatio} \title{Martin ratio of the return distribution} Modified: pkg/PerformanceAnalytics/man/MeanAbsoluteDeviation.Rd =================================================================== --- pkg/PerformanceAnalytics/man/MeanAbsoluteDeviation.Rd 2015-04-24 17:40:39 UTC (rev 3638) +++ pkg/PerformanceAnalytics/man/MeanAbsoluteDeviation.Rd 2015-04-25 12:49:00 UTC (rev 3639) @@ -1,4 +1,5 @@ -% Generated by roxygen2 (4.0.2): do not edit by hand +% Generated by roxygen2 (4.1.1): do not edit by hand +% Please edit documentation in R/MeanAbsoluteDeviation.R \name{MeanAbsoluteDeviation} \alias{MeanAbsoluteDeviation} \title{Mean absolute deviation of the return distribution} Modified: pkg/PerformanceAnalytics/man/Modigliani.Rd =================================================================== --- pkg/PerformanceAnalytics/man/Modigliani.Rd 2015-04-24 17:40:39 UTC (rev 3638) +++ pkg/PerformanceAnalytics/man/Modigliani.Rd 2015-04-25 12:49:00 UTC (rev 3639) @@ -1,4 +1,5 @@ -% Generated by roxygen2 (4.0.2): do not edit by hand +% Generated by roxygen2 (4.1.1): do not edit by hand +% Please edit documentation in R/Modigliani.R \name{Modigliani} \alias{Modigliani} \title{Modigliani-Modigliani measure} Modified: pkg/PerformanceAnalytics/man/NetSelectivity.Rd =================================================================== --- pkg/PerformanceAnalytics/man/NetSelectivity.Rd 2015-04-24 17:40:39 UTC (rev 3638) +++ pkg/PerformanceAnalytics/man/NetSelectivity.Rd 2015-04-25 12:49:00 UTC (rev 3639) @@ -1,4 +1,5 @@ -% Generated by roxygen2 (4.0.2): do not edit by hand +% Generated by roxygen2 (4.1.1): do not edit by hand +% Please edit documentation in R/NetSelectivity.R \name{NetSelectivity} \alias{NetSelectivity} \title{Net selectivity of the return distribution} Modified: pkg/PerformanceAnalytics/man/Omega.Rd =================================================================== --- pkg/PerformanceAnalytics/man/Omega.Rd 2015-04-24 17:40:39 UTC (rev 3638) +++ pkg/PerformanceAnalytics/man/Omega.Rd 2015-04-25 12:49:00 UTC (rev 3639) @@ -1,4 +1,5 @@ -% Generated by roxygen2 (4.0.2): do not edit by hand +% Generated by roxygen2 (4.1.1): do not edit by hand +% Please edit documentation in R/Omega.R \name{Omega} \alias{Omega} \title{calculate Omega for a return series} Modified: pkg/PerformanceAnalytics/man/OmegaExcessReturn.Rd =================================================================== --- pkg/PerformanceAnalytics/man/OmegaExcessReturn.Rd 2015-04-24 17:40:39 UTC (rev 3638) +++ pkg/PerformanceAnalytics/man/OmegaExcessReturn.Rd 2015-04-25 12:49:00 UTC (rev 3639) @@ -1,4 +1,5 @@ -% Generated by roxygen2 (4.0.2): do not edit by hand +% Generated by roxygen2 (4.1.1): do not edit by hand +% Please edit documentation in R/OmegaExcessReturn.R \name{OmegaExcessReturn} \alias{OmegaExcessReturn} \alias{OmegaExessReturn} Modified: pkg/PerformanceAnalytics/man/OmegaSharpeRatio.Rd =================================================================== --- pkg/PerformanceAnalytics/man/OmegaSharpeRatio.Rd 2015-04-24 17:40:39 UTC (rev 3638) +++ pkg/PerformanceAnalytics/man/OmegaSharpeRatio.Rd 2015-04-25 12:49:00 UTC (rev 3639) @@ -1,4 +1,5 @@ -% Generated by roxygen2 (4.0.2): do not edit by hand +% Generated by roxygen2 (4.1.1): do not edit by hand +% Please edit documentation in R/OmegaSharpeRatio.R \name{OmegaSharpeRatio} \alias{OmegaSharpeRatio} \title{Omega-Sharpe ratio of the return distribution} Modified: pkg/PerformanceAnalytics/man/PainIndex.Rd =================================================================== --- pkg/PerformanceAnalytics/man/PainIndex.Rd 2015-04-24 17:40:39 UTC (rev 3638) +++ pkg/PerformanceAnalytics/man/PainIndex.Rd 2015-04-25 12:49:00 UTC (rev 3639) @@ -1,4 +1,5 @@ -% Generated by roxygen2 (4.0.2): do not edit by hand +% Generated by roxygen2 (4.1.1): do not edit by hand +% Please edit documentation in R/PainIndex.R \name{PainIndex} \alias{PainIndex} \title{Pain index of the return distribution} Modified: pkg/PerformanceAnalytics/man/PainRatio.Rd =================================================================== --- pkg/PerformanceAnalytics/man/PainRatio.Rd 2015-04-24 17:40:39 UTC (rev 3638) +++ pkg/PerformanceAnalytics/man/PainRatio.Rd 2015-04-25 12:49:00 UTC (rev 3639) @@ -1,4 +1,5 @@ -% Generated by roxygen2 (4.0.2): do not edit by hand +% Generated by roxygen2 (4.1.1): do not edit by hand +% Please edit documentation in R/PainRatio.R \name{PainRatio} \alias{PainRatio} \title{Pain ratio of the return distribution} Modified: pkg/PerformanceAnalytics/man/ProspectRatio.Rd =================================================================== --- pkg/PerformanceAnalytics/man/ProspectRatio.Rd 2015-04-24 17:40:39 UTC (rev 3638) +++ pkg/PerformanceAnalytics/man/ProspectRatio.Rd 2015-04-25 12:49:00 UTC (rev 3639) @@ -1,4 +1,5 @@ -% Generated by roxygen2 (4.0.2): do not edit by hand +% Generated by roxygen2 (4.1.1): do not edit by hand +% Please edit documentation in R/ProspectRatio.R \name{ProspectRatio} \alias{ProspectRatio} \title{Prospect ratio of the return distribution} Modified: pkg/PerformanceAnalytics/man/Return.Geltner.Rd =================================================================== --- pkg/PerformanceAnalytics/man/Return.Geltner.Rd 2015-04-24 17:40:39 UTC (rev 3638) +++ pkg/PerformanceAnalytics/man/Return.Geltner.Rd 2015-04-25 12:49:00 UTC (rev 3639) @@ -1,4 +1,5 @@ -% Generated by roxygen2 (4.0.2): do not edit by hand +% Generated by roxygen2 (4.1.1): do not edit by hand +% Please edit documentation in R/Return.Geltner.R \name{Return.Geltner} \alias{Return.Geltner} \title{calculate Geltner liquidity-adjusted return series} Modified: pkg/PerformanceAnalytics/man/Return.annualized.Rd =================================================================== --- pkg/PerformanceAnalytics/man/Return.annualized.Rd 2015-04-24 17:40:39 UTC (rev 3638) +++ pkg/PerformanceAnalytics/man/Return.annualized.Rd 2015-04-25 12:49:00 UTC (rev 3639) @@ -1,4 +1,5 @@ -% Generated by roxygen2 (4.0.2): do not edit by hand +% Generated by roxygen2 (4.1.1): do not edit by hand +% Please edit documentation in R/Return.annualized.R \name{Return.annualized} \alias{Return.annualized} \title{calculate an annualized return for comparing instruments with different Modified: pkg/PerformanceAnalytics/man/Return.annualized.excess.Rd =================================================================== --- pkg/PerformanceAnalytics/man/Return.annualized.excess.Rd 2015-04-24 17:40:39 UTC (rev 3638) +++ pkg/PerformanceAnalytics/man/Return.annualized.excess.Rd 2015-04-25 12:49:00 UTC (rev 3639) @@ -1,4 +1,5 @@ -% Generated by roxygen2 (4.0.2): do not edit by hand +% Generated by roxygen2 (4.1.1): do not edit by hand +% Please edit documentation in R/Return.annualized.excess.R \name{Return.annualized.excess} \alias{Return.annualized.excess} \title{calculates an annualized excess return for comparing instruments with different Modified: pkg/PerformanceAnalytics/man/Return.calculate.Rd =================================================================== --- pkg/PerformanceAnalytics/man/Return.calculate.Rd 2015-04-24 17:40:39 UTC (rev 3638) +++ pkg/PerformanceAnalytics/man/Return.calculate.Rd 2015-04-25 12:49:00 UTC (rev 3639) @@ -1,4 +1,5 @@ -% Generated by roxygen2 (4.0.2): do not edit by hand +% Generated by roxygen2 (4.1.1): do not edit by hand +% Please edit documentation in R/Return.calculate.R \name{Return.calculate} \alias{CalculateReturns} \alias{Return.calculate} Modified: pkg/PerformanceAnalytics/man/Return.clean.Rd =================================================================== --- pkg/PerformanceAnalytics/man/Return.clean.Rd 2015-04-24 17:40:39 UTC (rev 3638) +++ pkg/PerformanceAnalytics/man/Return.clean.Rd 2015-04-25 12:49:00 UTC (rev 3639) @@ -1,4 +1,5 @@ -% Generated by roxygen2 (4.0.2): do not edit by hand +% Generated by roxygen2 (4.1.1): do not edit by hand +% Please edit documentation in R/Return.clean.R \name{Return.clean} \alias{Return.clean} \title{clean returns in a time series to to provide more robust risk estimates} Modified: pkg/PerformanceAnalytics/man/Return.cumulative.Rd =================================================================== --- pkg/PerformanceAnalytics/man/Return.cumulative.Rd 2015-04-24 17:40:39 UTC (rev 3638) +++ pkg/PerformanceAnalytics/man/Return.cumulative.Rd 2015-04-25 12:49:00 UTC (rev 3639) @@ -1,4 +1,5 @@ -% Generated by roxygen2 (4.0.2): do not edit by hand +% Generated by roxygen2 (4.1.1): do not edit by hand +% Please edit documentation in R/Return.cumulative.R \name{Return.cumulative} \alias{Return.cumulative} \title{calculate a compounded (geometric) cumulative return} Modified: pkg/PerformanceAnalytics/man/Return.excess.Rd =================================================================== --- pkg/PerformanceAnalytics/man/Return.excess.Rd 2015-04-24 17:40:39 UTC (rev 3638) +++ pkg/PerformanceAnalytics/man/Return.excess.Rd 2015-04-25 12:49:00 UTC (rev 3639) @@ -1,4 +1,5 @@ -% Generated by roxygen2 (4.0.2): do not edit by hand +% Generated by roxygen2 (4.1.1): do not edit by hand +% Please edit documentation in R/Return.excess.R \name{Return.excess} \alias{Return.excess} \title{Calculates the returns of an asset in excess of the given risk free rate} Modified: pkg/PerformanceAnalytics/man/Return.portfolio.Rd =================================================================== --- pkg/PerformanceAnalytics/man/Return.portfolio.Rd 2015-04-24 17:40:39 UTC (rev 3638) +++ pkg/PerformanceAnalytics/man/Return.portfolio.Rd 2015-04-25 12:49:00 UTC (rev 3639) @@ -1,4 +1,5 @@ -% Generated by roxygen2 (4.0.2): do not edit by hand +% Generated by roxygen2 (4.1.1): do not edit by hand +% Please edit documentation in R/Return.portfolio.R \name{Return.portfolio} \alias{Return.portfolio} \alias{Return.rebalancing} Modified: pkg/PerformanceAnalytics/man/Return.read.Rd =================================================================== --- pkg/PerformanceAnalytics/man/Return.read.Rd 2015-04-24 17:40:39 UTC (rev 3638) +++ pkg/PerformanceAnalytics/man/Return.read.Rd 2015-04-25 12:49:00 UTC (rev 3639) @@ -1,4 +1,5 @@ -% Generated by roxygen2 (4.0.2): do not edit by hand +% Generated by roxygen2 (4.1.1): do not edit by hand +% Please edit documentation in R/Return.read.R \name{Return.read} \alias{Return.read} \title{Read returns data with different date formats} Modified: pkg/PerformanceAnalytics/man/Return.relative.Rd =================================================================== --- pkg/PerformanceAnalytics/man/Return.relative.Rd 2015-04-24 17:40:39 UTC (rev 3638) +++ pkg/PerformanceAnalytics/man/Return.relative.Rd 2015-04-25 12:49:00 UTC (rev 3639) @@ -1,4 +1,5 @@ -% Generated by roxygen2 (4.0.2): do not edit by hand +% Generated by roxygen2 (4.1.1): do not edit by hand +% Please edit documentation in R/Return.relative.R \name{Return.relative} \alias{Return.relative} \title{calculate the relative return of one asset to another} Modified: pkg/PerformanceAnalytics/man/Selectivity.Rd =================================================================== --- pkg/PerformanceAnalytics/man/Selectivity.Rd 2015-04-24 17:40:39 UTC (rev 3638) +++ pkg/PerformanceAnalytics/man/Selectivity.Rd 2015-04-25 12:49:00 UTC (rev 3639) @@ -1,4 +1,5 @@ -% Generated by roxygen2 (4.0.2): do not edit by hand +% Generated by roxygen2 (4.1.1): do not edit by hand +% Please edit documentation in R/Selectivity.R \name{Selectivity} \alias{Selectivity} [TRUNCATED] To get the complete diff run: svnlook diff /svnroot/returnanalytics -r 3639 From noreply at r-forge.r-project.org Sat Apr 25 15:08:18 2015 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Sat, 25 Apr 2015 15:08:18 +0200 (CEST) Subject: [Returnanalytics-commits] r3640 - in pkg/PerformanceAnalytics: . R man Message-ID: <20150425130818.A16D418790E@r-forge.r-project.org> Author: braverock Date: 2015-04-25 15:08:18 +0200 (Sat, 25 Apr 2015) New Revision: 3640 Added: pkg/PerformanceAnalytics/man/AverageLength.Rd pkg/PerformanceAnalytics/man/AverageRecovery.Rd Modified: pkg/PerformanceAnalytics/DESCRIPTION pkg/PerformanceAnalytics/NAMESPACE pkg/PerformanceAnalytics/R/PortfolioRisk.R pkg/PerformanceAnalytics/R/chart.TimeSeries.R pkg/PerformanceAnalytics/R/chart.TimeSeries.base.R pkg/PerformanceAnalytics/man/chart.TimeSeries.Rd Log: - update chart.TimeSeries documentation, - un-export internal fn chart.TimeSeries.base - add Rd files for AverageDrawdown and AverageRecovery, since they are marked for export - bump version Modified: pkg/PerformanceAnalytics/DESCRIPTION =================================================================== --- pkg/PerformanceAnalytics/DESCRIPTION 2015-04-25 12:49:00 UTC (rev 3639) +++ pkg/PerformanceAnalytics/DESCRIPTION 2015-04-25 13:08:18 UTC (rev 3640) @@ -12,7 +12,7 @@ , person(given="Kyle",family="Balkissoon",role="ctb") , person(given="Diethelm",family="Wuertz",role="ctb") ) -Version: 1.4.3639 +Version: 1.4.3640 Date: $Date$ Description: Collection of econometric functions for performance and risk analysis. This package aims to aid Modified: pkg/PerformanceAnalytics/NAMESPACE =================================================================== --- pkg/PerformanceAnalytics/NAMESPACE 2015-04-25 12:49:00 UTC (rev 3639) +++ pkg/PerformanceAnalytics/NAMESPACE 2015-04-25 13:08:18 UTC (rev 3640) @@ -145,7 +145,6 @@ export(chart.SnailTrail) export(chart.StackedBar) export(chart.TimeSeries) -export(chart.TimeSeries.base) export(chart.VaRSensitivity) export(charts.Bar) export(charts.BarVaR) Modified: pkg/PerformanceAnalytics/R/PortfolioRisk.R =================================================================== --- pkg/PerformanceAnalytics/R/PortfolioRisk.R 2015-04-25 12:49:00 UTC (rev 3639) +++ pkg/PerformanceAnalytics/R/PortfolioRisk.R 2015-04-25 13:08:18 UTC (rev 3640) @@ -1,7 +1,7 @@ ############################################################################### -# Functions to peRform component risk calculations on portfolios of assets. +# Functions to perform component risk calculations on portfolios of assets. # -# Copyright (c) 2007-2009 Kris Boudt and Brian G. Peterson +# Copyright (c) 2007-2015 Kris Boudt 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 ############################################################################### Modified: pkg/PerformanceAnalytics/R/chart.TimeSeries.R =================================================================== --- pkg/PerformanceAnalytics/R/chart.TimeSeries.R 2015-04-25 12:49:00 UTC (rev 3639) +++ pkg/PerformanceAnalytics/R/chart.TimeSeries.R 2015-04-25 13:08:18 UTC (rev 3640) @@ -1,323 +1,324 @@ -#' Creates a time series chart with some extensions. -#' -#' Draws a line chart and labels the x-axis with the appropriate dates. This -#' is really a "primitive", since it extends the base \code{\link{plot}} and -#' standardizes the elements of a chart. Adds attributes for shading areas of -#' the timeline or aligning vertical lines along the timeline. This function is -#' intended to be used inside other charting functions. -#' -#' -#' @param R an xts, vector, matrix, data frame, timeSeries or zoo object of -#' asset returns -#' @param auto.grid if true, draws a grid aligned with the points on the x and -#' y axes -#' @param grid.color sets the color for the reference grid -#' @param grid.lty defines the line type for the grid -#' @param xaxis if true, draws the x axis -#' @param yaxis if true, draws the y axis -#' @param yaxis.right if true, draws the y axis on the right-hand side of the -#' plot -#' @param type set the chart type, same as in \code{\link{plot}} -#' @param lty set the line type, same as in \code{\link{plot}} -#' @param lwd set the line width, same as in \code{\link{plot}} -#' @param las set the axis label rotation, same as in \code{\link{plot}} -#' @param main set the chart title, same as in \code{\link{plot}} -#' @param ylab set the y-axis label, same as in \code{\link{plot}} -#' @param xlab set the x-axis label, same as in \code{\link{plot}} -#' @param date.format re-format the dates for the xaxis; the default is "\%m/\%y" -#' @param xlim set the x-axis limit, same as in \code{\link{plot}} -#' @param ylim set the y-axis limit, same as in \code{\link{plot}} -#' @param event.lines If not null, vertical lines will be drawn to indicate -#' that an event happened during that time period. \code{event.lines} should -#' be a list of dates (e.g., \code{c("09/03","05/06"))} formatted the same as -#' date.format. This function matches the re-formatted row names (dates) with -#' the events.list, so to get a match the formatting needs to be correct. -#' @param event.labels if not null and event.lines is not null, this will apply -#' a list of text labels (e.g., \code{c("This Event", "That Event")} to the -#' vertical lines drawn. See the example below. -#' @param period.areas these are shaded areas described by start and end dates -#' in a vector of xts date rangees, e.g., -#' \code{c("1926-10::1927-11","1929-08::1933-03")} See the examples below. -#' @param event.color draws the event described in \code{event.labels} in the -#' color specified -#' @param period.color draws the shaded region described by \code{period.areas} -#' in the color specified -#' @param colorset color palette to use, set by default to rational choices -#' @param pch symbols to use, see also \code{\link{plot}} -#' @param element.color provides the color for drawing chart elements, such as -#' the box lines, axis lines, etc. Default is "darkgray" -#' @param legend.loc places a legend into one of nine locations on the chart: -#' bottomright, bottom, bottomleft, left, topleft, top, topright, right, or -#' center. -#' @param ylog TRUE/FALSE set the y-axis to logarithmic scale, similar to -#' \code{\link{plot}}, default FALSE -#' @param date.format.in allows specification of other date formats in the data -#' object, defaults to "\%Y-\%m-\%d" -#' @param cex.axis The magnification to be used for axis annotation relative to -#' the current setting of 'cex', same as in \code{\link{plot}}. -#' @param cex.legend The magnification to be used for sizing the legend -#' relative to the current setting of 'cex'. -#' @param cex.labels The magnification to be used for event line labels -#' relative to the current setting of 'cex'. -#' @param cex.lab The magnification to be used for x- and y-axis labels -#' relative to the current setting of 'cex'. -#' @param cex.main The magnification to be used for the chart title relative to -#' the current setting of 'cex'. -#' @param major.ticks Should major tickmarks be drawn and labeled, default -#' 'auto' -#' @param minor.ticks Should minor tickmarks be drawn, default TRUE -#' @param xaxis.labels Allows for non-date labeling of date axes, default is -#' NULL -#' @param space default 0 -#' @param dygraphPlot Plot using dygraphs default FALSE -#' @param \dots any other passthru parameters -#' @author Peter Carl -#' @seealso \code{\link{plot}}, \code{\link{par}}, -#' \code{\link[xts]{axTicksByTime}} -###keywords ts multivariate distribution models hplot -#' @examples -#' -#' -#' # These are start and end dates, formatted as xts ranges. -#' ## http://www.nber.org-cycles.html -#' cycles.dates<-c("1857-06/1858-12", -#' "1860-10/1861-06", -#' "1865-04/1867-12", -#' "1869-06/1870-12", -#' "1873-10/1879-03", -#' "1882-03/1885-05", -#' "1887-03/1888-04", -#' "1890-07/1891-05", -#' "1893-01/1894-06", -#' "1895-12/1897-06", -#' "1899-06/1900-12", -#' "1902-09/1904-08", -#' "1907-05/1908-06", -#' "1910-01/1912-01", -#' "1913-01/1914-12", -#' "1918-08/1919-03", -#' "1920-01/1921-07", -#' "1923-05/1924-07", -#' "1926-10/1927-11", -#' "1929-08/1933-03", -#' "1937-05/1938-06", -#' "1945-02/1945-10", -#' "1948-11/1949-10", -#' "1953-07/1954-05", -#' "1957-08/1958-04", -#' "1960-04/1961-02", -#' "1969-12/1970-11", -#' "1973-11/1975-03", -#' "1980-01/1980-07", -#' "1981-07/1982-11", -#' "1990-07/1991-03", -#' "2001-03/2001-11", -#' "2007-12/2009-06" -#' ) -#' # Event lists - FOR BEST RESULTS, KEEP THESE DATES IN ORDER -#' risk.dates = c( -#' "Oct 87", -#' "Feb 94", -#' "Jul 97", -#' "Aug 98", -#' "Oct 98", -#' "Jul 00", -#' "Sep 01") -#' risk.labels = c( -#' "Black Monday", -#' "Bond Crash", -#' "Asian Crisis", -#' "Russian Crisis", -#' "LTCM", -#' "Tech Bubble", -#' "Sept 11") -#' data(edhec) -#' -#' R=edhec[,"Funds of Funds",drop=FALSE] -#' Return.cumulative = cumprod(1+R) - 1 -#' chart.TimeSeries(Return.cumulative) -#' chart.TimeSeries(Return.cumulative, colorset = "darkblue", -#' legend.loc = "bottomright", -#' period.areas = cycles.dates, -#' period.color = "lightblue", -#' event.lines = risk.dates, -#' event.labels = risk.labels, -#' event.color = "red", lwd = 2) -#' -#' @export -chart.TimeSeries <- -function (R, - auto.grid=TRUE, - xaxis = TRUE, - yaxis = TRUE, - yaxis.right = FALSE, - type = "l", - lty = 1, - lwd = 2, - las = par("las"), - main = NULL, - ylab=NULL, - xlab="", - date.format.in="%Y-%m-%d", - date.format = NULL, - xlim = NULL, - ylim = NULL, - element.color="darkgray", - event.lines = NULL, - event.labels = NULL, - period.areas = NULL, - event.color = "darkgray", - period.color = "aliceblue", colorset = (1:12), - pch = (1:12), - legend.loc = NULL, - ylog = FALSE, - cex.axis=0.8, - cex.legend = 0.8, - cex.lab = 1, - cex.labels = 0.8, - cex.main = 1, - major.ticks='auto', - minor.ticks=TRUE, - grid.color="lightgray", - grid.lty="dotted", - xaxis.labels = NULL, - dygraphPlot=FALSE,...) -{ # @author Peter Carl, Brian Peterson - - # DESCRIPTION: - # Draws a line chart and labels the x-axis with the appropriate dates. - # This is really a "primitive", since it constructs the elements of a plot - # to provide lines for each column of data provided. - - # Inputs: - # R = assumes that data is a regular time series, not irregular. Can take - # any type of object, whether a matrix, data frame, or timeSeries. - # date.format: allows passing of a date format for the xaxis - # legend.loc = use this to locate the legend, e.g., "topright" - # colorset = use the name of any of the palattes above - # reference.grid = if true, draws a grid aligned with the points on the - # x and y axes. - # xaxis = if true, draws the x axis. - # event.lines = if not null, will draw vertical lines indicating that an - # event happened during that time period. event.lines should be a list - # of dates (e.g., c("09/03","05/06")) formatted the same as date.format. - # This function matches the re-formatted row names (dates) with the - # events.list, so to get a match the formatting needs to be correct. - # event.labels = if not null and event.lines is not null, this will apply - # labels to the vertical lines drawn. - - # All other inputs are the same as "plot" and are principally included - # so that some sensible defaults could be set. - - # Output: - # Draws a timeseries graph of type "line" with some sensible defaults. - - # FUNCTION: - - y = checkData(R) - - # Set up dimensions and labels - columns = ncol(y) - rows = nrow(y) - columnnames = colnames(y) - - if (is.null(date.format)){ - freq = periodicity(y) - yr_eq <- ifelse(format(index(first(y)),format="%Y")==format(index(last(y)),format="%Y"),TRUE,FALSE) - switch(freq$scale, - seconds = { date.format = "%H:%M"}, - minute = { date.format = "%H:%M"}, - hourly = {date.format = "%d %H"}, - daily = {if (yr_eq) date.format = "%b %d" else date.format = "%Y-%m-%d"}, - weekly = {if (yr_eq) date.format = "%b %d" else date.format = "%Y-%m-%d"}, - monthly = {if (yr_eq) date.format = "%b" else date.format = "%b %y"}, - quarterly = {if (yr_eq) date.format = "%b" else date.format = "%b %y"}, - yearly = {date.format = "%Y"} - ) - } - # Needed for finding aligned dates for event lines and period areas - rownames = as.Date(time(y)) - rownames = format(strptime(rownames,format = date.format.in), date.format) - - time.scale = periodicity(y)$scale - ep = axTicksByTime(y,major.ticks, format.labels = date.format) - - # If the Y-axis is ln - logaxis = "" - if(ylog) { - logaxis = "y" - } - - - if(dygraphPlot==FALSE){ - chart.TimeSeries.base(R, - auto.grid, - xaxis, - yaxis, - yaxis.right, - type, - lty, - lwd , - las , - main , - ylab, - xlab, - date.format.in, - date.format , - xlim , - ylim , - element.color, - event.lines, - event.labels, - period.areas, - event.color , - period.color , colorset , - pch, - legend.loc , - ylog , - cex.axis, - cex.legend , - cex.lab , - cex.labels, - cex.main , - major.ticks, - minor.ticks, - grid.color, - grid.lty, - xaxis.labels,...) - - - - - }else{ - if(is.null(main)) - main=columnnames[1] - - if(is.null(ylab)) { - if(ylog) - ylab = "ln(Value)" - - else - ylab = "Value" - } - - ##@TODO Get all the graphical parameters integrated with these two - dyRangeSelector(dygraph(y,main = main, - xlab = xlab, - ylab = ylab)) - - } - -} - -############################################################################### -# R (http://r-project.org/) Econometrics for Performance and Risk Analysis -# -# Copyright (c) 2004-2015 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$ -# -############################################################################### +#' Creates a time series chart with some extensions. +#' +#' Draws a line chart and labels the x-axis with the appropriate dates. This +#' is really a "primitive", since it extends the base \code{\link{plot}} and +#' standardizes the elements of a chart. Adds attributes for shading areas of +#' the timeline or aligning vertical lines along the timeline. This function is +#' intended to be used inside other charting functions. +#' +#' +#' @param R an xts, vector, matrix, data frame, timeSeries or zoo object of +#' asset returns +#' @param auto.grid if true, draws a grid aligned with the points on the x and +#' y axes +#' @param grid.color sets the color for the reference grid +#' @param grid.lty defines the line type for the grid +#' @param xaxis if true, draws the x axis +#' @param yaxis if true, draws the y axis +#' @param yaxis.right if true, draws the y axis on the right-hand side of the +#' plot +#' @param type set the chart type, same as in \code{\link{plot}} +#' @param lty set the line type, same as in \code{\link{plot}} +#' @param lwd set the line width, same as in \code{\link{plot}} +#' @param las set the axis label rotation, same as in \code{\link{plot}} +#' @param main set the chart title, same as in \code{\link{plot}} +#' @param ylab set the y-axis label, same as in \code{\link{plot}} +#' @param xlab set the x-axis label, same as in \code{\link{plot}} +#' @param date.format re-format the dates for the xaxis; the default is "\%m/\%y" +#' @param xlim set the x-axis limit, same as in \code{\link{plot}} +#' @param ylim set the y-axis limit, same as in \code{\link{plot}} +#' @param event.lines If not null, vertical lines will be drawn to indicate +#' that an event happened during that time period. \code{event.lines} should +#' be a list of dates (e.g., \code{c("09/03","05/06"))} formatted the same as +#' date.format. This function matches the re-formatted row names (dates) with +#' the events.list, so to get a match the formatting needs to be correct. +#' @param event.labels if not null and event.lines is not null, this will apply +#' a list of text labels (e.g., \code{c("This Event", "That Event")} to the +#' vertical lines drawn. See the example below. +#' @param period.areas these are shaded areas described by start and end dates +#' in a vector of xts date rangees, e.g., +#' \code{c("1926-10::1927-11","1929-08::1933-03")} See the examples below. +#' @param event.color draws the event described in \code{event.labels} in the +#' color specified +#' @param period.color draws the shaded region described by \code{period.areas} +#' in the color specified +#' @param colorset color palette to use, set by default to rational choices +#' @param pch symbols to use, see also \code{\link{plot}} +#' @param element.color provides the color for drawing chart elements, such as +#' the box lines, axis lines, etc. Default is "darkgray" +#' @param legend.loc places a legend into one of nine locations on the chart: +#' bottomright, bottom, bottomleft, left, topleft, top, topright, right, or +#' center. +#' @param ylog TRUE/FALSE set the y-axis to logarithmic scale, similar to +#' \code{\link{plot}}, default FALSE +#' @param date.format.in allows specification of other date formats in the data +#' object, defaults to "\%Y-\%m-\%d" +#' @param cex.axis The magnification to be used for axis annotation relative to +#' the current setting of 'cex', same as in \code{\link{plot}}. +#' @param cex.legend The magnification to be used for sizing the legend +#' relative to the current setting of 'cex'. +#' @param cex.labels The magnification to be used for event line labels +#' relative to the current setting of 'cex'. +#' @param cex.lab The magnification to be used for x- and y-axis labels +#' relative to the current setting of 'cex'. +#' @param cex.main The magnification to be used for the chart title relative to +#' the current setting of 'cex'. +#' @param major.ticks Should major tickmarks be drawn and labeled, default +#' 'auto' +#' @param minor.ticks Should minor tickmarks be drawn, default TRUE +#' @param xaxis.labels Allows for non-date labeling of date axes, default is +#' NULL +#' @param space default 0 +#' @param dygraphPlot Plot using dygraphs default FALSE +#' @param \dots any other passthru parameters +#' @author Peter Carl +#' @seealso \code{\link{plot}}, \code{\link{par}}, +#' \code{\link[xts]{axTicksByTime}} +###keywords ts multivariate distribution models hplot +#' @examples +#' +#' +#' # These are start and end dates, formatted as xts ranges. +#' ## http://www.nber.org-cycles.html +#' cycles.dates<-c("1857-06/1858-12", +#' "1860-10/1861-06", +#' "1865-04/1867-12", +#' "1869-06/1870-12", +#' "1873-10/1879-03", +#' "1882-03/1885-05", +#' "1887-03/1888-04", +#' "1890-07/1891-05", +#' "1893-01/1894-06", +#' "1895-12/1897-06", +#' "1899-06/1900-12", +#' "1902-09/1904-08", +#' "1907-05/1908-06", +#' "1910-01/1912-01", +#' "1913-01/1914-12", +#' "1918-08/1919-03", +#' "1920-01/1921-07", +#' "1923-05/1924-07", +#' "1926-10/1927-11", +#' "1929-08/1933-03", +#' "1937-05/1938-06", +#' "1945-02/1945-10", +#' "1948-11/1949-10", +#' "1953-07/1954-05", +#' "1957-08/1958-04", +#' "1960-04/1961-02", +#' "1969-12/1970-11", +#' "1973-11/1975-03", +#' "1980-01/1980-07", +#' "1981-07/1982-11", +#' "1990-07/1991-03", +#' "2001-03/2001-11", +#' "2007-12/2009-06" +#' ) +#' # Event lists - FOR BEST RESULTS, KEEP THESE DATES IN ORDER +#' risk.dates = c( +#' "Oct 87", +#' "Feb 94", +#' "Jul 97", +#' "Aug 98", +#' "Oct 98", +#' "Jul 00", +#' "Sep 01") +#' risk.labels = c( +#' "Black Monday", +#' "Bond Crash", +#' "Asian Crisis", +#' "Russian Crisis", +#' "LTCM", +#' "Tech Bubble", +#' "Sept 11") +#' data(edhec) +#' +#' R=edhec[,"Funds of Funds",drop=FALSE] +#' Return.cumulative = cumprod(1+R) - 1 +#' chart.TimeSeries(Return.cumulative) +#' chart.TimeSeries(Return.cumulative, colorset = "darkblue", +#' legend.loc = "bottomright", +#' period.areas = cycles.dates, +#' period.color = "lightblue", +#' event.lines = risk.dates, +#' event.labels = risk.labels, +#' event.color = "red", lwd = 2) +#' +#' @export +chart.TimeSeries <- +function (R, + ... , + auto.grid=TRUE, + xaxis = TRUE, + yaxis = TRUE, + yaxis.right = FALSE, + type = "l", + lty = 1, + lwd = 2, + las = par("las"), + main = NULL, + ylab=NULL, + xlab="", + date.format.in="%Y-%m-%d", + date.format = NULL, + xlim = NULL, + ylim = NULL, + element.color="darkgray", + event.lines = NULL, + event.labels = NULL, + period.areas = NULL, + event.color = "darkgray", + period.color = "aliceblue", colorset = (1:12), + pch = (1:12), + legend.loc = NULL, + ylog = FALSE, + cex.axis=0.8, + cex.legend = 0.8, + cex.lab = 1, + cex.labels = 0.8, + cex.main = 1, + major.ticks='auto', + minor.ticks=TRUE, + grid.color="lightgray", + grid.lty="dotted", + xaxis.labels = NULL, + dygraphPlot=FALSE) +{ # @author Peter Carl, Brian Peterson + + # DESCRIPTION: + # Draws a line chart and labels the x-axis with the appropriate dates. + # This is really a "primitive", since it constructs the elements of a plot + # to provide lines for each column of data provided. + + # Inputs: + # R = assumes that data is a regular time series, not irregular. Can take + # any type of object, whether a matrix, data frame, or timeSeries. + # date.format: allows passing of a date format for the xaxis + # legend.loc = use this to locate the legend, e.g., "topright" + # colorset = use the name of any of the palattes above + # reference.grid = if true, draws a grid aligned with the points on the + # x and y axes. + # xaxis = if true, draws the x axis. + # event.lines = if not null, will draw vertical lines indicating that an + # event happened during that time period. event.lines should be a list + # of dates (e.g., c("09/03","05/06")) formatted the same as date.format. + # This function matches the re-formatted row names (dates) with the + # events.list, so to get a match the formatting needs to be correct. + # event.labels = if not null and event.lines is not null, this will apply + # labels to the vertical lines drawn. + + # All other inputs are the same as "plot" and are principally included + # so that some sensible defaults could be set. + + # Output: + # Draws a timeseries graph of type "line" with some sensible defaults. + + # FUNCTION: + + y = checkData(R) + + # Set up dimensions and labels + columns = ncol(y) + rows = nrow(y) + columnnames = colnames(y) + + if (is.null(date.format)){ + freq = periodicity(y) + yr_eq <- ifelse(format(index(first(y)),format="%Y")==format(index(last(y)),format="%Y"),TRUE,FALSE) + switch(freq$scale, + seconds = { date.format = "%H:%M"}, + minute = { date.format = "%H:%M"}, + hourly = {date.format = "%d %H"}, + daily = {if (yr_eq) date.format = "%b %d" else date.format = "%Y-%m-%d"}, + weekly = {if (yr_eq) date.format = "%b %d" else date.format = "%Y-%m-%d"}, + monthly = {if (yr_eq) date.format = "%b" else date.format = "%b %y"}, + quarterly = {if (yr_eq) date.format = "%b" else date.format = "%b %y"}, + yearly = {date.format = "%Y"} + ) + } + # Needed for finding aligned dates for event lines and period areas + rownames = as.Date(time(y)) + rownames = format(strptime(rownames,format = date.format.in), date.format) + + time.scale = periodicity(y)$scale + ep = axTicksByTime(y,major.ticks, format.labels = date.format) + + # If the Y-axis is ln + logaxis = "" + if(ylog) { + logaxis = "y" + } + + + if(dygraphPlot==FALSE){ + chart.TimeSeries.base(R, + auto.grid, + xaxis, + yaxis, + yaxis.right, + type, + lty, + lwd , + las , + main , + ylab, + xlab, + date.format.in, + date.format , + xlim , + ylim , + element.color, + event.lines, + event.labels, + period.areas, + event.color , + period.color , colorset , + pch, + legend.loc , + ylog , + cex.axis, + cex.legend , + cex.lab , + cex.labels, + cex.main , + major.ticks, + minor.ticks, + grid.color, + grid.lty, + xaxis.labels,...) + + + + + }else{ + if(is.null(main)) + main=columnnames[1] + + if(is.null(ylab)) { + if(ylog) + ylab = "ln(Value)" + + else + ylab = "Value" + } + + ##@TODO Get all the graphical parameters integrated with these two + dyRangeSelector(dygraph(y,main = main, + xlab = xlab, + ylab = ylab)) + + } + +} + +############################################################################### +# R (http://r-project.org/) Econometrics for Performance and Risk Analysis +# +# Copyright (c) 2004-2015 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$ +# +############################################################################### Modified: pkg/PerformanceAnalytics/R/chart.TimeSeries.base.R =================================================================== --- pkg/PerformanceAnalytics/R/chart.TimeSeries.base.R 2015-04-25 12:49:00 UTC (rev 3639) +++ pkg/PerformanceAnalytics/R/chart.TimeSeries.base.R 2015-04-25 13:08:18 UTC (rev 3640) @@ -1,375 +1,230 @@ -#' Creates a time series chart with some extensions. -#' -#' Draws a line chart and labels the x-axis with the appropriate dates. This -#' is really a "primitive", since it extends the base \code{\link{plot}} and -#' standardizes the elements of a chart. Adds attributes for shading areas of -#' the timeline or aligning vertical lines along the timeline. This function is -#' intended to be used inside other charting functions. -#' -#' -#' @param R an xts, vector, matrix, data frame, timeSeries or zoo object of -#' asset returns -#' @param auto.grid if true, draws a grid aligned with the points on the x and -#' y axes -#' @param grid.color sets the color for the reference grid -#' @param grid.lty defines the line type for the grid -#' @param xaxis if true, draws the x axis -#' @param yaxis if true, draws the y axis -#' @param yaxis.right if true, draws the y axis on the right-hand side of the -#' plot -#' @param type set the chart type, same as in \code{\link{plot}} -#' @param lty set the line type, same as in \code{\link{plot}} -#' @param lwd set the line width, same as in \code{\link{plot}} -#' @param las set the axis label rotation, same as in \code{\link{plot}} -#' @param main set the chart title, same as in \code{\link{plot}} -#' @param ylab set the y-axis label, same as in \code{\link{plot}} -#' @param xlab set the x-axis label, same as in \code{\link{plot}} -#' @param date.format re-format the dates for the xaxis; the default is "\%m/\%y" -#' @param xlim set the x-axis limit, same as in \code{\link{plot}} -#' @param ylim set the y-axis limit, same as in \code{\link{plot}} -#' @param event.lines If not null, vertical lines will be drawn to indicate -#' that an event happened during that time period. \code{event.lines} should -#' be a list of dates (e.g., \code{c("09/03","05/06"))} formatted the same as -#' date.format. This function matches the re-formatted row names (dates) with -#' the events.list, so to get a match the formatting needs to be correct. -#' @param event.labels if not null and event.lines is not null, this will apply -#' a list of text labels (e.g., \code{c("This Event", "That Event")} to the -#' vertical lines drawn. See the example below. -#' @param period.areas these are shaded areas described by start and end dates -#' in a vector of xts date rangees, e.g., -#' \code{c("1926-10::1927-11","1929-08::1933-03")} See the examples below. -#' @param event.color draws the event described in \code{event.labels} in the -#' color specified -#' @param period.color draws the shaded region described by \code{period.areas} -#' in the color specified -#' @param colorset color palette to use, set by default to rational choices -#' @param pch symbols to use, see also \code{\link{plot}} -#' @param element.color provides the color for drawing chart elements, such as -#' the box lines, axis lines, etc. Default is "darkgray" -#' @param legend.loc places a legend into one of nine locations on the chart: -#' bottomright, bottom, bottomleft, left, topleft, top, topright, right, or -#' center. -#' @param ylog TRUE/FALSE set the y-axis to logarithmic scale, similar to -#' \code{\link{plot}}, default FALSE -#' @param date.format.in allows specification of other date formats in the data -#' object, defaults to "\%Y-\%m-\%d" -#' @param cex.axis The magnification to be used for axis annotation relative to -#' the current setting of 'cex', same as in \code{\link{plot}}. -#' @param cex.legend The magnification to be used for sizing the legend -#' relative to the current setting of 'cex'. -#' @param cex.labels The magnification to be used for event line labels -#' relative to the current setting of 'cex'. -#' @param cex.lab The magnification to be used for x- and y-axis labels -#' relative to the current setting of 'cex'. -#' @param cex.main The magnification to be used for the chart title relative to -#' the current setting of 'cex'. -#' @param major.ticks Should major tickmarks be drawn and labeled, default -#' 'auto' -#' @param minor.ticks Should minor tickmarks be drawn, default TRUE -#' @param xaxis.labels Allows for non-date labeling of date axes, default is -#' NULL -#' @param space default 0 -#' @param \dots any other passthru parameters -#' @author Peter Carl -#' @seealso \code{\link{plot}}, \code{\link{par}}, -#' \code{\link[xts]{axTicksByTime}} -###keywords ts multivariate distribution models hplot -#' @examples -#' -#' -#' # These are start and end dates, formatted as xts ranges. -#' ## http://www.nber.org-cycles.html -#' cycles.dates<-c("1857-06/1858-12", -#' "1860-10/1861-06", -#' "1865-04/1867-12", -#' "1869-06/1870-12", -#' "1873-10/1879-03", -#' "1882-03/1885-05", -#' "1887-03/1888-04", -#' "1890-07/1891-05", -#' "1893-01/1894-06", -#' "1895-12/1897-06", -#' "1899-06/1900-12", -#' "1902-09/1904-08", -#' "1907-05/1908-06", -#' "1910-01/1912-01", -#' "1913-01/1914-12", [TRUNCATED] To get the complete diff run: svnlook diff /svnroot/returnanalytics -r 3640 From noreply at r-forge.r-project.org Sun Apr 26 07:56:47 2015 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Sun, 26 Apr 2015 07:56:47 +0200 (CEST) Subject: [Returnanalytics-commits] r3641 - in pkg/FactorAnalytics: . R man tests vignettes Message-ID: <20150426055648.2291B18790E@r-forge.r-project.org> Author: pragnya Date: 2015-04-26 07:56:44 +0200 (Sun, 26 Apr 2015) New Revision: 3641 Added: pkg/FactorAnalytics/tests/FactorAnalytics_04_25_15.pdf Removed: pkg/FactorAnalytics/tests/FactorAnalytics_04_21_15.pdf Modified: pkg/FactorAnalytics/DESCRIPTION pkg/FactorAnalytics/R/fitTsfm.R pkg/FactorAnalytics/R/fitTsfm.control.R pkg/FactorAnalytics/R/plot.tsfm.r pkg/FactorAnalytics/man/fitTsfm.control.Rd pkg/FactorAnalytics/vignettes/fitTsfm_vignette.Rnw pkg/FactorAnalytics/vignettes/fitTsfm_vignette.pdf Log: Added lmRob control parameters Modified: pkg/FactorAnalytics/DESCRIPTION =================================================================== --- pkg/FactorAnalytics/DESCRIPTION 2015-04-25 13:08:18 UTC (rev 3640) +++ pkg/FactorAnalytics/DESCRIPTION 2015-04-26 05:56:44 UTC (rev 3641) @@ -1,8 +1,8 @@ Package: factorAnalytics Type: Package Title: Factor Analytics -Version:2.0.18 -Date:2015-04-21 +Version:2.0.19 +Date:2015-04-25 Author: Eric Zivot, Sangeetha Srinivasan and Yi-An Chen Maintainer: Sangeetha Srinivasan Description: An R package for the estimation and risk analysis of linear factor Modified: pkg/FactorAnalytics/R/fitTsfm.R =================================================================== --- pkg/FactorAnalytics/R/fitTsfm.R 2015-04-25 13:08:18 UTC (rev 3640) +++ pkg/FactorAnalytics/R/fitTsfm.R 2015-04-26 05:56:44 UTC (rev 3641) @@ -185,8 +185,8 @@ m1 <- match(c("weights","model","x","y","qr"), names(control), 0L) lm.args <- control[m1, drop=TRUE] - m2 <- match(c("weights","model","x","y","nrep","efficiency"), - names(control), 0L) + m2 <- match(c("weights","model","x","y","nrep","efficiency","mxr","mxf", + "mxs","trace"), names(control), 0L) lmRob.args <- control[m2, drop=TRUE] m3 <- match(c("scope","scale","direction","trace","steps","k"), names(control), 0L) Modified: pkg/FactorAnalytics/R/fitTsfm.control.R =================================================================== --- pkg/FactorAnalytics/R/fitTsfm.control.R 2015-04-25 13:08:18 UTC (rev 3640) +++ pkg/FactorAnalytics/R/fitTsfm.control.R 2015-04-26 05:56:44 UTC (rev 3641) @@ -45,6 +45,12 @@ #' resampling is being used, the value of \code{nrep} is ignored. #' @param efficiency the asymptotic efficiency of the final estimate for #' \code{fit.method="Robust"}. Default is 0.9. +#' @param mxr the maximum number of iterations in the refinement step. Default +#' is 50. +#' @param mxf the maximum number of iterations for computing final coefficient +#' estimates. Default is 50. +#' @param mxs the maximum number of iterations for computing scale estimate. +#' Default is 50. #' @param scope defines the range of models examined in the \code{"stepwise"} #' search. This should be either a single formula, or a list containing #' components \code{upper} and \code{lower}, both formulae. See @@ -56,9 +62,10 @@ #' "backward", or "forward", with a default of "both". If the \code{scope} #' argument is missing the default for \code{direction} is "backward". #' @param trace If positive (or, not \code{FALSE}), info is printed during the -#' running of \code{\link[stats]{step}}, \code{\link[robust]{step.lmRob}}, -#' \code{\link[lars]{lars}} or \code{\link[lars]{cv.lars}} as relevant. Larger -#' values may give more detailed information. Default is \code{FALSE}. +#' running of \code{\link[robust]{lmRob}}, \code{\link[stats]{step}}, +#' \code{\link[robust]{step.lmRob}}, \code{\link[lars]{lars}} or +#' \code{\link[lars]{cv.lars}} as relevant. Larger values may give more +#' detailed information. Default is \code{FALSE}. #' @param steps the maximum number of steps to be considered for #' \code{"stepwise"}. Default is 1000 (essentially as many as required). It is #' typically used to stop the process early. @@ -131,11 +138,11 @@ #' fitTsfm.control <- function(decay=0.95, weights, model=TRUE, x=FALSE, y=FALSE, - qr=TRUE, nrep=NULL, efficiency=0.9, scope, scale, - direction, trace=FALSE, steps=1000, k=2, nvmin=1, - nvmax=8, force.in=NULL, force.out=NULL, method, - really.big=FALSE, type, normalize=TRUE, - eps=.Machine$double.eps, max.steps, + qr=TRUE, nrep=NULL, efficiency=0.9, mxr=50, mxf=50, + mxs=50, scope, scale, direction, trace=FALSE, + steps=1000, k=2, nvmin=1, nvmax=8, force.in=NULL, + force.out=NULL, method, really.big=FALSE, type, + normalize=TRUE, eps=.Machine$double.eps, max.steps, lars.criterion="Cp", K=10) { # get the user-specified arguments (that have no defaults) @@ -186,10 +193,10 @@ # return list of arguments with defaults if they are unspecified result <- c(args, list(decay=decay, model=model, x=x, y=y, qr=qr, nrep=nrep, - efficiency=efficiency, trace=trace, steps=steps, k=k, - nvmin=nvmin, nvmax=nvmax, force.in=force.in, - force.out=force.out, really.big=really.big, - normalize=normalize, eps=eps, + efficiency=efficiency, mxr=mxr, mxf=mxf, mxs=mxs, + trace=trace, steps=steps, k=k, nvmin=nvmin, + nvmax=nvmax, force.in=force.in, force.out=force.out, + really.big=really.big, normalize=normalize, eps=eps, lars.criterion=lars.criterion, K=K)) return(result) } Modified: pkg/FactorAnalytics/R/plot.tsfm.r =================================================================== --- pkg/FactorAnalytics/R/plot.tsfm.r 2015-04-25 13:08:18 UTC (rev 3640) +++ pkg/FactorAnalytics/R/plot.tsfm.r 2015-04-26 05:56:44 UTC (rev 3641) @@ -375,7 +375,7 @@ } rawdata <- coredata(merge.xts(x$data[,i], x$data[,x$factor.names])) plot(x=rawdata[,2], y=rawdata[,1], pch=20, main="", - xlab=paste(x$factor.names, "Returns"), ylab=paste(i,"Returns")) + xlab=paste(x$factor.names, "Returns"), ylab=paste(i,"Returns"), ...) coef <- summary(fit)$coefficients a=coef[1,1]; b=coef[2,1] se.a=round(coef[1,2],2); se.b=round(coef[2,2],2) @@ -552,14 +552,14 @@ asset <- x$asset.names[i] rawdata <- coredata(merge.xts(x$data[,asset], x$data[,x$factor.names])) plot(x=rawdata[,2], y=rawdata[,1], pch=20, main="", - xlab=paste(x$factor.names, "Returns"), ylab=paste(asset,"Returns")) + xlab=paste(x$factor.names, "Returns"), ylab=paste(asset,"Returns"), ...) coef <- summary(fit)$coefficients a=coef[1,1]; b=coef[2,1] se.a=round(coef[1,2],2); se.b=round(coef[2,2],2) abline(a=a, b=b, col="red", lty=2, lwd=2) lgnd <- c(bquote(.(meth) ~~ hat(alpha) == .(round(a,2))~(.(se.a))), bquote(.(meth) ~~ hat(beta) == .(round(b,2))~(.(se.b)))) - legend(x=legend.loc, bty="n", legend=as.expression(lgnd)) + legend(x=legend.loc, bty="n", legend=as.expression(lgnd), cex=0.9) } par(mfrow=c(1,1)) }, Modified: pkg/FactorAnalytics/man/fitTsfm.control.Rd =================================================================== --- pkg/FactorAnalytics/man/fitTsfm.control.Rd 2015-04-25 13:08:18 UTC (rev 3640) +++ pkg/FactorAnalytics/man/fitTsfm.control.Rd 2015-04-26 05:56:44 UTC (rev 3641) @@ -5,11 +5,11 @@ \title{List of control parameters for \code{fitTsfm}} \usage{ fitTsfm.control(decay = 0.95, weights, model = TRUE, x = FALSE, - y = FALSE, qr = TRUE, nrep = NULL, efficiency = 0.9, scope, scale, - direction, trace = FALSE, steps = 1000, k = 2, nvmin = 1, nvmax = 8, - force.in = NULL, force.out = NULL, method, really.big = FALSE, type, - normalize = TRUE, eps = .Machine$double.eps, max.steps, - lars.criterion = "Cp", K = 10) + y = FALSE, qr = TRUE, nrep = NULL, efficiency = 0.9, mxr = 50, + mxf = 50, mxs = 50, scope, scale, direction, trace = FALSE, + steps = 1000, k = 2, nvmin = 1, nvmax = 8, force.in = NULL, + force.out = NULL, method, really.big = FALSE, type, normalize = TRUE, + eps = .Machine$double.eps, max.steps, lars.criterion = "Cp", K = 10) } \arguments{ \item{decay}{a scalar in (0, 1] to specify the decay factor for "DLS". @@ -34,6 +34,15 @@ \item{efficiency}{the asymptotic efficiency of the final estimate for \code{fit.method="Robust"}. Default is 0.9.} +\item{mxr}{the maximum number of iterations in the refinement step. Default +is 50.} + +\item{mxf}{the maximum number of iterations for computing final coefficient +estimates. Default is 50.} + +\item{mxs}{the maximum number of iterations for computing scale estimate. +Default is 50.} + \item{scope}{defines the range of models examined in the \code{"stepwise"} search. This should be either a single formula, or a list containing components \code{upper} and \code{lower}, both formulae. See @@ -48,9 +57,10 @@ argument is missing the default for \code{direction} is "backward".} \item{trace}{If positive (or, not \code{FALSE}), info is printed during the -running of \code{\link[stats]{step}}, \code{\link[robust]{step.lmRob}}, -\code{\link[lars]{lars}} or \code{\link[lars]{cv.lars}} as relevant. Larger -values may give more detailed information. Default is \code{FALSE}.} +running of \code{\link[robust]{lmRob}}, \code{\link[stats]{step}}, +\code{\link[robust]{step.lmRob}}, \code{\link[lars]{lars}} or +\code{\link[lars]{cv.lars}} as relevant. Larger values may give more +detailed information. Default is \code{FALSE}.} \item{steps}{the maximum number of steps to be considered for \code{"stepwise"}. Default is 1000 (essentially as many as required). It is Deleted: pkg/FactorAnalytics/tests/FactorAnalytics_04_21_15.pdf =================================================================== (Binary files differ) Added: pkg/FactorAnalytics/tests/FactorAnalytics_04_25_15.pdf =================================================================== (Binary files differ) Property changes on: pkg/FactorAnalytics/tests/FactorAnalytics_04_25_15.pdf ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Modified: pkg/FactorAnalytics/vignettes/fitTsfm_vignette.Rnw =================================================================== --- pkg/FactorAnalytics/vignettes/fitTsfm_vignette.Rnw 2015-04-25 13:08:18 UTC (rev 3640) +++ pkg/FactorAnalytics/vignettes/fitTsfm_vignette.Rnw 2015-04-26 05:56:44 UTC (rev 3641) @@ -258,7 +258,7 @@ For easy reference, here's a classified list of control parameters accepted and passed by \code{fitTsfm} to their respective model fitting (or) model selection functions in other packages. See the corresponding help files for more details on each parameter. \begin{itemize} \item \verb"lm": "weights","model","x","y","qr" -\item \verb"lmRob": "weights","model","x","y","nrep","efficiency" +\item \verb"lmRob": "weights","model","x","y","nrep","efficiency","mxr","mxf","mxs","trace" \item \verb"step": "scope","scale","direction","trace","steps","k" \item \verb"regsubsets": "weights","nvmax","force.in","force.out","method","really.big" \item \verb"lars": "type","normalize","eps","max.steps","trace" Modified: pkg/FactorAnalytics/vignettes/fitTsfm_vignette.pdf =================================================================== (Binary files differ)