REITs for Everybody

[This article was first published on Timely Portfolio, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

THIS IS NOT INVESTMENT ADVICE.  IT IS SIMPLY MY OPINION.  LISTENING TO MY OPINION MIGHT LOSE LOTS OF MONEY.

I contend that REITs now have two buyers: dividend pickers and beta chasers.  The beta chasers’ demand has driven prices to significantly overvalued levels considering relative and absolute yields.

As a quick break from my quantstrat fun A Quantstrat to Build on Part 5, I thought I would try to replicate in R some of the fine work done by The Aleph Blog on REITs How to Make More Returns on REITs.  Unfortunately, I will not be able to finish before I head home for the weekend, so I will just show the start of the project in this post and hope to finish this weekend or Monday.

From TimelyPortfolio

R code (click to download):

require(quantmod)
require(PerformanceAnalytics)
require(stringr)   #get NAREIT data
require(gdata) 
URL <- "http://returns.reit.com/returns/MonthlyHistoricalReturns.xls"
reitData <- read.xls(URL,sheet="Data",pattern="All REITs",stringsAsFactors=FALSE)   #shift colnames over 1
colnames(reitData) <- colnames(reitData)[c(1,1:(NCOL(reitData)-1))]   #get dates and return columns
reitData <- reitData[,c(1,3,24,38)]
#name columns
colnames(reitData) <- c("Date",paste(colnames(reitData)[2:4],".Total.Return",sep=""))
reitData <- reitData[3:NROW(reitData),]
#get in format we can use with xts
datetoformat <- reitData[,1]
datetoformat <- paste(substr(datetoformat,1,3),"-01-",substr(datetoformat,5,6),sep="")
datetoformat <- as.Date(datetoformat,format="%b-%d-%y")
rownames(reitData) <- datetoformat
#eliminate column 2
reitData<-reitData[,2:NCOL(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=datetoformat)   chart.TimeSeries(reitData,ylog=TRUE,legend.loc="topleft",main="NAREIT REIT Monthly Performance")

To leave a comment for the author, please follow the link and comment on their blog: Timely Portfolio.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)