| chart.Histogram {PerformanceAnalytics} | R Documentation |
Create a histogram of returns, with optional curve fits for density and normal. This is wrapper function for hist, see the help for that function for additional arguments you may wish to pass in.
chart.Histogram(R, breaks = "FD", main = NULL, xlab = "Returns", ylab = "Frequency", methods = c("add.density", "add.normal", "add.centered", "add.rug", "add.risk", "add.qqplot"), colorset = c("lightgray", "#00008F", "#005AFF", "#23FFDC", "#ECFF13", "#FF4A00", "#800000"), border.col = "white", box.col = "white", lwd = 2, xlim = NULL, darken = FALSE, ...)
R |
a vector, matrix, data frame, timeSeries or zoo object of asset returns |
breaks |
how to calculate the breaks between the bars, one of:
hist for details, default "FD"
|
methods |
|
main |
set the chart title, same as in plot |
ylab |
set the y-axis label, same as in plot |
xlab |
set the x-axis label, same as in plot |
border.col |
color to use for the border |
box.col |
color to use for the box |
xlim |
set the x-axis limit, same as in plot |
lwd |
set the line width, same as in plot |
colorset |
color palette to use, set by default to rational choices |
darken |
if true, draws the chart elements in "darkgray" rather than "gray". Makes it easier to print for some printers. |
... |
any other passthru parameters |
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.
chart of histogram of returns
Code inspired by a chart on: http://zoonek2.free.fr/UNIX/48_R/03.html
Peter Carl
#first get some data
data(edhec)
#default chart is too busy
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.centered") )
# version with just the histogram and normal distribution centered on 0
chart.Histogram(edhec[,'Equity.Market.Neutral',drop=FALSE], methods = c( "add.centered") )
# version with histogram, normal, and close fit distribtuion
chart.Histogram(edhec[,'Equity.Market.Neutral',drop=FALSE], methods = c( "add.centered", "add.density") )
# 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") )