Long XLU Short SPY

May 20, 2011
By

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

THIS IS NOT INVESTMENT ADVICE.  YOU ARE RESPONSIBLE FOR YOUR OWN GAINS AND LOSSES.

I spend my days and nights wondering what a bond manager should do if he/she doesn’t like bonds, but also cannot sit in 0% cash.  I generally dislike spreads, but if the bond manager has some flexibility, maybe long Utilities (XLU) and short S&P 500 (SPY) might offer a decent substitute.

The spread offers a dividend yield of XLU (3.94%) – SPY (1.71%) = 2.23% Source: Yahoo! Finance but also offers potential price appreciation with low or negative correlation to bonds and stocks.

From TimelyPortfolio
From TimelyPortfolio
From TimelyPortfolio
From TimelyPortfolio

R code:

require(quantmod)
require(PerformanceAnalytics)
require(fAssets)
require(ggplot2)

tckr<-c("XLU","VBMFX","IWM","GLD","SPY","SDS")

start<-"2000-01-01"
end<- format(Sys.Date(),"%Y-%m-%d") # yyyy-mm-dd

# Pull tckr index data from Yahoo! Finance
getSymbols(tckr, from=start, to=end)

XLU<-adjustOHLC(XLU,use.Adjusted=T)
VBMFX<-adjustOHLC(VBMFX,use.Adjusted=T)
IWM<-adjustOHLC(IWM,use.Adjusted=T)
GLD<-adjustOHLC(GLD,use.Adjusted=T)
SPY<-adjustOHLC(SPY,use.Adjusted=T)
SDS<-adjustOHLC(SDS,use.Adjusted=T)

XLU<-to.weekly(XLU, indexAt='endof')
VBMFX<-to.weekly(VBMFX, indexAt='endof')
IWM<-to.weekly(IWM, indexAt='endof')
GLD<-to.weekly(GLD, indexAt='endof')
SPY<-to.weekly(SPY, indexAt='endof')
SDS<-to.weekly(SDS, indexAt='endof')
XLUSPY<-to.weekly(XLU/SPY, indexAt='endof')

RetToAnalyze<-merge(weeklyReturn(XLU),weeklyReturn(VBMFX),weeklyReturn(IWM),weeklyReturn(GLD),weeklyReturn(SPY),weeklyReturn(SDS),weeklyReturn(XLUSPY),weeklyReturn(XLU)+weeklyReturn(SDS)/2)
colnames(RetToAnalyze)<-c(tckr,"XLUSPY","XLUSDS")

#assetsDendrogramPlot(as.timeSeries(RetToAnalyze))
assetsCorEigenPlot(as.timeSeries(RetToAnalyze))

#charts.PerformanceSummary(RetToAnalyze)
#charts.RollingRegression(RetToAnalyze[,7,drop=F],RetToAnalyze[,5],Rf=0.005,legend.loc="topleft")
#chart.RollingCorrelation(RetToAnalyze[,1:5,drop=F],RetToAnalyze[,7],legend.loc="topleft",width=25)

chart.Correlation(RetToAnalyze[,1:7,drop=F])
corXLUSPYtoBonds<-runCor(RetToAnalyze[,7],RetToAnalyze[,2],25)
corXLUSPYtoStocks<-runCor(RetToAnalyze[,7],RetToAnalyze[,5],25)
chartSeries(XLUSPY,TA="addBBands();addTA(corXLUSPYtoBonds);addTA(corXLUSPYtoStocks)",theme="white")

#get performance during difficult times
difficultTimes<-data.frame(cbind(c("2000 Tech Bubble Collapse","2008 Financial Panic","2010 Collapse"),
    c(round(coredata(XLUSPY["2001-09-21",4])/coredata(XLUSPY["2000-02-25",4])-1,digits=2),
    round(coredata(XLUSPY["2009-01-30",4])/coredata(XLUSPY["2007-09-28",4])-1,digits=2),   
    round(coredata(XLUSPY["2010-08-27",4])/coredata(XLUSPY["2010-04-23",4])-1,digits=2))))
colnames(difficultTimes)<-c("Period","XLUSPYChange")
ggplot(difficultTimes,stat="identity",aes(Period,XLUSPYChange)) + geom_bar(position="dodge") +
    xlab(NULL) + ylab("% Change in Price") +
    opts(title = "Long XLU Short SPY in Difficult Times")

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

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: 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.