[Returnanalytics-commits] r3861 - in pkg/Dowd: . R man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Jul 28 10:03:33 CEST 2015


Author: dacharya
Date: 2015-07-28 10:03:33 +0200 (Tue, 28 Jul 2015)
New Revision: 3861

Modified:
   pkg/Dowd/DESCRIPTION
   pkg/Dowd/NAMESPACE
   pkg/Dowd/R/PCAPrelim.R
   pkg/Dowd/man/PCAPrelim.Rd
Log:
Dependence on external package expm avoided. Simple version of function %^% was implemented.

Modified: pkg/Dowd/DESCRIPTION
===================================================================
--- pkg/Dowd/DESCRIPTION	2015-07-26 22:43:47 UTC (rev 3860)
+++ pkg/Dowd/DESCRIPTION	2015-07-28 08:03:33 UTC (rev 3861)
@@ -1,16 +1,15 @@
-Package: Dowd
-Type: Package
-Title: R-Version of MMR II Toolbox Offered in Kevin Dowd's Book Measuring Market Risk
-Version: 0.1
-Date: 2015-05-24
-Author: Dinesh Acharya <dines.acharya at gmail.com>
-Maintainer: Dinesh Acharya <dines.acharya at gmail.com>
-Description: R-version of MMR2 Toolbox that supplements
-          Kevin Dowd's book Measuring Market Risk.
-Depends: R (>= 3.0.0), 
-          bootstrap,
-          MASS,
-          expm
-Suggests: PerformanceAnalytics, 
-          testthat
-License: GPL
+Package: Dowd
+Type: Package
+Title: R-Version of MMR II Toolbox Offered in Kevin Dowd's Book Measuring Market Risk
+Version: 0.1
+Date: 2015-05-24
+Author: Dinesh Acharya <dines.acharya at gmail.com>
+Maintainer: Dinesh Acharya <dines.acharya at gmail.com>
+Description: R-version of MMR2 Toolbox that supplements
+          Kevin Dowd's book Measuring Market Risk.
+Depends: R (>= 3.0.0), 
+          bootstrap,
+          MASS
+Suggests: PerformanceAnalytics, 
+          testthat
+License: GPL

Modified: pkg/Dowd/NAMESPACE
===================================================================
--- pkg/Dowd/NAMESPACE	2015-07-26 22:43:47 UTC (rev 3860)
+++ pkg/Dowd/NAMESPACE	2015-07-28 08:03:33 UTC (rev 3861)
@@ -110,4 +110,3 @@
 export(TQQPlot)
 import(MASS)
 import(bootstrap)
-import(expm)

Modified: pkg/Dowd/R/PCAPrelim.R
===================================================================
--- pkg/Dowd/R/PCAPrelim.R	2015-07-26 22:43:47 UTC (rev 3860)
+++ pkg/Dowd/R/PCAPrelim.R	2015-07-28 08:03:33 UTC (rev 3861)
@@ -1,11 +1,10 @@
-#' PCAPrelim
 #' 
 #' Estimates VaR plot using principal components analysis
 #' 
 #' @param Ra Matrix return data set where each row is interpreted as a set of 
 #' daily observations, and each column as the returns to each position in a 
-#' portfolio
-#' position
+#' portfolio position
+#' 
 #' @references Dowd, K. Measuring Market Risk, Wiley, 2007.
 #'
 #' @author Dinesh Acharya
@@ -15,11 +14,10 @@
 #'    # This code was based on Dowd's code and similar to Dowd's code,
 #'    # it is inconsistent for non-scalar data (Ra).
 #'    library(MASS)
-#'    library(expm)
 #'    Ra <- .15
 #'    PCAPrelim(Ra)
 #'
-#' @import expm MASS
+#' @import MASS
 #'
 #' @export
 PCAPrelim <- function(Ra){
@@ -69,3 +67,12 @@
   title("Explanatory Power of the Principal Components")
   
 }
+
+# ------------------------------ Helper function ------------------------------
+# Matrix exponentiation
+"%^%" <- function(S, power) {
+  # Uses eigenvalue decomposition A = PDP^-1 for matrix exponentiation.
+  # Also see expm package for larger matrices for efficiency.
+  y <- with(eigen(S), vectors %*% (values^power * solve(vectors)))
+  return(y)
+}
\ No newline at end of file

Modified: pkg/Dowd/man/PCAPrelim.Rd
===================================================================
--- pkg/Dowd/man/PCAPrelim.Rd	2015-07-26 22:43:47 UTC (rev 3860)
+++ pkg/Dowd/man/PCAPrelim.Rd	2015-07-28 08:03:33 UTC (rev 3861)
@@ -9,8 +9,7 @@
 \arguments{
 \item{Ra}{Matrix return data set where each row is interpreted as a set of
 daily observations, and each column as the returns to each position in a
-portfolio
-position}
+portfolio position}
 }
 \description{
 Estimates VaR plot using principal components analysis
@@ -20,7 +19,6 @@
    # This code was based on Dowd's code and similar to Dowd's code,
    # it is inconsistent for non-scalar data (Ra).
    library(MASS)
-   library(expm)
    Ra <- .15
    PCAPrelim(Ra)
 }



More information about the Returnanalytics-commits mailing list