[Returnanalytics-commits] r3469 - in pkg/FactorAnalytics: data man sandbox

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Jul 9 22:49:39 CEST 2014


Author: gyollin
Date: 2014-07-09 22:49:39 +0200 (Wed, 09 Jul 2014)
New Revision: 3469

Modified:
   pkg/FactorAnalytics/data/CommonFactors.RData
   pkg/FactorAnalytics/man/CommonFactors.Rd
   pkg/FactorAnalytics/sandbox/getCommomFactor.r
Log:
Data for common factors updated

Modified: pkg/FactorAnalytics/data/CommonFactors.RData
===================================================================
(Binary files differ)

Modified: pkg/FactorAnalytics/man/CommonFactors.Rd
===================================================================
--- pkg/FactorAnalytics/man/CommonFactors.Rd	2014-07-09 06:46:28 UTC (rev 3468)
+++ pkg/FactorAnalytics/man/CommonFactors.Rd	2014-07-09 20:49:39 UTC (rev 3469)
@@ -1,39 +1,37 @@
 \name{CommonFactors}
 \alias{CommonFactors}
-\alias{factors}
+\alias{factors.M}
 \alias{factors.Q}
 \docType{data}
 \title{
 Factor set of several commonly used factors
 }
 \description{
-10 monthly and quarterly common factors xts data from 1997-01-31 to 2013-07-31. 
+Collection of common factors as both monthly and quarterly time series
 \itemize{
-\item SP500 is SP500 returns from FRED,
-\item GS10TR US Treasury 10y yields total returns from the yeild of the 10 year constant maturity from FRED,
-\item USD.Index Trade Weighted U.S. Dollar Index: Major Currencies - TWEXMMTH. from FRED
-\item Term.Spread Yield spread of Merrill Lynch High-Yield Corporate Master II Index minus 10-year Treasury. from FRED
-\item TED.Spread 3-Month Treasury Bill: Secondary Market Rate(TB3MS) - 3-Month Eurodollar Deposit Rate (London) (MED)3. from FRED.
-\item DJUBSTR DJUBS Commodities index.
-\item dVIX the first difference of the end-of-month value of the CBOE Volatility Index (VIX).
-\item OILPRICE ""OILPRICE" from FRED.
-\item TB3MS 3-Month Treasury Bill: Secondary Market Rate(TB3MS) from FRED
+\item SP500: S&P 500 composite index returns. (Yahoo)
+\item GS10TR: US Treasury 10y yields total returns from the yeild of the 10 year constant maturity. (FRED)
+\item USD.Index: Trade Weighted U.S. Dollar Index: Major Currencies - TWEXMMTH. (FRED)
+\item Term.Spread: Yield spread of Merrill Lynch High-Yield Corporate Master II Index minus 10-year Treasury. (FRED)
+\item TED.Spread: 3-Month Treasury Bill: Secondary Market Rate(TB3MS) - 3-Month Eurodollar Deposit Rate (MED3). (FRED)
+\item dVIX: First difference of the end-of-month value of the CBOE Volatility Index (VIX). (Yahoo)
+\item OILPRICE: Monthly returns of spot price of West Texas Intermediate. (FRED)
+\item TB3MS: 3-Month Treasury Bill Secondary Market Rate (TB3MS). (FRED)
 }
 
 }
 \usage{data(CommonFactors)}
 \format{
-  A data frame with 0 observations on the following 2 variables.
+  xts time series object
   \describe{
-    \item{\code{x}}{a numeric vector}
-    \item{\code{y}}{a numeric vector}
+    \item{\code{factor.M}}{Jan-1997 through May-2014}
+    \item{\code{factor.Q}}{Q1-1997 through Q1-2014}
   }
 }
 \source{
 \itemize{
-\item FRED
-\item http://www.djindexes.com/mdsidx/downloads/xlspages/ubsci_public/DJUBS_full_hist.xls
-\item http://www.cboe.com/publish/ScheduledTask/MktData/datahouse/vixarchive.xls
+\item Federal Reserve Economic Data (FRED):  \url{http://research.stlouisfed.org/fred2/}
+\item Yahoo Finance: \url{http://finance.yahoo.com/}
 }
 }
 

Modified: pkg/FactorAnalytics/sandbox/getCommomFactor.r
===================================================================
--- pkg/FactorAnalytics/sandbox/getCommomFactor.r	2014-07-09 06:46:28 UTC (rev 3468)
+++ pkg/FactorAnalytics/sandbox/getCommomFactor.r	2014-07-09 20:49:39 UTC (rev 3469)
@@ -1,7 +1,8 @@
+rm(list=ls())
 # Acquire data for factors
 
 # Script downloads, parses, and transforms data for a small set
-# of common factors to be included as example data within 
+# of common factors to be included as example data within
 # FactorAnalytics.  For more information, see the help file
 # for ?factors
 
@@ -11,6 +12,7 @@
 require(gdata)
 require(quantmod)
 require(RQuantLib)
+require(XLConnect)
 
 ## Factor set of several commonly used factors
 
@@ -18,8 +20,8 @@
 # @TODO: Find a source for TR of SP500
 
 # setup perl
-perl = "C:/Program Files/MATLAB/R2010b/sys/perl/win32/bin/perl.exe"
-setwd("C:/Users/Yi-An Chen/Documents/R-project/R FA project")
+#perl = "C:/Program Files/MATLAB/R2010b/sys/perl/win32/bin/perl.exe"
+#setwd("C:/Users/Yi-An Chen/Documents/R-project/R FA project")
 
 ### Equities
 # Get S&P price returns from FRED for now, TR later
@@ -34,7 +36,7 @@
 colnames(SP500.Q.R)="SP500"
 
 ### Bonds
-# Calculate total returns from the yeild of the 10 year constant maturity 
+# Calculate total returns from the yeild of the 10 year constant maturity
 # index maintained by the Fed
 getSymbols("GS10", src="FRED") #load US Treasury 10y yields from FRED
 # Dates should be end of month, not beginning of the month as reported
@@ -99,7 +101,8 @@
 # Download the most recent file
 print("Downloading excel spreadsheet from DJUBS web site...")
 # Can't get it directly, sorry windows users
-system("wget http://www.djindexes.com/mdsidx/downloads/xlspages/ubsci_public/DJUBS_full_hist.xls")
+#system("wget http://www.djindexes.com/mdsidx/downloads/xlspages/ubsci_public/DJUBS_full_hist.xls")
+download.file(url="http://www.djindexes.com/mdsidx/downloads/xlspages/ubsci_public/DJUBS_full_hist.xls",destfile="DJUBS_full_hist.xls",mode = "wb")
 if(!file.exists("DJUBS_full_hist.xls"))
   stop(paste("No spreadsheet exists.  Download the spreadsheet to be processed from www.djindexes.com into ", filesroot, "/.incoming", sep=""))
 
@@ -107,8 +110,12 @@
 print("Reading sheet... This will take a moment...")
 
 
-x = read.xls("DJUBS_full_hist.xls", sheet="Total Return",perl=perl)
-x=x[-1:-2,] # Get rid of the headings  
+#x = read.xls("DJUBS_full_hist.xls", sheet="Total Return",perl=perl)
+x <- readWorksheetFromFile("DJUBS_full_hist.xls", sheet = "Total Return",
+    header = FALSE, startCol = 1, startRow = 4,
+    endCol = 0, endRow = 0, check.names=FALSE)
+
+x=x[-1:-3,] # Get rid of the headings
 x=x[-dim(x)[1],] # Get rid of the last line, which contains the disclaimer
 ISOdates = as.Date(x[,1], "%m/%d/%Y") # Get dates
 
@@ -123,13 +130,13 @@
 # @ TODO Want to delete the last line off ONLY IF the month is incomplete
 #  if(tail(index(x.xts),1) != as.Date(as.yearmon(tail(index(x.xts),1)), frac=1)) {
 # That test isn't quite right, but its close.  It won't work on the first
-# day of a new month when the last business day wasn't the last day of 
+# day of a new month when the last business day wasn't the last day of
 # the month.  It will work for the second day.
 #     x.m.xts = x.m.xts[-dim(x.m.xts)[1],]
 #   }
 
-# Index is set to last trading day of the month.  
-# Reset index to last day of the month to make alignment easier with other monthly series.  
+# Index is set to last trading day of the month.
+# Reset index to last day of the month to make alignment easier with other monthly series.
 index(x.m.xts)=as.Date(index(x.m.xts), frac=1)
 index(x.q.xts)=as.Date(index(x.q.xts), frac=1)
 DJUBS.R = x.m.xts
@@ -145,8 +152,11 @@
 # Daily from 1990-2003
 
 
-x= read.xls( "http://www.cboe.com/publish/ScheduledTask/MktData/datahouse/vixarchive.xls",
-             perl = perl)
+#x= read.xls( "http://www.cboe.com/publish/ScheduledTask/MktData/datahouse/vixarchive.xls",perl = perl)
+download.file(url="http://www.cboe.com/publish/ScheduledTask/MktData/datahouse/vixarchive.xls",destfile="vixarchive.xls",mode = "wb")
+x <- readWorksheetFromFile("vixarchive.xls", sheet = 1,
+    header = FALSE, startCol = 1, startRow = 3,
+    endCol = 0, endRow = 0, check.names=FALSE)
 ISOdates = as.Date(x[,1], "%m/%d/%y") # Get dates
 x.xts = as.xts(as.numeric(as.vector(x[,5])), order.by=ISOdates)
 x.m.xts = to.monthly(x.xts)
@@ -183,11 +193,16 @@
 index(OIL.Q.R) = as.Date(as.yearqtr(index(OIL.Q.R)), frac=1)
 
 ### PUT
-system("wget https://www.cboe.com/micro/put/PUT_86-06.xls")
-setwd("C:/Users/Yi-An Chen/Documents/R-project/R FA project")
-x = read.xls("PUT_86-06.xls",perl=perl)
-x=na.omit(x[-1:-4,1:2])
-ISOdates = as.Date(x[,1], "%d-%b-%Y") # Get dates
+#system("wget https://www.cboe.com/micro/put/PUT_86-06.xls")
+download.file(url="http://www.cboe.com/micro/put/PUT_86-06.xls",destfile="PUT_86-06.xls",mode="wb")
+#setwd("C:/Users/Yi-An Chen/Documents/R-project/R FA project")
+#x = read.xls("PUT_86-06.xls",perl=perl)
+#x = read.xls("PUT_86-06.xls",perl=perl)
+x <- readWorksheetFromFile("PUT_86-06.xls", sheet = 1,
+    header = FALSE, startCol = 1, startRow = 7,
+    endCol = 2, endRow = 0, check.names=FALSE)
+#x=na.omit(x[-1:-4,1:2])
+ISOdates = as.Date(x[,1], "%Y-%m-%d") # Get dates
 PUT1 = xts(as.numeric(as.vector(x[,2])), order.by=ISOdates)
 
 # link fails
@@ -206,10 +221,10 @@
 lastquarter=format(as.Date(as.yearqtr(Sys.Date())-.25, frac=1), "%Y-%m")
 
 
-factors=cbind(SP500.R, GS10.R, USDI.R, TERM, CREDIT, DJUBS.R, dVIX, TED, OIL.R, TB3MS/100)
-factors=factors["1997::",]
-factors.Q=cbind(SP500.Q.R, GS10.Q.R, USDI.Q.R, TERM.Q, CREDIT.Q, DJUBS.Q.R, dVIX.Q, TED.Q, OIL.Q.R, TB3MS[endpoints(TB3MS, on="quarters"),]/100)
-factors.Q=factors.Q[paste("1997::",lastquarter,sep=""),]
+factorsM=cbind(SP500.R, GS10.R, USDI.R, TERM, CREDIT, DJUBS.R, dVIX, TED, OIL.R, TB3MS/100)
+factorsM=factorsM["1997::",]
+factorsQ=cbind(SP500.Q.R, GS10.Q.R, USDI.Q.R, TERM.Q, CREDIT.Q, DJUBS.Q.R, dVIX.Q, TED.Q, OIL.Q.R, TB3MS[endpoints(TB3MS, on="quarters"),]/100)
+factorsQ=factorsQ[paste("1997::",lastquarter,sep=""),]
 
 setwd("C:/Users/Yi-An Chen/Documents/R-project/returnanalytics/pkg/FactorAnalytics/data")
-save(factors,factors.Q,file="CommomFactors.RData")
\ No newline at end of file
+save(factors,factorsQ,file="CommomFactors.RData")



More information about the Returnanalytics-commits mailing list