This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #plot.xts with horizons | |
| #install.packages("xtsExtra", repos="http://R-Forge.R-project.org") | |
| require(PerformanceAnalytics) | |
| require(quantmod) | |
| require(xtsExtra) #if you get error, install xtsExtra from r-forge | |
| horizon.panel <- function(index,x,...) { | |
| #get some decent colors from RColorBrewer | |
| #we will use colors on the edges so 2:4 for red and 7:9 for blue |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #install.packages("xtsExtra", repos="http://R-Forge.R-project.org") | |
| require(quantmod) | |
| require(rugarch) | |
| require(xtsExtra) #if you get an error, see first line and install from r-forge | |
| getSymbols("DEXJPUS",src="FRED") | |
| DEXJPUS<-1/to.weekly(DEXJPUS) | |
| ugarch.panel <- function(index,x,type,cex,col,pch,...){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #install.packages("xtsExtra", repos="http://R-Forge.R-project.org") | |
| require(quantmod) | |
| require(RColorBrewer) | |
| require(xtsExtra) #if you get an error, see first line and install from r-forge | |
| #use Mebane Faber tickers VTI, VEU, IEF, VNQ, DBC | |
| #as discussed in http://papers.ssrn.com/sol3/papers.cfm?abstract_id=962461 | |
| tckrs <- c("VTI", "VEU", "IEF", "VNQ", "DBC") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require(quantmod) | |
| require(PerformanceAnalytics) | |
| require(xtsExtra) | |
| require(RColorBrewer) | |
| #unfortunately don't feel like fighting IP lawyers so I cannot share this index data | |
| portfolio <- read.csv("file.csv",stringsAsFactors=FALSE) | |
| portfolio <- portfolio[2:NROW(portfolio),2:NCOL(portfolio)] | |
| portfolio <- portfolio[,c(1,3,5)] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #first attempt at implementing horizon plots in ggplot2 | |
| #pleased with result but code sloppy and inflexible | |
| #as always very open to improvements and forks | |
| require(ggplot2) | |
| require(reshape2) | |
| require(quantmod) | |
| require(PerformanceAnalytics) | |
| require(xtsExtra) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #integrate 2 Google Summer of Code 2012 Projects | |
| #plot.xts and PerformanceAnalytics both received very nice additions | |
| #wish I knew the exact link but believe this section came from stackoverflow | |
| #this allows you to work with the code straight from r-forge SVN | |
| ## If you want to source() a bunch of files, something like | |
| ## the following may be useful: | |
| #path="C:\\Program Files\\R\\R-2.15.1\\sandbox\\svnsource\\returnanalytics\\pkg\\PerformanceAnalytics\\r" | |
| #sourceDir <- function(path, trace = TRUE, ...) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #explore exceptional case of the Russell 2000 | |
| require(quantmod) | |
| require(PerformanceAnalytics) | |
| require(xtsExtra) | |
| getSymbols("^RUT", from = "1900-01-01") | |
| getSymbols("^GSPC", from = "1900-01-01") | |
| #do initial exploration of distribution |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require(PerformanceAnalytics) | |
| require(quantmod) | |
| getSymbols("^GSPC", from = "1900-01-01") | |
| #get return series from closing price | |
| ret.bh <- ROC(GSPC[,4],n = 1,type = "discrete") | |
| #change first value from NA to 0 | |
| ret.bh[1,] <- 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #obviousness of reits? | |
| #get NAREIT data | |
| #I like NAREIT since I get back to 1971 | |
| #much easier though to get Wilshire REIT from FRED | |
| #also it is daily instead of monthly | |
| #getSymbols("WILLREITIND",src="FRED") will do this | |
| require(gdata) | |
| reitURL <- "http://returns.reit.com/returns/MonthlyHistoricalReturns.xls" | |
| reitExcel <- read.xls(reitURL,sheet="Index Data",pattern="All REITs",stringsAsFactors=FALSE) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require(quantmod) | |
| require(PerformanceAnalytics) | |
| getSymbols("^RUT",from = "1900-01-01") | |
| getSymbols("^GSPC",from = "1900-01-01") | |
| #get 1 day change for the Russell 2000 and S&P 500 | |
| roc <- na.omit(merge(ROC(RUT[,4],type="discrete",n=1),ROC(GSPC[,4],type="discrete",n=1))) | |
| stdev <- rollapplyr(roc,FUN=sd,width=50) | |
| #get relative strength of Russell 2000 versus S&P 500 |