public
Last active

obviousness of reits

  • Download Gist
obviousness of reits.r
R
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
#obviousness of reits?
 
#get NAREIT data
#I like NAREIT since I get back to 1971
#much easier though to get Wilshire REIT from FRED
#also it is daily instead of monthly
#getSymbols("WILLREITIND",src="FRED") will do this
require(gdata)
reitURL <- "http://returns.reit.com/returns/MonthlyHistoricalReturns.xls"
reitExcel <- read.xls(reitURL,sheet="Index Data",pattern="All REITs",stringsAsFactors=FALSE)
#clean up dates so we can use xts functionality later
datetoformat <- reitExcel[,1]
datetoformat <- paste(substr(datetoformat,1,3),"-01-",substr(datetoformat,5,6),sep="")
datetoformat <- as.Date(datetoformat,format="%b-%d-%y")
reitExcel[,1] <- datetoformat
 
#######now get the returns and clean up slightly############
require(quantmod)
require(xtsExtra)
#shift colnames over 1
colnames(reitExcel) <- colnames(reitExcel)[c(1,1:(NCOL(reitExcel)-1))]
#get return columns
reitData <- reitExcel[,c(3,24)]
#name columns
colnames(reitData) <- c("AllREITs","EquityREITs")
reitData <- reitData[3:NROW(reitData),]
#erase commas
col2cvt <- 1:NCOL(reitData)
reitData[,col2cvt] <- lapply(reitData[,col2cvt],function(x){as.numeric(gsub(",", "", x))})
#create xts
reitData <- as.xts(reitData,order.by=reitExcel[3:NROW(reitExcel),1])
#add the sp500
getSymbols("SP500",src="FRED")
SP500 <- to.monthly(SP500)[,4]
#get 1st of month to align when we merge
index(SP500) <- as.Date(index(SP500))
#merge REIT and S&p
reitSp500 <- na.omit(merge(reitData,SP500))
reitSp500 <- ROC(reitSp500,n=1,type="discrete")
#make first return 0 instead of NA
reitSp500[1,] <- 0
 
##################make some charts#########################
require(PerformanceAnalytics)
layout(matrix(c(1,2),nrow=1))
chart.RiskReturnScatter(reitSp500["2000::",],
col=c("steelblue4","steelblue2","gray50"),
main="REITS and the S&P 500 Since 2000",
xlim = c(0,0.35))
chart.RiskReturnScatter(reitSp500["1984::1999",],
col=c("steelblue4","steelblue2","gray50"),
main="REITS and the S&P 500 1984-1999",
xlim = c(0,0.25))
 
charts.PerformanceSummary(reitSp500["2000::",],
colorset =c("steelblue4","steelblue2","gray50"),
main="REITS and the S&P 500 Since 2000")
 
charts.PerformanceSummary(reitSp500["1984::1999",],
colorset =c("steelblue4","steelblue2","gray50"),
main="REITS and the S&P 500 1984-1999")

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.