[Uwgarp-commits] r12 - pkg/GARPFRM/sandbox

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sat Nov 23 18:01:41 CET 2013


Author: rossbennett34
Date: 2013-11-23 18:01:41 +0100 (Sat, 23 Nov 2013)
New Revision: 12

Added:
   pkg/GARPFRM/sandbox/equity_data_download.R
Log:
Adding script to download equity data

Added: pkg/GARPFRM/sandbox/equity_data_download.R
===================================================================
--- pkg/GARPFRM/sandbox/equity_data_download.R	                        (rev 0)
+++ pkg/GARPFRM/sandbox/equity_data_download.R	2013-11-23 17:01:41 UTC (rev 12)
@@ -0,0 +1,32 @@
+library(quantmod)
+
+tickers <- c("SPY", "AAPL", "XOM", "GOOG", "MSFT", "GE")
+
+# Download daily data
+getSymbols(Symbols=tickers, from="2005-01-01", to=Sys.Date())
+
+# Convert to weekly
+for(ticker in tickers) {
+  x <- get(ticker)
+  x <- to.weekly(x, indexAt='lastof')
+  indexFormat(x) <- '%Y-%m-%d'
+  colnames(x) <- gsub("x", ticker, colnames(x))
+  assign(ticker, x)
+}
+
+# Calculate the returns based on the adjusted close price and combine into a 
+# single object
+for(i in 1:length(tickers)){
+  x <- get(tickers[i])
+  x <- Ad(x)
+  x.ret <- ROC(x=x, n=1, type="discrete", na.pad=FALSE)
+  colnames(x.ret) <- tickers[i]
+  if(i == 1){
+    returns <- x.ret
+  } else {
+    returns <- cbind(returns, x.ret)
+  }
+}
+
+#save(returns, file="/Users/rossbennett/devel/R/UWGARP/uwgarp/pkg/GARPFRM/data/returns.rda")
+#save(AAPL, GE, GOOG, MSFT, SPY, XOM, file="/Users/rossbennett/devel/R/UWGARP/uwgarp/pkg/GARPFRM/data/equity_data.rda")



More information about the Uwgarp-commits mailing list