[Returnanalytics-commits] r3601 - in pkg/FactorAnalytics: . R man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Mon Feb 23 23:57:04 CET 2015
Author: chenyian
Date: 2015-02-23 23:57:04 +0100 (Mon, 23 Feb 2015)
New Revision: 3601
Added:
pkg/FactorAnalytics/R/summary.tsfmUpDn.r
pkg/FactorAnalytics/man/summary.tsfmUpDn.Rd
Modified:
pkg/FactorAnalytics/NAMESPACE
pkg/FactorAnalytics/R/fitTsfmUpDn.r
Log:
Add summary.tsfmUpDn.r method and print.summary.tsfmUpDn.r method
Modified: pkg/FactorAnalytics/NAMESPACE
===================================================================
--- pkg/FactorAnalytics/NAMESPACE 2015-02-09 20:05:44 UTC (rev 3600)
+++ pkg/FactorAnalytics/NAMESPACE 2015-02-23 22:57:04 UTC (rev 3601)
@@ -21,12 +21,14 @@
S3method(print,sfm)
S3method(print,summary.sfm)
S3method(print,summary.tsfm)
+S3method(print,summary.tsfmUpDn)
S3method(print,tsfm)
S3method(residuals,sfm)
S3method(residuals,tsfm)
S3method(summary,pafm)
S3method(summary,sfm)
S3method(summary,tsfm)
+S3method(summary,tsfmUpDn)
export(dCornishFisher)
export(fitSfm)
export(fitTsfm)
Modified: pkg/FactorAnalytics/R/fitTsfmUpDn.r
===================================================================
--- pkg/FactorAnalytics/R/fitTsfmUpDn.r 2015-02-09 20:05:44 UTC (rev 3600)
+++ pkg/FactorAnalytics/R/fitTsfmUpDn.r 2015-02-23 22:57:04 UTC (rev 3601)
@@ -201,5 +201,7 @@
data=dataDn.xts,fit.method=fit.method,variable.selection=variable.selection,
control=control)
-return(list(Up = fitUp, Dn = fitDn))
+ result <- list(Up = fitUp, Dn = fitDn)
+ class(result) <- "tsfmUpDn"
+return(result)
}
Added: pkg/FactorAnalytics/R/summary.tsfmUpDn.r
===================================================================
--- pkg/FactorAnalytics/R/summary.tsfmUpDn.r (rev 0)
+++ pkg/FactorAnalytics/R/summary.tsfmUpDn.r 2015-02-23 22:57:04 UTC (rev 3601)
@@ -0,0 +1,92 @@
+#' @title Summarizing a fitted up and down market time series factor model
+#'
+#' @description \code{summary} method for object of class \code{tsfmUpDn}.
+#' Returned object is of class {summary.tsfmUpDn}. This function provides a \code{summary}
+#' method to an object returned by a wrapper function \code{fitTsfmUpDn}.
+#'
+#' @details Since \code{fitTsfmUpDn} fits both up market and down market,
+#' \code{summary.tsfmUpDn} applies \code{summary.tsfm} for both markets fitted
+#' objects and combines the coefficients interested together.
+#'
+#'
+#' @param object an object of class \code{tsfmUpDn} returned by \code{fitTsfmUpDn}.
+#' @param ... futher arguments passed to or from \code{summary.tsfm} methods.
+#' @param uD.list an object of class \code{summary.tsfmUpDn}.
+#' @param digits number of significants digits to use when printing.
+#' Default is 3.
+#'
+#' @return Returns an object of class \code{summary.tsfmUpDn}. This object contains
+#' a list object of \code{Up} and \code{Dn} for up market and down market respectively.
+#'
+#' The print method for class \code{summary.tsfmUpDn} outputs the call,
+#' coefficients (with standard errors and t-statistics), r-squared and
+#' residual volatilty (under the homoskedasticity assumption) for all assets in up and
+#' down market.
+#'
+#' Object of class \code{summary.tsfmUpDn} is a list of 2 containing:
+#' \item{Up}{A list of the up market fitted object. It is a class of \code{summary.tsfm}}
+#' \item{Dn}{A list of the down market fitted object. It is a class of \code{summary.tsfm}}
+#'
+#' @author Yi-An Chen.
+#'
+#' @seealso \code{\link{fitTsfmUpDn}}, \code{\link[stats]{summary.tsfm}}
+#'
+#' @examples
+#' # load data from the database
+#' data(managers)
+#'
+#' # example: Up and down market factor model with OLS fit
+#' fitUpDn <- fitTsfmUpDn(asset.names=colnames(managers[,(1:6)]),mkt.name="SP500.TR",
+#' data=managers, fit.method="OLS",control=NULL)
+#'
+#' summary(fitUpDn)
+#'
+#' @importFrom lmtest coeftest.default
+#' @importFrom sandwich vcovHC.default vcovHAC.default
+#'
+#' @method summary tsfmUpDn
+#' @export
+
+summary.tsfmUpDn <- function(object,...) {
+ # check input object validity
+ if (!inherits(object, "tsfmUpDn")) {
+ stop("Invalid 'tsfmUpDn' object")
+ }
+ uD.list <- lapply(object,summary,...)
+ class(uD.list) <- "summary.tsfmUpDn"
+ return(uD.list)
+}
+ #' @rdname summary.tsfmUpDn
+ #' @method print summary.tsfmUpDn
+ #' @export
+
+
+ print.summary.tsfmUpDn <- function(uD.list, digits=3, ...) {
+ if(!is.null(cl <- uD.list$Up$call)) {
+ cat("\nCall:\n")
+ dput(cl)
+ }
+ cat("\nFactor Model Coefficients:\n", sep="")
+ n <- length(uD.list$Up$sum.list)
+ for (i in 1:n) {
+ options(digits = digits)
+ table.coef.Up <- (uD.list$Up$sum.list)[[i]]$coefficients
+ rownames(table.coef.Up) <- sapply(rownames(table.coef.Up),function(x) paste(x,"_Up",sep="") )
+ table.coef.Dn <- (uD.list$Dn$sum.list)[[i]]$coefficients
+ rownames(table.coef.Dn) <- sapply(rownames(table.coef.Dn),function(x) paste(x,"_Dn",sep="") )
+ table.coef <- rbind(table.coef.Up,table.coef.Dn)
+ if (dim(table.coef)[2] > 1) {
+ cat("\nAsset", i, ": ", names(uD.list$Up$sum.list[i]), "\n(", uD.list$Up$se.type,
+ " Standard Errors & T-stats)\n\n", sep="")
+ } else {
+ cat("\nAsset", i, ": ", names(uD.list$Up$sum.list[i]), "\n\n", sep="")
+ }
+ r2Up <- uD.list$Up$sum.list[[i]]$r.squared
+ sigmaUp <- uD.list$Up$sum.list[[i]]$sigma
+ r2Dn <- uD.list$Dn$sum.list[[i]]$r.squared
+ sigmaDn <- uD.list$Dn$sum.list[[i]]$sigma
+ printCoefmat(table.coef, digits=digits,...)
+ cat("\n R-squared_Up: ", r2Up,", Residual Volatility_Up: ", sigmaUp,"\n",
+ "R-squared_Dn: ", r2Dn,", Residual Volatility_Dn: ", sigmaDn)
+ }
+}
\ No newline at end of file
Added: pkg/FactorAnalytics/man/summary.tsfmUpDn.Rd
===================================================================
--- pkg/FactorAnalytics/man/summary.tsfmUpDn.Rd (rev 0)
+++ pkg/FactorAnalytics/man/summary.tsfmUpDn.Rd 2015-02-23 22:57:04 UTC (rev 3601)
@@ -0,0 +1,61 @@
+% Generated by roxygen2 (4.1.0): do not edit by hand
+% Please edit documentation in R/summary.tsfmUpDn.r
+\name{summary.tsfmUpDn}
+\alias{print.summary.tsfmUpDn}
+\alias{summary.tsfmUpDn}
+\title{Summarizing a fitted up and down market time series factor model}
+\usage{
+\method{summary}{tsfmUpDn}(object, ...)
+
+\method{print}{summary.tsfmUpDn}(uD.list, digits = 3, ...)
+}
+\arguments{
+\item{object}{an object of class \code{tsfmUpDn} returned by \code{fitTsfmUpDn}.}
+
+\item{...}{futher arguments passed to or from \code{summary.tsfm} methods.}
+
+\item{uD.list}{an object of class \code{summary.tsfmUpDn}.}
+
+\item{digits}{number of significants digits to use when printing.
+Default is 3.}
+}
+\value{
+Returns an object of class \code{summary.tsfmUpDn}. This object contains
+a list object of \code{Up} and \code{Dn} for up market and down market respectively.
+
+The print method for class \code{summary.tsfmUpDn} outputs the call,
+coefficients (with standard errors and t-statistics), r-squared and
+residual volatilty (under the homoskedasticity assumption) for all assets in up and
+down market.
+
+Object of class \code{summary.tsfmUpDn} is a list of 2 containing:
+\item{Up}{A list of the up market fitted object. It is a class of \code{summary.tsfm}}
+\item{Dn}{A list of the down market fitted object. It is a class of \code{summary.tsfm}}
+}
+\description{
+\code{summary} method for object of class \code{tsfmUpDn}.
+Returned object is of class {summary.tsfmUpDn}. This function provides a \code{summary}
+method to a return object of a wrapper function \code{fitTsfmUpDn}.
+}
+\details{
+Since \code{fitTsfmUpDn} fits both up market and down market,
+\code{summary.tsfmUpDn} applies \code{summary.tsfm} for both markets fitted
+objects and combines the coefficients together.
+}
+\examples{
+# load data from the database
+data(managers)
+
+# example: Up and down market factor model with OLS fit
+fitUpDn <- fitTsfmUpDn(asset.names=colnames(managers[,(1:6)]),mkt.name="SP500.TR",
+ data=managers, fit.method="OLS",control=NULL)
+
+ summary(fitUpDn)
+}
+\author{
+Yi-An Chen.
+}
+\seealso{
+\code{\link{fitTsfmUpDn}}, \code{\link[stats]{summary.tsfm}}
+}
+
More information about the Returnanalytics-commits
mailing list