Learn R Programming

PerformanceAnalytics (version 1.0.4.4)

chart.Histogram: histogram of returns

Description

Create a histogram of returns, with optional curve fits for density and normal. This is a wrapper function for hist, see the help for that function for additional arguments you may wish to pass in.

Usage

chart.Histogram(R, breaks="FD", main = NULL, xlab = "Returns", ylab = "Frequency", methods = c("none","add.density", "add.normal", "add.centered", "add.cauchy", "add.sst", "add.rug", "add.risk", "add.qqplot"), show.outliers = TRUE, colorset = c("lightgray", "#00008F", "#005AFF", "#23FFDC", "#ECFF13", "#FF4A00", "#800000"), border.col = "white", lwd = 2, xlim = NULL, ylim = NULL, element.color="darkgray", note.lines = NULL, note.labels = NULL, note.cex = 0.7, note.color = "darkgray", probability = FALSE, p = 0.95, cex.axis = 0.8, cex.legend = 0.8, cex.lab = 1, cex.main = 1, xaxis=TRUE, yaxis=TRUE, ...)

Arguments

R
an xts, vector, matrix, data frame, timeSeries or zoo object of asset returns
breaks
one of:
  • a vector giving the breakpoints between histogram cells,
  • a single number giving the number of cells for the histogram,
  • a character string naming an algorithm to compute the number of cells (seeDetails),
methods
what to graph, one or more of:
  • add.density
{ to display the density plot} add.normal{ to display a fitted normal distibution line over the mean} add.centered{ to display a fitted normal line o

item

  • p
  • probability
  • show.outliers
  • main
  • ylab
  • xlab
  • ylim
  • border.col
  • xlim
  • lwd
  • colorset
  • element.color
  • note.lines
  • note.labels
  • note.cex
  • note.color
  • cex.legend
  • cex.axis
  • cex.lab
  • cex.main
  • xaxis
  • yaxis
  • ...

code

plot

Details

The default for breaks is "FD". Other names for which algorithms are supplied are "Sturges" (see nclass.Sturges), "Scott", and "FD" / "Freedman-Diaconis" (with corresponding functions nclass.scott and nclass.FD). Case is ignored and partial matching is used. Alternatively, a function can be supplied which will compute the intended number of breaks as a function of R.

See Also

hist

Examples

Run this code
data(edhec)
    chart.Histogram(edhec[,'Equity Market Neutral',drop=FALSE])

    # version with more breaks and the standard close fit density distribution
    chart.Histogram(edhec[,'Equity Market Neutral',drop=FALSE], breaks=40, methods = c("add.density", "add.rug") )

    chart.Histogram(edhec[,'Equity Market Neutral',drop=FALSE], methods = c( "add.density", "add.normal") )

    # version with just the histogram and normal distribution centered on 0
    chart.Histogram(edhec[,'Equity Market Neutral',drop=FALSE], methods = c( "add.density", "add.centered") )

    # add a rug to the previous plot for more granularity on precisely where the distribution fell
    chart.Histogram(edhec[,'Equity Market Neutral',drop=FALSE], methods = c( "add.centered", "add.density", "add.rug") )

    # now show a qqplot to give us another view on how normal the data are
    chart.Histogram(edhec[,'Equity Market Neutral',drop=FALSE], methods = c( "add.centered", "add.density", "add.rug", "add.qqplot") )

    # add risk measure(s) to show where those are in relation to observed returns
    chart.Histogram(edhec[,'Equity Market Neutral',drop=FALSE], methods = c("add.density", "add.centered", "add.rug", "add.risk") )

Run the code above in your browser using DataLab