plot.ffm: Plots from a fitted fundamental factor model

View source: R/plot.ffm.R

plot.ffmR Documentation

Plots from a fitted fundamental factor model

Description

Generic plot method for object of class ffm. Plots chosen characteristic(s) for one or more assets.

Usage

## S3 method for class 'ffm'
plot(
  x,
  which = NULL,
  f.sub = 1:2,
  a.sub = 1:6,
  plot.single = FALSE,
  asset.name,
  asset.variable,
  colorset = c("royalblue", "dimgray", "olivedrab", "firebrick", "goldenrod",
    "mediumorchid", "deepskyblue", "chocolate", "darkslategray"),
  legend.loc = "topleft",
  las = 1,
  lwd = 2,
  maxlag = 15,
  ...
)

Arguments

x

an object of class ffm produced by fitFfm.

which

a number to indicate the type of plot. If multiple plots are required, specify a subset from 1:12 for group plots and 1:13 for individual plots. If which=NULL (default), the following menu appears:

For plots of a group of assets:
1 = Distribution of factor returns,
2 = Factor exposures from the last period,
3 = Actual and Fitted asset returns,
4 = Time-series of R-squared values,
5 = Residual variance across assets, x
6 = Scatterplot matrix of residuals, with histograms, density overlays, correlations and significance stars,
7 = Factor Model Residual Correlation
8 = Factor Model Return Correlation,
9 = Factor Contribution to SD,
10 = Factor Contribution to ES,
11 = Factor Contribution to VaR,
12 = Time series of factor returns,

For individual asset plots:
1 = Actual and fitted,
2 = Actual vs. fitted,
3 = Residuals vs. fitted,
4 = Residuals with standard error bands,
5 = Time series of squared residuals,
6 = Time series of absolute residuals,
7 = SACF and PACF of residuals,
8 = SACF and PACF of squared residuals,
9 = SACF and PACF of absolute residuals,
10 = Non-parametric density of residuals with normal overlaid,
11 = Non-parametric density of residuals with skew-t overlaid,
12 = Histogram of residuals with non-parametric density and normal overlaid,
13 = QQ-plot of residuals

f.sub

numeric/character vector; subset of indexes/names of factors to include for group plots. Default is 1:2.

a.sub

numeric/character vector; subset of indexes/names of assets to include for group plots. At least 2 assets must be selected. Default is 1:6.

plot.single

logical; If TRUE plots the characteristics of an individual asset's factor model. The type of plot is given by which. Default is FALSE.

asset.name

name of the individual asset to be plotted. Is necessary if x contains multiple asset fits and plot.single=TRUE.

asset.variable

the name of asset variable.

colorset

color palette to use for all the plots. The 1st element will be used for individual time series plots or the 1st object plotted, the 2nd element for the 2nd object in the plot and so on.

legend.loc

places a legend into one of nine locations on the chart: "bottomright", "bottom", "bottomleft", "left", "topleft", "top", "topright", "right", or "center". Default is "bottomright". Use legend.loc=NULL to suppress the legend.

las

one of 0, 1, 2, 3 to set the direction of axis labels, same as in plot. Default is 1.

lwd

set the line width, same as in plot. Default is 2.

maxlag

optional number of lags to be calculated for ACF. Default is 15.

...

further arguments to be passed to other plotting functions.

Details

The function can be used for group plots and individual plots. User can select the type of plot either from the menu prompt (default) or directly via argument which.

In case multiple plots are needed, the menu is repeated after each plot (enter 0 to exit). User can also input a numeric vector of plot options via which.

Group plots are the default. The selected assets in a.sub and selected factors in f.sub are plotted depending on the characteristic chosen. The default is to show the first 2 factors and first 6 assets.

Setting plot.single=TRUE enables individual plots. If there is more than one asset fit by x, asset.name should be specified. In case the ffm object x contains only a single asset fit, plot.ffm can infer asset.name without user input.

Author(s)

Eric Zivot, Sangeetha Srinivasan and Yi-An Chen

See Also

fitFfm, residuals.ffm, fitted.ffm, fmCov.ffm and summary.ffm for time series factor model fitting and related S3 methods. Refer to fmSdDecomp, fmEsDecomp, fmVaRDecomp for factor model risk measures.

Here is a list of plotting functions used. (I=individual, G=Group) I(1,5,6,7), G(3,4,12) - chart.TimeSeries, I(2,3,4,19), G(12) - plot.default, I(3,4) - panel.smooth, I(8,9,10) - chart.ACFplus, I(11,12) - plot.density, I(13) - chart.Histogram, I(14) - chart.QQPlot, I(15,16,17) - plot.efp (requires strucchange package), I(18) - plot.zoo, G(1) - chart.Boxplot, G(2,5,9,10,11) - barchart, G(6) - chart.Correlation and G(7,8) - corrplot.mixed (requires corrplot package).

Examples


## Not run: 
# 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 with style variables BP and LogMktCap

fit.style <- 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) # Not run, but user should try it out


# plot all factor exposures from the last time period for 1st 10 assets

plot(fit.style, 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, which = 6)

# 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, plot.single = TRUE, asset.name = "ALCO", which = 12)

## End(Not run)


braverock/factorAnalytics documentation built on Dec. 16, 2024, 1:05 p.m.