[Returnanalytics-commits] r2522 - pkg/PerformanceAnalytics/sandbox/Shubhankit/Week2

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Jul 8 21:19:58 CEST 2013


Author: shubhanm
Date: 2013-07-08 21:19:58 +0200 (Mon, 08 Jul 2013)
New Revision: 2522

Added:
   pkg/PerformanceAnalytics/sandbox/Shubhankit/Week2/table.ComparitiveReturn.GLM.R
Log:
Week 2: Table for Comparative Analysis of Smooth and Unsmooth Returns for GLM Model

Added: pkg/PerformanceAnalytics/sandbox/Shubhankit/Week2/table.ComparitiveReturn.GLM.R
===================================================================
--- pkg/PerformanceAnalytics/sandbox/Shubhankit/Week2/table.ComparitiveReturn.GLM.R	                        (rev 0)
+++ pkg/PerformanceAnalytics/sandbox/Shubhankit/Week2/table.ComparitiveReturn.GLM.R	2013-07-08 19:19:58 UTC (rev 2522)
@@ -0,0 +1,76 @@
+#' Compenent Decomposition of Table of Unsmooth Returns for GLM Model
+#' 
+#' Creates a table of comparitive changes in Normality Properties for Third
+#' and Fourth Moment Vectors i.e. Skewness and Kurtosis for Orignal and Unsmooth 
+#' Returns Respectively
+#' 
+#' @param R an xts, vector, matrix, data frame, timeSeries or zoo object of
+#' asset returns
+#' @param ci confidence interval, defaults to 95\%
+#' @param n number of series lags
+#' @param digits number of digits to round results to
+#' @author R
+#' @keywords ts unsmooth GLM return models
+#'
+#' @export 
+table.ComparitiveReturn.GLM <-
+  function (R, n = 3, digits = 4)
+  {# @author 
+    
+    # DESCRIPTION:
+    # Downside Risk Summary: Statistics and Stylized Facts
+    
+    # Inputs:
+    # R: a regular timeseries of returns (rather than prices)
+    # n : Number of lags
+    # p = Confifence Level
+    # Output:
+    # A table of estimates of Moving Average
+    
+    y = checkData(R, method = "xts")
+    columns = ncol(y)
+    rows = nrow(y)
+    columnnames = colnames(y)
+    rownames = rownames(y)
+    
+    # for each column, do the following:
+    for(column in 1:columns) {
+      x = y[,column]
+      skew = skewness(x)
+      arma.coeff= arma(x,0,n)
+      kurt= kurtosis(x)
+      z = c(skew,
+            ((sum(arma.coeff$theta^2)^1.5)*(skew/(sum(arma.coeff$theta^3)))),
+            kurt,
+             (kurt*(sum(arma.coeff$theta^2)^2)/(sum(arma.coeff$theta^4))))
+      znames = c(
+        "Skewness ( Orignal) ",
+        "Skewness (Unsmooth)",
+        "Kurtosis (Orignal)",
+        "Kurtosis (Unsmooth)")
+      if(column == 1) {
+        resultingtable = data.frame(Value = z, row.names = znames)
+      }
+      else {
+        nextcolumn = data.frame(Value = z, row.names = znames)
+        resultingtable = cbind(resultingtable, nextcolumn)
+      }
+    }
+    colnames(resultingtable) = columnnames
+    ans = base::round(resultingtable, digits)
+    ans
+    
+    
+  }
+
+###############################################################################
+# R (http://r-project.org/) 
+#
+# Copyright (c) 2004-2013 
+#
+# This R package is distributed under the terms of the GNU Public License (GPL)
+# for full details see the file COPYING
+#
+# $Id: table.ComparitiveReturn.GLM
+#
+###############################################################################



More information about the Returnanalytics-commits mailing list