Wednesday, June 22, 2011

REITs for Everybody Now REITs for Nobody Part 3

THIS IS NOT INVESTMENT ADVICE.  LISTENING TO ME COULD LOSE LOTS OF MONEY.

For some additional insight to my short REITs beliefs presented in REITs for Everybody Now REITs for Nobody Part 2 and REITs for Everybody Might Now Mean REITs for Nobody, I thought we should look at the underlying commercial real estate prices with the Moody’s/REAL CPPI indexes updated today June 22.  They generously provide the data but unfortunately in zip compressed format.  I am not sure how to automate the unzip step in R Thanks to theHausdorffMetric and –Digital Dude- for showing me how to unzip files in R.  Now, we can easily analyze the unzipped csv data in R. 

From TimelyPortfolio

On a standalone basis, the index is very ugly with a new recent downturn into new lows.

From TimelyPortfolio

Let’s see how closely REITs match underlying commercial property prices.  I don’t know about you, but something doesn’t seem quite right about these next charts.

From TimelyPortfolio
From TimelyPortfolio

R code(click to download):

require(quantmod)
require(PerformanceAnalytics)   #thanks theHausdorffMetric and -Digital Dude- for the comments
#showing how to download, unzip, and access a zip file
my.url="http://web.mit.edu/cre/research/credl/rca/MoodysREAL-2011Q1.zip"
my.tempfile<-paste(tempdir(),"\\moodys-cppi.zip",sep="")
download.file(my.url, my.tempfile, method="auto", quiet = FALSE, mode = "wb",cacheOK = TRUE)
unzip(my.tempfile,exdir = tempdir(),junkpath=TRUE)
moodyscppi <- read.csv(paste(tempdir(),"\\Monthly Returns National - All Properties.csv",sep=""))
#get date ready for xts
moodyscppi[,1] <- paste(moodyscppi[,1],
ifelse(moodyscppi[,2]<10,paste("0",moodyscppi[,2],sep=""),moodyscppi[,2]),
"01",sep="-")
moodyscppi <- as.xts(moodyscppi[,3:4],order.by=as.Date(moodyscppi[,1]))   #jpeg(filename="moodys-cppi-performance.jpg",quality=100,width=6.25, height = 5,
# units="in",res=96)
charts.PerformanceSummary(moodyscppi[,2],
main="Moody's/REAL Commercial Property Price Index")
#dev.off()   getSymbols("WILLREITIND",src="FRED") #get Wilshire REIT Total Return
getSymbols("WILLREITPR",src="FRED") #get Wilshire REIT Price
WILLREITIND <- to.monthly(WILLREITIND)[,4]
WILLREITPR <- to.monthly(WILLREITPR)[,4]
index(WILLREITIND) <- as.Date(index(WILLREITIND))
index(WILLREITPR) <- as.Date(index(WILLREITPR))
#merge returns from cppi and reit indexes
cppi_reit <- na.omit(merge(moodyscppi[,2],
ROC(WILLREITIND,n=1,type="discrete"),
ROC(WILLREITPR,n=1,type="discrete")))
colnames(cppi_reit) <- c("Moodys/REAL CPPI",
"Wilshire REIT Total Return","Wilshire REIT Price")
#jpeg(filename="moodys-cppi-reit.jpg",quality=100,width=6.25, height = 5,
# units="in",res=96)
charts.PerformanceSummary(cppi_reit,cex.legend=1.2,
main="Moodys/REAL CPPI and Wilshire REIT Indexes",
colorset=c("cadetblue","darkolivegreen3","purple"))
#dev.off()
#jpeg(filename="cppi-reit-rolling.jpg",quality=100,width=6.25, height = 6.25,
# units="in",res=96)
charts.RollingPerformance(cppi_reit,width=12,legend.loc="topleft",cex.legend=1.2,
main="Moodys/REAL CPPI and Wilshire REIT Indexes
Rolling 12 Month Return"
,
colorset=c("cadetblue","darkolivegreen3","purple"))
#dev.off()

Created by Pretty R at inside-R.org

2 comments:

  1. To automate a download with unzip, following example which takes ECB reference exchange rates:


    my.url="http://www.ecb.int/stats/eurofxref/eurofxref-hist.zip"
    my.tempfile<-paste(tempdir(),"\\eurofxref-hist.zip",sep="")
    download.file(my.url, my.tempfile, method="auto", quiet = FALSE, mode = "wb",cacheOK = TRUE)
    unzip(my.tempfile,exdir = tempdir(),junkpath=TRUE)

    jj<-read.csv(paste(tempdir(),"\\eurofxref-hist.csv",sep=""),na.strings="N/A")

    Hope its useful...

    ReplyDelete
  2. Hi Timely,

    Nice example systems you have here... Thank you!!!

    Here is what I use to fetch and unzip... Hope it helps you along your way...

    # this will get a remote zip file
    download.file('http://www.???.gov/remote_name.zip','local_name.zip')

    # this will unzip and load into an r var
    rvar <- read.csv(unzip('local_name.zip'))

    Cordially,

    -DD-

    ReplyDelete