Created
April 7, 2011 16:02
-
-
Save milktrader/908077 to your computer and use it in GitHub Desktop.
This file contains 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(vioplot) | |
getSymbols("GLD") | |
friend <- DonchianChannel( GLD[,c("GLD.High","GLD.Low")], n=20 ) | |
buddy <- DonchianChannel( GLD[,c("GLD.High","GLD.Low")], n=10 ) | |
pal <- DonchianChannel( GLD[,c("GLD.High","GLD.Low")], n=5 ) | |
posse <- merge(friend$mid, buddy$mid, pal$mid) | |
GLD <- merge(GLD, posse) | |
GLD <- na.locf(GLD, na.rm=TRUE) | |
compadre <- ifelse(Cl(GLD) > GLD$mid & Cl(GLD) > GLD$mid.1 & Cl(GLD) > GLD$mid.2, 1, | |
ifelse(Cl(GLD) < GLD$mid & Cl(GLD) < GLD$mid.1 & Cl(GLD) < GLD$mid.2, -1, 0)) | |
hist(compadre, main="What are your positions over the past few years?", col="goldenrod") | |
dinero <- Lag(ROC(Cl(GLD)))*compadre | |
dinero <- na.locf(dinero, na.rm=TRUE) | |
vioplot(dinero, names="Distribution of 'compadre' daily returns", col="blue") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment