Long XLU Short SPY
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. 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”)
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.