Created
March 25, 2011 02:18
-
-
Save milktrader/886250 to your computer and use it in GitHub Desktop.
Plot how much today's close is different from the close 24 days ago in % terms
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
blueberry <- function(sym="SLV", file="~/Desktop/24_days_ago.png"){ | |
require("quantmod") | |
ticker <- getSymbols(sym, auto.assign=FALSE) | |
ticker <- merge(ticker[,4], lag(ticker[,4],24)) | |
ticker <- na.locf(ticker, na.rm=TRUE) | |
lag_diff <- function(x,y){ | |
pdiff <- (x - y)/y | |
return(pdiff) | |
} | |
ticker <- cbind(ticker, apply(ticker,1, function(x)lag_diff(x[1],x[2]))) | |
change <- ticker[,3] | |
png(file) | |
# plot(change, main="% Change From Close Today & Close 24 Days Ago") | |
# hist(change, main="% Change From Close Today & Close 24 Days Ago") | |
plot(density(change), main="% Change From Close Today & Close 24 Days Ago") | |
polygon(density(change), col="blue") | |
dev.off() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment