[Returnanalytics-commits] r2097 - pkg/MPO/R

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Jul 2 01:21:41 CEST 2012


Author: jamesleehobbs
Date: 2012-07-02 01:21:41 +0200 (Mon, 02 Jul 2012)
New Revision: 2097

Modified:
   pkg/MPO/R/buildDataSet.R
Log:
-script used to build returns data set

Modified: pkg/MPO/R/buildDataSet.R
===================================================================
--- pkg/MPO/R/buildDataSet.R	2012-07-01 23:19:16 UTC (rev 2096)
+++ pkg/MPO/R/buildDataSet.R	2012-07-01 23:21:41 UTC (rev 2097)
@@ -4,7 +4,9 @@
 library(PerformanceAnalytics)
 
 ###TODO load from package
-file.choose()
+### market cap data from:  http://pages.stern.nyu.edu/~adamodar/New_Home_Page/data.html
+
+#yahoo is missing data from DF and DFG
 mktCap <- read.csv("N:\\School\\Summer 2012\\Data Set\\Market Cap Data\\mktCapSummary.csv",as.is=TRUE)
 classifiers <- c("class.2011","class.12yrAvg","class.2yrAvg")
 large <- 10000
@@ -24,7 +26,38 @@
   mktCap[mktCap[,1+i] <= small,classifiers[i]]   <- "micro"
 }
 
-#Test
-mktCap[mktCap[,"Ticker"]=="AAPL",]
+### Get 100 tickers by group
+groupSize <- 100
+large.tickers <- mktCap[mktCap[,"class.2011"]=="large","Ticker"][1:groupSize]
+mid.tickers <- mktCap[mktCap[,"class.2011"]=="mid","Ticker"][1:groupSize]
+small.tickers <- mktCap[mktCap[,"class.2011"]=="small","Ticker"][1:groupSize]
+micro.tickers <- mktCap[mktCap[,"class.2011"]=="micro","Ticker"][1:groupSize]
 
-###TODO Select smaller subset of tickers (~100) per group
\ No newline at end of file
+### Download Data
+start.date <- as.Date("2000-01-01")
+end.date <- as.Date("2012-06-29")
+
+
+###get symbols wrapper function
+###add documentation and option for daily or weekly returns
+getReturns <- function(symbols,...){
+  nSymbols <- length(symbols)
+  price.list <- list()
+  for (i in 1:nSymbols){
+    #download adjusted close
+    price.list[[i]]   <- getSymbols(symbols[i],auto.assign = FALSE 
+                                          ,...)[,6]
+    #keep month end price
+    price.list[[i]] <- to.monthly(price.list[[i]],indexAt="Date")[,4]
+    }
+  price.df = as.data.frame(price.list)
+  price.xts = as.xts(price.df, order.by=as.Date(rownames(price.df)))
+  returns <- Return.calculate(price.xts,method="compound")
+  names(returns) <- symbols
+  returns[-1]
+}
+
+large.cap.returns <- getReturns(large.tickers,from = start.date, to = end.date)
+mid.cap.returns <- getReturns(mid.tickers,from = start.date, to = end.date)
+small.cap.returns <- getReturns(small.tickers,from = start.date, to = end.date)
+micro.cap.returns <- getReturns(micro.tickers,from = start.date, to = end.date)



More information about the Returnanalytics-commits mailing list