[Returnanalytics-commits] r3605 - in pkg/FactorAnalytics: . R man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Tue Feb 24 02:37:13 CET 2015
Author: chenyian
Date: 2015-02-24 02:37:13 +0100 (Tue, 24 Feb 2015)
New Revision: 3605
Added:
pkg/FactorAnalytics/R/plot.tsfmUpDn.r
pkg/FactorAnalytics/man/plot.tsfmUpDn.Rd
Modified:
pkg/FactorAnalytics/NAMESPACE
Log:
Add plot.tsfmUpDn.r and plot.tsfmUpDn.Rd
Modified: pkg/FactorAnalytics/NAMESPACE
===================================================================
--- pkg/FactorAnalytics/NAMESPACE 2015-02-24 00:03:47 UTC (rev 3604)
+++ pkg/FactorAnalytics/NAMESPACE 2015-02-24 01:37:13 UTC (rev 3605)
@@ -15,6 +15,7 @@
S3method(plot,pafm)
S3method(plot,sfm)
S3method(plot,tsfm)
+S3method(plot,tsfmUpDn)
S3method(predict,sfm)
S3method(predict,tsfm)
S3method(predict,tsfmUpDn)
Added: pkg/FactorAnalytics/R/plot.tsfmUpDn.r
===================================================================
--- pkg/FactorAnalytics/R/plot.tsfmUpDn.r (rev 0)
+++ pkg/FactorAnalytics/R/plot.tsfmUpDn.r 2015-02-24 01:37:13 UTC (rev 3605)
@@ -0,0 +1,67 @@
+#' @title Plot actual against fitted values of up and down market time series factor model
+#'
+#' @description Generic \code{plot} method for object of class \code{tsfmUpDn}.
+#'
+#' @details
+#' This method plots actual values against fitted value of up and down market time series
+#' factor model. The black dots are actual values and the red lines are fitted values.
+#'
+#' For other types of plots, use the list objects (\code{Up} and \code{Dn}) of class \code{tsfmUpDn}. As a result, the
+#' \code{plot.tsfm} can be applied.
+#'
+#' @param object an object of class \code{tsfmUpDn} produced by \code{fitTsfmUpDn}.
+#' @param mkt.name The name of market returns used in \code{fitTsfmUpDn}. It is necessary
+#' to provide the name of market returns.
+#' @param assets.name The name of the assets used in \code{fitTsfmUpDn}. It only supports
+#' single asset so far.
+#' @param ... Other arguments can be used in \code{plot}.
+#' @author Yi-An Chen
+#'
+#' @seealso \code{\link{fitTsfmUpDn}}
+#'
+#' @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)
+#' # plot the fitted model of the first asset
+#' plot(fitUpDn,mkt.name="SP500.TR",assets.name="HAM1")
+#'
+#'
+#' @method plot tsfmUpDn
+#' @export
+
+
+plot.tsfmUpDn <- function(object,mkt.name,assets.name,...) {
+
+ if (is.null(mkt.name)){
+ stop("Missing argument: mkt.name has to be specified for plot method.")
+ }
+
+ if (is.null(assets.name)){
+ stop("Missing argument: assets.name has to be specified.")
+ }
+
+ if (!(mkt.name %in% object$Up$factor.names)) {
+ stop("mkt.name has to the same mkt.name used in fitTsfmUpDn().")
+ }
+
+ # extract info from the fitTsfm object
+ plotDataUp <- merge.xts(object$Up$data[,c(assets.name,mkt.name)], fitted(object$Up)[,assets.name])
+ colnames(plotDataUp) <- c("ActualUp","MktUp","FittedUp")
+ plotDataDn <-merge.xts(object$Dn$data[,c(assets.name,mkt.name)], fitted(object$Dn)[,assets.name])
+ colnames(plotDataDn) <- c("ActualDn","MktDn","FittedDn")
+
+ plot(rbind(coredata(plotDataUp$MktUp),coredata(plotDataDn$MktDn)),
+ rbind(coredata(plotDataUp$ActualUp),coredata(plotDataDn$ActualDn)),
+ main = paste("Actual vs Fitted values of the Asset ",assets.name,sep=""),
+ xlab=mkt.name,ylab=assets.name,...)
+ abline(v=0)
+ lines(coredata(plotDataUp$MktUp),coredata(plotDataUp$FittedUp),col="red")
+ lines(coredata(plotDataDn$MktDn),coredata(plotDataDn$FittedDn),col="red")
+ abline(h=0)
+
+
+}
\ No newline at end of file
Added: pkg/FactorAnalytics/man/plot.tsfmUpDn.Rd
===================================================================
--- pkg/FactorAnalytics/man/plot.tsfmUpDn.Rd (rev 0)
+++ pkg/FactorAnalytics/man/plot.tsfmUpDn.Rd 2015-02-24 01:37:13 UTC (rev 3605)
@@ -0,0 +1,45 @@
+% Generated by roxygen2 (4.1.0): do not edit by hand
+% Please edit documentation in R/plot.tsfmUpDn.r
+\name{plot.tsfmUpDn}
+\alias{plot.tsfmUpDn}
+\title{Plot actual against fitted values of up and down market time series factor model}
+\usage{
+\method{plot}{tsfmUpDn}(object, mkt.name, assets.name, ...)
+}
+\arguments{
+\item{object}{an object of class \code{tsfmUpDn} produced by \code{fitTsfmUpDn}.}
+
+\item{mkt.name}{The name of market returns used in \code{fitTsfmUpDn}. It is necessary
+to provide the name of market returns.}
+
+\item{assets.name}{The name of the assets used in \code{fitTsfmUpDn}. It only supports
+single asset so far.}
+
+\item{...}{Other arguments can be used in \code{plot}.}
+}
+\description{
+Generic \code{plot} method for object of class \code{tsfmUpDn}.
+}
+\details{
+This method plots actual values against fitted value of up and down market time series
+factor model. The black dots are actual values and the red lines are fitted values.
+
+For other types of plots, use the list objects (\code{Up} and \code{Dn}) of class \code{tsfmUpDn}. As a result, the
+\code{plot.tsfm} can be applied.
+}
+\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)
+ # plot the fitted model of the first asset
+ plot(fitUpDn,mkt.name="SP500.TR",assets.name="HAM1")
+}
+\author{
+Yi-An Chen
+}
+\seealso{
+\code{\link{fitTsfmUpDn}}
+}
+
More information about the Returnanalytics-commits
mailing list