[Introcompfinr-commits] r17 - in pkg/IntroCompFinR: . R man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Wed Mar 4 21:15:02 CET 2015
Author: bethanyyollin
Date: 2015-03-04 21:15:02 +0100 (Wed, 04 Mar 2015)
New Revision: 17
Added:
pkg/IntroCompFinR/R/fourPanelPlot.R
pkg/IntroCompFinR/man/fourPanelPlot.Rd
Modified:
pkg/IntroCompFinR/DESCRIPTION
pkg/IntroCompFinR/NAMESPACE
Log:
Added fourPanelPlot.R and function documentation. Changed imports in DESCRIPTION to include PerfomanceAnalytics (for use of checkData in fourPanelPlot.R).
Modified: pkg/IntroCompFinR/DESCRIPTION
===================================================================
--- pkg/IntroCompFinR/DESCRIPTION 2015-03-02 20:17:45 UTC (rev 16)
+++ pkg/IntroCompFinR/DESCRIPTION 2015-03-04 20:15:02 UTC (rev 17)
@@ -11,7 +11,6 @@
Moreover, the book coming soon is also based on this package.
License: GPL-2
Depends: R (>= 2.12.2), xts
-Imports: quadprog
-Suggests: PerformanceAnalytics
+Imports: quadprog, PerformanceAnalytics
LazyLoad: yes
LazyData: true
\ No newline at end of file
Modified: pkg/IntroCompFinR/NAMESPACE
===================================================================
--- pkg/IntroCompFinR/NAMESPACE 2015-03-02 20:17:45 UTC (rev 16)
+++ pkg/IntroCompFinR/NAMESPACE 2015-03-04 20:15:02 UTC (rev 17)
@@ -2,6 +2,7 @@
export(efficient.frontier)
export(efficient.portfolio)
+export(fourPanelPlot)
export(getPortfolio)
export(globalMin.portfolio)
export(plot.Markowitz)
Added: pkg/IntroCompFinR/R/fourPanelPlot.R
===================================================================
--- pkg/IntroCompFinR/R/fourPanelPlot.R (rev 0)
+++ pkg/IntroCompFinR/R/fourPanelPlot.R 2015-03-04 20:15:02 UTC (rev 17)
@@ -0,0 +1,36 @@
+#' @title Create four-panel plot of returns
+#'
+#' @author Eric Zivot
+#'
+#' @description
+#' Four-panel plot showing histogram with normal curve overlaid, boxplot, sample ACF, and normal
+#' qq-plot. Inspired by the four-panel plot in Statistical Analysis of Financial Data with R by
+#' Rene Carmona.
+#'
+#' @param ret Single data object (xts, zoo, matrix, data.frame) of returns. It is assumed that the
+#' column has a name
+#'
+#' @export fourPanelPlot
+
+fourPanelPlot <-
+function(ret)
+{
+ ret = PerformanceAnalytics::checkData(ret, "matrix")
+ retName = colnames(ret)
+ ret.den = density(ret)
+ par(mfrow=c(2,2))
+ hist(ret, main=paste(retName, " monthly returns", sep=""),
+ xlab=retName, probability=T, col="cornflowerblue")
+ # overlay normal distribution on smoothed density
+ lines(ret.den$x, dnorm(ret.den$x, mean=mean(ret), sd=sd(ret)),
+ col="black", lwd=2)
+ legend(x="topleft", legend=c("Normal Curve"),
+ lty=1, col="black", lwd=2, bty="n")
+ boxplot(ret, outchar=T, col="cornflowerblue")
+ # autocorrelations
+ acf(ret, lwd=2, main="")
+ # qq plot
+ qqnorm(ret, col="cornflowerblue", pch=16)
+ qqline(ret)
+ par(mfrow=c(1,1))
+}
\ No newline at end of file
Added: pkg/IntroCompFinR/man/fourPanelPlot.Rd
===================================================================
--- pkg/IntroCompFinR/man/fourPanelPlot.Rd (rev 0)
+++ pkg/IntroCompFinR/man/fourPanelPlot.Rd 2015-03-04 20:15:02 UTC (rev 17)
@@ -0,0 +1,21 @@
+% Generated by roxygen2 (4.1.0): do not edit by hand
+% Please edit documentation in R/fourPanelPlot.R
+\name{fourPanelPlot}
+\alias{fourPanelPlot}
+\title{Create four-panel plot of returns}
+\usage{
+fourPanelPlot(ret)
+}
+\arguments{
+\item{ret}{Single data object (xts, zoo, matrix, data.frame) of returns. It is assumed that the
+column has a name}
+}
+\description{
+Four-panel plot showing histogram with normal curve overlaid, boxplot, sample ACF, and normal
+qq-plot. Inspired by the four-panel plot in Statistical Analysis of Financial Data with R by
+Rene Carmona.
+}
+\author{
+Eric Zivot
+}
+
More information about the Introcompfinr-commits
mailing list