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
| #look at steps in constructing a horizon plot version | |
| #of http://www.mebanefaber.com/timing-model/ | |
| #do horizon of percent above or below 10 month / 200 day moving average | |
| require(lattice) | |
| require(latticeExtra) | |
| require(quantmod) | |
| #since we are focused on the horizon plot, let's just look at one stock |
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
| #code almost entirely from addRSI from quantmod package | |
| # add_RSI {{{ | |
| add_RSI.test <- function (n=14, maType="EMA", ..., RSIup=70, RSIdn=30, horizonscale=25) { | |
| require(RColorBrewer) | |
| lenv <- new.env() | |
| lenv$plot_rsi <- function(x, n, maType, ...) { | |
| xdata <- x$Env$xdata | |
| xsubset <- x$Env$xsubset | |
| rsi <- RSI(Cl(xdata),n=n,maType=maType)[xsubset] - 50 |
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(RColorBrewer) | |
| require(quantmod) | |
| require(PerformanceAnalytics) | |
| data(managers) | |
| #let's do managers from 2002 to 2004 to get positive and negative | |
| x <- cumprod(1+managers["2002::2004"])[,1] - 1 | |
| #get some decent colors from RColorBrewer |
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
| #get very helpful Ken French data | |
| #for this project we will look at Industry Portfolios | |
| #http://mba.tuck.dartmouth.edu/pages/faculty/ken.french/ftp/48_Industry_Portfolios_daily.zip | |
| require(latticeExtra) | |
| require(PerformanceAnalytics) | |
| require(quantmod) | |
| #my.url will be the location of the zip file with the data | |
| my.url="http://mba.tuck.dartmouth.edu/pages/faculty/ken.french/ftp/48_Industry_Portfolios_daily.zip" |
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
| #get very helpful Ken French data | |
| #for this project we will look at Industry Portfolios | |
| #http://mba.tuck.dartmouth.edu/pages/faculty/ken.french/ftp/48_Industry_Portfolios_daily.zip | |
| require(latticeExtra) | |
| require(PerformanceAnalytics) | |
| require(quantmod) | |
| #my.url will be the location of the zip file with the data | |
| my.url="http://mba.tuck.dartmouth.edu/pages/faculty/ken.french/ftp/48_Industry_Portfolios_daily.zip" |
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(fAssets) | |
| require(latticeExtra) | |
| require(quantmod) | |
| require(PerformanceAnalytics) | |
| #my.url will be the location of the zip file with the data | |
| my.url="http://mba.tuck.dartmouth.edu/pages/faculty/ken.french/ftp/48_Industry_Portfolios_daily.zip" | |
| #this will be the temp file set up for the zip file | |
| my.tempfile<-paste(tempdir(),"\\frenchindustry.zip",sep="") | |
| #my.usefile is the name of the txt file with the data |
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
| #get very helpful Ken French data | |
| #for this project we will look at Industry Portfolios | |
| #http://mba.tuck.dartmouth.edu/pages/faculty/ken.french/ftp/48_Industry_Portfolios_daily.zip | |
| require(latticeExtra) | |
| require(animation) | |
| require(PerformanceAnalytics) | |
| require(quantmod) | |
| #my.url will be the location of the zip file with the data |
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
| #work on porting chart.TimeSeries to plot.xts | |
| #believe all these initial issues have been resolved | |
| #issues: no log scale y axis option so will have to handle | |
| # no legend functionality yet | |
| # shading of blocks not reaching bottom (sent to M Weylandt) | |
| # main does not automatically choose first column like chart.TimeSeries | |
| require(PerformanceAnalytics) |
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 | |
| require(PerformanceAnalytics) | |
| 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 | |
| require(RColorBrewer) | |
| col.brew <- brewer.pal(name="RdBu",n=10) | |
| #ease this reference later | |
| n=NROW(x) |
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(PerformanceAnalytics) | |
| require(xtsExtra) #if you get error, please install xtsExtra from r-forge as shown in the top line | |
| require(RColorBrewer) | |
| #function add alpha or transparency to colors | |
| addalpha <- function(cols,alpha=180) { | |
| rgbcomp <- col2rgb(cols) | |
| rgbcomp[4] <- alpha |