Skip to content

Commit

Permalink
#69 updated plot.ffm. Other issues discovered with the function and d…
Browse files Browse the repository at this point in the history
…ocumented in #70
  • Loading branch information
JustinMShea committed Dec 13, 2021
1 parent 6b69ce8 commit a95f2a2
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 33 deletions.
61 changes: 43 additions & 18 deletions R/plot.ffm.R
Original file line number Diff line number Diff line change
Expand Up @@ -108,30 +108,46 @@
#'
#' @examples
#'
#' # load data from the database
#' data("factorDataSetDjia5Yrs")
#' # load data
#'data(stocksCRSP)
#'data(factorsSPGMI)
#'
#'stocks_factors <- selectCRSPandSPGMI(stocks = stocksCRSP, factors = factorsSPGMI,
#' dateSet = c("2006-01-31", "2010-12-31"),
#' stockItems = c("Date", "TickerLast",
#' "CapGroup", "Sector",
#' "Return", "Ret13WkBill",
#' "mktIndexCRSP"),
#' factorItems = c("BP", "LogMktCap", "SEV"),
#' capChoice = "SmallCap",
#' Nstocks = 20)
#'
#' # fit a fundamental factor model
#' exposure.vars <- c("P2B", "MKTCAP")
#' fit.style.sector <- fitFfm(data=factorDataSetDjia5Yrs, asset.var="TICKER",
#' ret.var="RETURN", date.var="DATE",
#' exposure.vars=exposure.vars)
#'
#' # 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.style.sector)
#'
#' fit.style.sector <- fitFfm(data = stocks_factors,
#' asset.var = "TickerLast",
#' ret.var = "Return",
#' date.var = "Date",
#' exposure.vars = c("BP", "LogMktCap")
#' )
#'
#' # For group plots (default), one can select plot option from prompt menu.
#' # The menu is repeated to produce multiple plots based on the same fit
#'
#' plot(fit.style.sector)
#'
#' # choose specific plot option(s) using which
#' # plot all factor exposures from the last time period for 1st 10 assets
#' plot(fit.style.sector, which=2, f.sub=1:2, a.sub=1:10)
#'
#' plot(fit.style.sector, which = 2, f.sub = 1:2, a.sub = 1:10)
#'
#' # plot factor model residuals scatterplot matrix, with histograms, density
#' # overlays, correlations and significance stars
#' plot(fit.style.sector, which=6)
#' plot(fit.style.sector, 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.style.sector, plot.single=TRUE, asset.name="AA", which=12)
#' # For individual plots: define `plot.single=TRUE` and specify `asset.name`.
#' # This will display a histogram of residuals from the asset's factor model fit
#'
#' plot(fit.style.sector, plot.single = TRUE, asset.name = "ALCO", which = 12)
#'
#' @method plot ffm
#' @export
Expand Down Expand Up @@ -378,8 +394,17 @@ plot.ffm <- function(x, which=NULL, f.sub=1:2, a.sub=1:6,
plotData <- merge.xts(asset.ret.xts, fitted.ret)
colnames(plotData) <- c("Actual","Fitted")
main <- paste("Actual and Fitted:", asset)
PerformanceAnalytics::chart.TimeSeries(plotData, colorset=colorset, lwd=lwd, main=main, xlab="",
ylab="Asset returns", legend.loc=legend.loc, pch=NULL, las=las, ...)

PerformanceAnalytics::chart.TimeSeries(plotData,
colorset = colorset,
lwd = lwd,
main = main,
xlab = "",
ylab = "Asset returns",
legend.loc = legend.loc,
pch = NULL,
las = las,
...)
}
par(mfrow=c(1,1))
},
Expand Down
46 changes: 31 additions & 15 deletions man/plot.ffm.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a95f2a2

Please sign in to comment.