[Returnanalytics-commits] r3628 - in pkg/FactorAnalytics: . R man vignettes
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Mon Apr 13 08:38:17 CEST 2015
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 <sangee at uw.edu>
-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 <sangee at uw.edu>
+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
More information about the Returnanalytics-commits
mailing list