[Returnanalytics-commits] r3623 - in pkg/FactorAnalytics: R man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Fri Mar 20 20:48:33 CET 2015


Author: chenyian
Date: 2015-03-20 20:48:33 +0100 (Fri, 20 Mar 2015)
New Revision: 3623

Modified:
   pkg/FactorAnalytics/R/plot.tsfmUpDn.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/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
Log:
debug plot.tsfmUpDn.r
1. change arguments name : SFM.line, LSnRob
2. change legend layout.
3. debug a straight line fitting. 


Modified: pkg/FactorAnalytics/R/plot.tsfmUpDn.r
===================================================================
--- pkg/FactorAnalytics/R/plot.tsfmUpDn.r	2015-03-20 08:48:00 UTC (rev 3622)
+++ pkg/FactorAnalytics/R/plot.tsfmUpDn.r	2015-03-20 19:48:33 UTC (rev 3623)
@@ -1,148 +1,162 @@
-#' @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 dots are actual values and the dashed lines are fitted values. Users can 
-#' choose to add a single market factor model and a robust up and down model for comaprsion. 
-#' 
-#' For other types of plots, use the list objects \code{Up} and \code{Dn} of class \code{tsfmUpDn}. 
-#' The \code{plot.tsfm} can be applied.
-#' 
-#' @param x an object of class \code{tsfmUpDn} produced by \code{fitTsfmUpDn}.
-#' @param which.assets A vector of character to show single or multiple assets names. The defualt if 
-#' \code{NULL}.  
-#' @param line.color A vector of color codes of up/dn fitted line. The first color is for the object fitted
-#' line and the second color for the comparison fitted line. The default is \code{c("blue","purple")}.
-#' @param line.type The line type of up/dn fitted values. The default is \code{"dotted"}.
-#' @param add.legend A logic flag to add a legend. The default is \code{TRUE}.
-#' @param add.SFM.line A logic flag to add a fitted single factor model. The default is \code{FALSE}.
-#' @param add.comparison A logic flag to add a comparison Up/Down factor model. If the original model
-#' is \code{""}, the comparison model is \code{"Robust"} and vice versa. The default is \code{FALSE}.
-#' @param show.comparison.legend A logic flag to opt for showing the legend of the comparison model. 
-#' The default is \code{FALSE}.  
-#' @param legend.loc The default is \code{"topleft"}.
-#' @param legend.cex \code{cex} of \code{legend}.
-#' 
-#' @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  fit
-#'  fitUpDn <- fitTsfmUpDn(asset.names=colnames(managers[,(1:6)]),mkt.name="SP500.TR",
-#'                        data=managers, fit.method="LS")
-#' # plot the fitted model of every assets, press enter to show the next plot.
-#'  plot(fitUpDn)
-#'  
-#' # or choose to plot one specific asset
-#'  plot(fitUpDn,which.assets="HAM1")
-#'  
-#' # add a single market factor model fitted line
-#'  plot(fitUpDn,add.SFM.line=TRUE,which.assets="HAM1")
-#'              
-#' # add Robust Up/Dn model fitted line and change legend to show the robust up/dn Beta                               
-#'  plot(fitUpDn,add.comparison=TRUE,show.comparison.legend=TRUE,add.SFM.line=TRUE,which.assets="HAM1")
-#'  
-#'                                                                                                                                      
-#' @method plot tsfmUpDn
-#' @export
-
-
-plot.tsfmUpDn <- function(x,which.assets=NULL,add.SFM.line=FALSE,add.comparison=FALSE,
-                          line.color=c("blue","purple"),line.type="dotted",
-                          add.legend=TRUE,legend.loc="topleft",legend.cex=0.9,
-                          show.comparison.legend=FALSE,...) {
-  
-  # specify the name of market returns and the assets returns
-  mkt.name = x$Up$factor.names
-  
-  # add SFM estimation 
-  
-  if (add.SFM.line) {
-    data = x$data
-    asset.names = x$Up$asset.names
-    fit.method = x$Up$fit.method
-    fitSf <-  fitTsfm(asset.names=asset.names,factor.names=mkt.name,mkt.name=mkt.name,rf.name=NULL,
-                      data=data,fit.method=fit.method)
-    plotDataSf <- merge.xts(fitted(fitSf),fitSf$data[,mkt.name])
-  }
-  
-  # add LS/Robust Up/Dn comparison
-  
-  if (add.comparison) {
-    fit.methods <- c("LS","Robust")
-    x$call$fit.method <- fit.methods[!fit.methods%in%x$call$fit.method]
-    x.alt <- eval(x$call)  
-  }
-  
-  if (is.null(which.assets)) { 
-    assets.name.all = x$Up$asset.names    
-  } else {
-    assets.name.all = which.assets  
-  }
-    while(length(assets.name.all)>0){
-      assets.name = assets.name.all[1]
-      # extract info from the fitTsfm x
-      plotDataUp <- merge.xts(x$Up$data[,c(assets.name,mkt.name)], fitted(x$Up)[,assets.name])
-      colnames(plotDataUp) <- c("ActualUp","MktUp","FittedUp")
-      plotDataDn <-merge.xts(x$Dn$data[,c(assets.name,mkt.name)], fitted(x$Dn)[,assets.name])
-      colnames(plotDataDn) <- c("ActualDn","MktDn","FittedDn")
-    
-      plot(rbind(coredata(plotDataUp$MktUp),coredata(plotDataDn$MktDn)),
-           rbind(coredata(plotDataUp$ActualUp),coredata(plotDataDn$ActualDn)),
-           xlab=mkt.name,ylab=assets.name,...)
-      abline(v=0)
-      lines(coredata(plotDataUp$MktUp),coredata(plotDataUp$FittedUp),col=line.color[1],lty=line.type)
-      lines(coredata(plotDataDn$MktDn),coredata(plotDataDn$FittedDn),col=line.color[1],lty=line.type)
-      abline(h=0)
-      
-      up.beta <- round(summary(x$Up)$sum.list[[assets.name]]$coefficients[mkt.name,1:2],2)
-      dn.beta <- round(summary(x$Dn)$sum.list[[assets.name]]$coefficients[mkt.name,1:2],2)
-      up.beta <- c(as.character(up.beta)[1],paste("(",as.character(up.beta)[2],")",sep=""))
-      dn.beta <- c(as.character(dn.beta)[1],paste("(",as.character(dn.beta)[2],")",sep=""))
-      line.col = line.color[1]
-      # add LS line 
-      if (add.SFM.line){
-        lines(coredata(plotDataSf[,assets.name]),coredata(plotDataSf[,mkt.name]),lty="dotted")
-        legend.name = paste(fit.method,"fitted line",seq="")
-        
-      }
-      
-      # add alternative Up/Dn model for comparison
-      if (add.comparison){
-        plotDataUp.alt <- merge.xts(x.alt$Up$data[,c(assets.name,mkt.name)], fitted(x.alt$Up)[,assets.name])
-        colnames(plotDataUp.alt) <- c("ActualUp","MktUp","FittedUp")
-        plotDataDn.alt <-merge.xts(x.alt$Dn$data[,c(assets.name,mkt.name)], fitted(x.alt$Dn)[,assets.name])
-        colnames(plotDataDn.alt) <- c("ActualDn","MktDn","FittedDn")
-        lines(coredata(plotDataUp.alt$MktUp),coredata(plotDataUp.alt$FittedUp),col=line.color[2],lty=line.type)
-        lines(coredata(plotDataDn.alt$MktDn),coredata(plotDataDn.alt$FittedDn),col=line.color[2],lty=line.type)
-        
-        # add comparison legend 
-        if (show.comparison.legend) {
-        up.beta <- round(summary(x.alt$Up)$sum.list[[assets.name]]$coefficients[mkt.name,1:2],2)
-        dn.beta <- round(summary(x.alt$Dn)$sum.list[[assets.name]]$coefficients[mkt.name,1:2],2)
-        up.beta <- c(as.character(up.beta)[1],paste("(",as.character(up.beta)[2],")",sep=""))
-        dn.beta <- c(as.character(dn.beta)[1],paste("(",as.character(dn.beta)[2],")",sep=""))
-        line.col = line.color[2]
-        } 
-      }
-      
-      if (add.legend){
-          legend.txt = c("Up Beta",up.beta,"Dn Beta",dn.beta)                          
-          legend.lty = c(line.type,NA,NA,line.type,NA,NA) 
-          legend.col = c(line.col,NA,NA,line.col,NA,NA)
-          legend(legend.loc,legend=legend.txt,ncol=2,lty=legend.lty,col=legend.col,cex=legend.cex)            
-                
-      }
-      assets.name.all <- assets.name.all[-1]
-      par(ask=TRUE)
-    }
-  # turn it back
-  par(ask=FALSE)
+#' @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 dots are actual values and the dashed lines are fitted values. Users can 
+#' choose to add a single market factor model and a robust up and down model for comaprsion. 
+#' 
+#' For other types of plots, use the list objects \code{Up} and \code{Dn} of class \code{tsfmUpDn}. 
+#' The \code{plot.tsfm} can be applied.
+#' 
+#' @param x an object of class \code{tsfmUpDn} produced by \code{fitTsfmUpDn}.
+#' @param asset.name A vector of character to show single or multiple assets names. The defualt if 
+#' \code{NULL}.  
+#' @param line.color A vector of color codes of up/dn fitted line. The first color is for the object fitted
+#' line and the second color for the comparison fitted line. The default is \code{c("blue","purple")}.
+#' @param line.type The line type of up/dn fitted values. The default is \code{"dotted"}.
+#' @param add.legend A logic flag to add a legend. The default is \code{TRUE}.
+#' @param SFM.line A logic flag to add a fitted single factor model. The default is \code{FALSE}.
+#' @param LSnRob A logic flag to add a comparison Up/Down factor model. If the original model
+#' is \code{"LS"}, the comparison model is \code{"Robust"} and vice versa. The default is \code{FALSE}.
+#' The default is \code{FALSE}.  
+#' @param legend.loc The default is \code{"topleft"}.
+#' @param legend.cex \code{cex} of \code{legend}.
+#' 
+#' @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  fit
+#'  fitUpDn <- fitTsfmUpDn(asset.names=colnames(managers[,(1:6)]),mkt.name="SP500.TR",
+#'                        data=managers, fit.method="LS")
+#' # plot the fitted model of every assets, press enter to show the next plot.
+#'  plot(fitUpDn)
+#'  
+#' # or choose to plot one specific asset
+#'  plot(fitUpDn,asset.name="HAM1")
+#'  
+#' # add a single market factor model fitted line
+#'  plot(fitUpDn,SFM.line=TRUE,asset.name="HAM1")
+#'              
+#' # add Robust Up/Dn model fitted line and change legend to show the robust up/dn Beta                               
+#'  plot(fitUpDn,LSnRob=TRUE,asset.name="HAM1")
+#'  
+#'                                                                                                                                      
+#' @method plot tsfmUpDn
+#' @export
+
+
+plot.tsfmUpDn <- function(x,asset.name=NULL,SFM.line=FALSE,LSnRob=FALSE,
+                          line.color=c("blue","purple"),line.type="dotted",
+                          add.legend=TRUE,legend.loc="topleft",legend.cex=0.9,
+                          ...) {
+  
+  # specify the name of market returns and the assets returns
+  mkt.name = x$Up$factor.names
+  
+  # add SFM estimation 
+  
+  if (SFM.line) {
+    data = x$data
+    asset.names = x$Up$asset.names
+    fit.method = x$Up$fit.method
+    fitSf <-  fitTsfm(asset.names=asset.names,factor.names=mkt.name,mkt.name=mkt.name,rf.name=NULL,
+                      data=data,fit.method=fit.method)
+    plotDataSf <- merge.xts(fitted(fitSf),fitSf$data[,mkt.name])
+  }
+  
+  # add LS/Robust Up/Dn comparison
+  
+  if (LSnRob) {
+    fit.methods <- c("LS","Robust")
+    x$call$fit.method <- fit.methods[!fit.methods%in%x$Up$fit.method]
+    x.alt <- eval(x$call)  
+  }
+  
+  if (is.null(asset.name)) { 
+    assets.name.all = x$Up$asset.names    
+  } else {
+    assets.name.all = asset.name  
+  }
+    while(length(assets.name.all)>0){
+      assets.name = assets.name.all[1]
+      # extract info from the fitTsfm x
+      plotDataUp <- merge.xts(x$Up$data[,c(assets.name,mkt.name)], fitted(x$Up)[,assets.name])
+      colnames(plotDataUp) <- c("ActualUp","MktUp","FittedUp")
+      plotDataDn <-merge.xts(x$Dn$data[,c(assets.name,mkt.name)], fitted(x$Dn)[,assets.name])
+      colnames(plotDataDn) <- c("ActualDn","MktDn","FittedDn")
+    
+      plot(rbind(coredata(plotDataUp$MktUp),coredata(plotDataDn$MktDn)),
+           rbind(coredata(plotDataUp$ActualUp),coredata(plotDataDn$ActualDn)),
+           xlab=mkt.name,ylab=assets.name,...)
+      abline(v=0)
+      lines(coredata(plotDataUp$MktUp),coredata(plotDataUp$FittedUp),col=line.color[1],lty=line.type)
+      lines(coredata(plotDataDn$MktDn),coredata(plotDataDn$FittedDn),col=line.color[1],lty=line.type)
+      abline(h=0)
+      
+      up.beta <- round(summary(x$Up)$sum.list[[assets.name]]$coefficients[mkt.name,1:2],2)
+      dn.beta <- round(summary(x$Dn)$sum.list[[assets.name]]$coefficients[mkt.name,1:2],2)
+      up.beta <- paste(as.character(up.beta)[1]," (",as.character(up.beta)[2],")",sep="")
+      dn.beta <- paste(as.character(dn.beta)[1]," (",as.character(dn.beta)[2],")",sep="")
+    
+      # add LS line 
+      if (SFM.line){
+        lines(coredata(plotDataSf[,mkt.name]),coredata(plotDataSf[,assets.name]),lty="dotted")
+       # legend.name = paste(fit.method,"fitted line",seq="")
+        
+      }
+      
+      # add alternative Up/Dn model for comparison
+      if (LSnRob){
+        plotDataUp.alt <- merge.xts(x.alt$Up$data[,c(assets.name,mkt.name)], fitted(x.alt$Up)[,assets.name])
+        colnames(plotDataUp.alt) <- c("ActualUp","MktUp","FittedUp")
+        plotDataDn.alt <-merge.xts(x.alt$Dn$data[,c(assets.name,mkt.name)], fitted(x.alt$Dn)[,assets.name])
+        colnames(plotDataDn.alt) <- c("ActualDn","MktDn","FittedDn")
+        lines(coredata(plotDataUp.alt$MktUp),coredata(plotDataUp.alt$FittedUp),col=line.color[2],lty=line.type)
+        lines(coredata(plotDataDn.alt$MktDn),coredata(plotDataDn.alt$FittedDn),col=line.color[2],lty=line.type)
+        
+       
+        up.beta.alt <- round(summary(x.alt$Up)$sum.list[[assets.name]]$coefficients[mkt.name,1:2],2)
+        dn.beta.alt <- round(summary(x.alt$Dn)$sum.list[[assets.name]]$coefficients[mkt.name,1:2],2)
+        up.beta.alt <- paste(as.character(up.beta.alt)[1]," (",as.character(up.beta.alt)[2],")",sep="")
+        dn.beta.alt <- paste(as.character(dn.beta.alt)[1]," (",as.character(dn.beta.alt)[2],")",sep="")
+                
+      }
+      
+      if (add.legend){
+        
+        if (LSnRob){
+            if (x$call$fit.method=="Robust") {
+                beta.legend = c("Up Beta","Dn Beta","Up BetaRob","Dn BetaRob")
+            } else {
+                beta.legend = c("Up BetaRob","Dn BetaRob","Up Beta","Dn Beta")
+            }
+          legend.txt = c(beta.legend,up.beta,dn.beta,up.beta.alt,dn.beta.alt)                          
+          legend(legend.loc,legend=legend.txt,ncol=2,cex=legend.cex,bty="n")
+        } else {
+            if (x$Up$fit.method=="Robust") {
+            beta.legend = c("Up BetaRob","Dn BetaRob")
+          } else {
+            beta.legend = c("Up Beta","Dn Beta")
+          }
+          legend.txt = c(beta.legend,up.beta,dn.beta)                          
+          legend(legend.loc,legend=legend.txt,ncol=2,cex=legend.cex,bty="n")
+        }
+        # legend.lty = c(line.type,NA,NA,line.type,NA,NA) 
+        #  legend.col = c(line.col,NA,NA,line.col,NA,NA)
+         # legend(legend.loc,legend=legend.txt,ncol=2,lty=legend.lty,col=legend.col,cex=legend.cex)            
+                
+      }
+      assets.name.all <- assets.name.all[-1]
+      par(ask=TRUE)
+    }
+  # turn it back
+  par(ask=FALSE)
   }
\ No newline at end of file

Modified: pkg/FactorAnalytics/man/CornishFisher.Rd
===================================================================
--- pkg/FactorAnalytics/man/CornishFisher.Rd	2015-03-20 08:48:00 UTC (rev 3622)
+++ pkg/FactorAnalytics/man/CornishFisher.Rd	2015-03-20 19:48:33 UTC (rev 3623)
@@ -1,85 +1,86 @@
-% Generated by roxygen2 (4.0.2): do not edit by hand
-\name{dCornishFisher}
-\alias{Cornish-Fisher}
-\alias{dCornishFisher}
-\alias{pCornishFisher}
-\alias{qCornishFisher}
-\alias{rCornishFisher}
-\title{Cornish-Fisher expansion}
-\usage{
-dCornishFisher(x, n, skew, ekurt)
-
-pCornishFisher(q, n, skew, ekurt)
-
-qCornishFisher(p, n, skew, ekurt)
-
-rCornishFisher(n, sigma, skew, ekurt, seed = NULL)
-}
-\arguments{
-\item{x,q}{vector of standardized quantiles.}
-
-\item{n}{scalar; number of simulated values in random simulation, sample
-length in density, distribution and quantile functions.}
-
-\item{skew}{scalar; skewness.}
-
-\item{ekurt}{scalar; excess kurtosis.}
-
-\item{p}{vector of probabilities.}
-
-\item{sigma}{scalar standard deviation.}
-
-\item{seed}{scalar; set seed. Default is \code{NULL}.}
-}
-\value{
-\code{dCornishFisher} gives the density, \code{pCornishFisher} gives the
-distribution function, \code{qCornishFisher} gives the quantile function,
-and \code{rCornishFisher} generates \code{n} random simulations.
-}
-\description{
-Density, distribution function, quantile function and random
-generation using Cornish-Fisher approximation.
-}
-\details{
-CDF(q) = Pr(sqrt(n)*(x_bar-mu)/sigma < q)
-\code{dCornishFisher} Computes Cornish-Fisher density from two term Edgeworth
-expansion given mean, standard deviation, skewness and excess kurtosis.
-\code{pCornishFisher} Computes Cornish-Fisher CDF from two term Edgeworth
-expansion given mean, standard deviation, skewness and excess kurtosis.
-\code{qCornishFisher} Computes Cornish-Fisher quantiles from two term
-Edgeworth expansion given mean, standard deviation, skewness and excess
-kurtosis.
-\code{rCornishFisher} simulates observations based on Cornish-Fisher quantile
-expansion given mean, standard deviation, skewness and excess kurtosis.
-}
-\examples{
-\dontrun{
-# generate 1000 observation from Cornish-Fisher distribution
-rc <- rCornishFisher(1000,1,0,5)
-hist(rc, breaks=100, freq=FALSE,
-     main="simulation of Cornish Fisher Distribution", xlim=c(-10,10))
-lines(seq(-10,10,0.1), dnorm(seq(-10,10,0.1), mean=0, sd=1), col=2)
-# compare with standard normal curve
-
-# exponential example from A.dasGupta p.188
-# x is iid exp(1) distribution, sample size = 5
-# then x_bar is Gamma(shape=5, scale=1/5) distribution
-q <- c(0,0.4,1,2)
-# exact cdf
-pgamma(q/sqrt(5)+1, shape=5, scale=1/5)
-# use CLT
-pnorm(q)
-# use edgeworth expansion
-pCornishFisher(q, n=5, skew=2, ekurt=6)
-}
-}
-\author{
-Eric Zivot and Yi-An Chen.
-}
-\references{
-DasGupta, A. (2008). Asymptotic theory of statistics and probability.
-Springer.
-Severini, T. A., (2000). Likelihood Methods in Statistics. Oxford University
-Press.
-}
-
+% Generated by roxygen2 (4.1.0): do not edit by hand
+% Please edit documentation in R/CornishFisher.R
+\name{dCornishFisher}
+\alias{Cornish-Fisher}
+\alias{dCornishFisher}
+\alias{pCornishFisher}
+\alias{qCornishFisher}
+\alias{rCornishFisher}
+\title{Cornish-Fisher expansion}
+\usage{
+dCornishFisher(x, n, skew, ekurt)
+
+pCornishFisher(q, n, skew, ekurt)
+
+qCornishFisher(p, n, skew, ekurt)
+
+rCornishFisher(n, sigma, skew, ekurt, seed = NULL)
+}
+\arguments{
+\item{x,q}{vector of standardized quantiles.}
+
+\item{n}{scalar; number of simulated values in random simulation, sample
+length in density, distribution and quantile functions.}
+
+\item{skew}{scalar; skewness.}
+
+\item{ekurt}{scalar; excess kurtosis.}
+
+\item{p}{vector of probabilities.}
+
+\item{sigma}{scalar standard deviation.}
+
+\item{seed}{scalar; set seed. Default is \code{NULL}.}
+}
+\value{
+\code{dCornishFisher} gives the density, \code{pCornishFisher} gives the
+distribution function, \code{qCornishFisher} gives the quantile function,
+and \code{rCornishFisher} generates \code{n} random simulations.
+}
+\description{
+Density, distribution function, quantile function and random
+generation using Cornish-Fisher approximation.
+}
+\details{
+CDF(q) = Pr(sqrt(n)*(x_bar-mu)/sigma < q)
+\code{dCornishFisher} Computes Cornish-Fisher density from two term Edgeworth
+expansion given mean, standard deviation, skewness and excess kurtosis.
+\code{pCornishFisher} Computes Cornish-Fisher CDF from two term Edgeworth
+expansion given mean, standard deviation, skewness and excess kurtosis.
+\code{qCornishFisher} Computes Cornish-Fisher quantiles from two term
+Edgeworth expansion given mean, standard deviation, skewness and excess
+kurtosis.
+\code{rCornishFisher} simulates observations based on Cornish-Fisher quantile
+expansion given mean, standard deviation, skewness and excess kurtosis.
+}
+\examples{
+\dontrun{
+# generate 1000 observation from Cornish-Fisher distribution
+rc <- rCornishFisher(1000,1,0,5)
+hist(rc, breaks=100, freq=FALSE,
+     main="simulation of Cornish Fisher Distribution", xlim=c(-10,10))
+lines(seq(-10,10,0.1), dnorm(seq(-10,10,0.1), mean=0, sd=1), col=2)
+# compare with standard normal curve
+
+# exponential example from A.dasGupta p.188
+# x is iid exp(1) distribution, sample size = 5
+# then x_bar is Gamma(shape=5, scale=1/5) distribution
+q <- c(0,0.4,1,2)
+# exact cdf
+pgamma(q/sqrt(5)+1, shape=5, scale=1/5)
+# use CLT
+pnorm(q)
+# use edgeworth expansion
+pCornishFisher(q, n=5, skew=2, ekurt=6)
+}
+}
+\author{
+Eric Zivot and Yi-An Chen.
+}
+\references{
+DasGupta, A. (2008). Asymptotic theory of statistics and probability.
+Springer.
+Severini, T. A., (2000). Likelihood Methods in Statistics. Oxford University
+Press.
+}
+

Modified: pkg/FactorAnalytics/man/fitSfm.Rd
===================================================================
--- pkg/FactorAnalytics/man/fitSfm.Rd	2015-03-20 08:48:00 UTC (rev 3622)
+++ pkg/FactorAnalytics/man/fitSfm.Rd	2015-03-20 19:48:33 UTC (rev 3623)
@@ -1,179 +1,180 @@
-% Generated by roxygen2 (4.0.2): do not edit by hand
-\name{fitSfm}
-\alias{coef.sfm}
-\alias{fitSfm}
-\alias{fitted.sfm}
-\alias{residuals.sfm}
-\title{Fit a statistical factor model using principal component analysis}
-\usage{
-fitSfm(data, k = 1, max.k = NULL, refine = TRUE, sig = 0.05,
-  check = FALSE, corr = FALSE, ...)
-
-\method{coef}{sfm}(object, ...)
-
-\method{fitted}{sfm}(object, ...)
-
-\method{residuals}{sfm}(object, ...)
-}
-\arguments{
-\item{data}{vector, matrix, data.frame, xts, timeSeries or zoo object with
-asset returns. See details.}
-
-\item{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.}
-
-\item{max.k}{scalar; the maximum number of factors to be considered for
-methods "bn" or "ck". Default is \code{NULL}. See details.}
-
-\item{refine}{logical; whether to use the Connor-Korajczyk refinement for
-APCA. Default is \code{TRUE}.}
-
-\item{sig}{scalar; desired level of significance when "ck" method is
-specified. Default is 0.05.}
-
-\item{check}{logical; to check if any asset has identical observations.
-Default is \code{FALSE}.}
-
-\item{corr}{logical; whether to use the correlation instead of the covariance
-matrix when finding the principal components. Default is \code{FALSE}.}
-
-\item{...}{optional arguments passed to \code{\link[stats]{lm}}.}
-
-\item{object}{a fit object of class \code{sfm} which is returned by
-\code{fitSfm}}
-}
-\value{
-fitTsfm returns an object of class \code{"sfm"} for which
-\code{print}, \code{plot}, \code{predict} and \code{summary} methods exist.
-
-The generic accessor functions \code{coef}, \code{fitted} and
-\code{residuals} extract various useful features of the fit object.
-Additionally, \code{fmCov} computes the covariance matrix for asset returns
-based on the fitted factor model
-
-An object of class \code{"sfm"} is a list containing the following
-components:
-\item{asset.fit}{fitted object of class \code{"mlm"} or \code{"lm"} from the
-time-series LS regression of asset returns on estimated factors.}
-\item{k}{number of factors; as input or determined by "ck" or "bn" methods.}
-\item{factors}{T x K xts object of estimated factor realizations.}
-\item{loadings}{N x K matrix of factor loadings estimated by
-regressing the asset returns on estimated factors.}
-\item{alpha}{length-N vector of estimated alphas.}
-\item{r2}{length-N vector of R-squared values.}
-\item{resid.sd}{length-N vector of residual standard deviations.}
-\item{residuals}{T x N xts object of residuals from the LS regression.}
-\item{Omega}{N x N return covariance matrix estimated by the factor model.}
-\item{eigen}{length-N (or length-T for APCA) vector of eigenvalues of the
-sample covariance matrix.}
-\item{mimic}{N x K matrix of factor mimicking portfolio weights.}
-\item{call}{the matched function call.}
-\item{data}{T x N xts data object containing the asset returns.}
-\item{asset.names}{length-N vector of column names from data.}
-Where N is the number of assets, K is the number of factors, and T is the
-number of observations.
-}
-\description{
-Fits a statistical factor model using Principal Component
-Analysis (PCA) for one or more asset returns or excess returns. When the
-number of assets exceeds the number of time periods, Asymptotic Principal
-Component Analysis (APCA) is performed. An object of class \code{"sfm"} is
-returned. This function is based on the S+FinMetric function \code{mfactor}.
-}
-\details{
-If \code{data} is not of class \code{"xts"}, rownames must provide an
-\code{"xts"} compatible time index. Before model fitting, incomplete cases in
-\code{data} are removed using \code{\link[stats]{na.omit}}. Specifying
-\code{check=TRUE}, issues a warning if any asset is found to have identical
-observations.
-
-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.
-
-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.
-
-\code{refine} specifies whether a refinement of the APCA procedure from
-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
-typically decided by practioners on a case-by-case basis. The variable with
-the highest variance dominates the PCA when the covariance matrix is used.
-However, this may be justified if a volatile asset is more interesting for
-some reason and volatility information shouldn't be discarded. On the other
-hand, using the correlation matrix standardizes the variables and makes them
-comparable, avoiding penalizing variables with less dispersion.
-
-Finally, if the median of the 1st principal component is negative, all it's
-factor realizations are automatically inverted to enable more meaningful
-interpretation.
-}
-\examples{
-# load return data
-data(StockReturns)
-
-# PCA is performed on r.M and APCA on r.W
-class(r.M)
-dim(r.M)
-range(rownames(r.M))
-class(r.W)
-dim(r.W)
-
-# PCA
-args(fitSfm)
-fit.pca <- fitSfm(r.M, k=2)
-class(fit.pca)
-names(fit.pca)
-head(fit.pca$factors)
-head(fit.pca$loadings)
-fit.pca$r2
-fit.pca$resid.sd
-fit.pca$mimic
-
-# APCA with number of factors, k=15
-fit.apca <- fitSfm(r.W, k=15, refine=TRUE)
-
-# APCA with the Bai & Ng method
-fit.apca.bn <- fitSfm(r.W, k="bn")
-
-# APCA with the Connor-Korajczyk method
-fit.apca.ck <- fitSfm(r.W, k="ck")
-}
-\author{
-Eric Zivot, Sangeetha Srinivasan and Yi-An Chen
-}
-\references{
-Bai, J., & Ng, S. (2002). Determining the number of factors in approximate
-factor models. Econometrica, 70(1), 191-221.
-
-Connor, G., & Korajczyk, R. A. (1988). Risk and return in an equilibrium
-APT: Application of a new test methodology. Journal of Financial Economics,
-21(2), 255-289.
-
-Connor, G., & Korajczyk, R. A. (1993). A test for the number of factors in
-an approximate factor model. The Journal of Finance, 48(4), 1263-1291.
-
-Zivot, E., & Wang, J. (2007). Modeling Financial Time Series with S-PLUS
-(Vol. 191). Springer.
-}
-\seealso{
-The \code{sfm} methods for generic functions:
-\code{\link{plot.sfm}}, \code{\link{predict.sfm}},
-\code{\link{print.sfm}} and \code{\link{summary.sfm}}.
-
-And, the following extractor functions: \code{\link[stats]{coef}},
-\code{\link[stats]{fitted}}, \code{\link[stats]{residuals}},
-\code{\link{fmCov}}, \code{\link{fmSdDecomp}}, \code{\link{fmVaRDecomp}}
-and \code{\link{fmEsDecomp}}.
-
-\code{\link{paFm}} for Performance Attribution.
-}
-
+% Generated by roxygen2 (4.1.0): do not edit by hand
+% Please edit documentation in R/fitSfm.R
+\name{fitSfm}
+\alias{coef.sfm}
+\alias{fitSfm}
+\alias{fitted.sfm}
+\alias{residuals.sfm}
+\title{Fit a statistical factor model using principal component analysis}
+\usage{
+fitSfm(data, k = 1, max.k = NULL, refine = TRUE, sig = 0.05,
+  check = FALSE, corr = FALSE, ...)
+
+\method{coef}{sfm}(object, ...)
+
+\method{fitted}{sfm}(object, ...)
+
+\method{residuals}{sfm}(object, ...)
+}
+\arguments{
+\item{data}{vector, matrix, data.frame, xts, timeSeries or zoo object with
+asset returns. See details.}
+
+\item{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.}
+
+\item{max.k}{scalar; the maximum number of factors to be considered for
+methods "bn" or "ck". Default is \code{NULL}. See details.}
+
+\item{refine}{logical; whether to use the Connor-Korajczyk refinement for
+APCA. Default is \code{TRUE}.}
+
+\item{sig}{scalar; desired level of significance when "ck" method is
+specified. Default is 0.05.}
+
+\item{check}{logical; to check if any asset has identical observations.
+Default is \code{FALSE}.}
+
+\item{corr}{logical; whether to use the correlation instead of the covariance
+matrix when finding the principal components. Default is \code{FALSE}.}
+
+\item{...}{optional arguments passed to \code{\link[stats]{lm}}.}
+
+\item{object}{a fit object of class \code{sfm} which is returned by
+\code{fitSfm}}
+}
+\value{
+fitTsfm returns an object of class \code{"sfm"} for which
+\code{print}, \code{plot}, \code{predict} and \code{summary} methods exist.
+
+The generic accessor functions \code{coef}, \code{fitted} and
+\code{residuals} extract various useful features of the fit object.
+Additionally, \code{fmCov} computes the covariance matrix for asset returns
+based on the fitted factor model
+
+An object of class \code{"sfm"} is a list containing the following
+components:
+\item{asset.fit}{fitted object of class \code{"mlm"} or \code{"lm"} from the
+time-series LS regression of asset returns on estimated factors.}
+\item{k}{number of factors; as input or determined by "ck" or "bn" methods.}
+\item{factors}{T x K xts object of estimated factor realizations.}
+\item{loadings}{N x K matrix of factor loadings estimated by
+regressing the asset returns on estimated factors.}
+\item{alpha}{length-N vector of estimated alphas.}
+\item{r2}{length-N vector of R-squared values.}
+\item{resid.sd}{length-N vector of residual standard deviations.}
+\item{residuals}{T x N xts object of residuals from the LS regression.}
+\item{Omega}{N x N return covariance matrix estimated by the factor model.}
+\item{eigen}{length-N (or length-T for APCA) vector of eigenvalues of the
+sample covariance matrix.}
+\item{mimic}{N x K matrix of factor mimicking portfolio weights.}
+\item{call}{the matched function call.}
+\item{data}{T x N xts data object containing the asset returns.}
+\item{asset.names}{length-N vector of column names from data.}
+Where N is the number of assets, K is the number of factors, and T is the
+number of observations.
+}
+\description{
+Fits a statistical factor model using Principal Component
+Analysis (PCA) for one or more asset returns or excess returns. When the
+number of assets exceeds the number of time periods, Asymptotic Principal
+Component Analysis (APCA) is performed. An object of class \code{"sfm"} is
+returned. This function is based on the S+FinMetric function \code{mfactor}.
+}
+\details{
+If \code{data} is not of class \code{"xts"}, rownames must provide an
+\code{"xts"} compatible time index. Before model fitting, incomplete cases in
+\code{data} are removed using \code{\link[stats]{na.omit}}. Specifying
+\code{check=TRUE}, issues a warning if any asset is found to have identical
+observations.
+
+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.
+
+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.
+
+\code{refine} specifies whether a refinement of the APCA procedure from
+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
+typically decided by practioners on a case-by-case basis. The variable with
[TRUNCATED]

To get the complete diff run:
    svnlook diff /svnroot/returnanalytics -r 3623


More information about the Returnanalytics-commits mailing list