REITs for Everybody

June 10, 2011
By

(This article was first published on Timely Portfolio, and kindly contributed to R-bloggers)

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")

Created by Pretty R at inside-R.org

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 on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...



If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Tags: , ,

Comments are closed.

Sponsors

Mango solutions



RStudio homepage



Zero Inflated Models and Generalized Linear Mixed Models with R

Quantide: statistical consulting and training



http://www.eoda.de







ODSC

ODSC

CRC R books series











Contact us if you wish to help support R-bloggers, and place your banner here.

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)