Skip to content

Instantly share code, notes, and snippets.

@mbusigin
Created October 12, 2013 17:10
Show Gist options
  • Save mbusigin/6952446 to your computer and use it in GitHub Desktop.
Save mbusigin/6952446 to your computer and use it in GitHub Desktop.
R example of creating bar chart of ytd returns for a few assets
getSymbols(c("SPY", "TLT", "LQD"))
a = merge(SPY[,6], TLT[,6], LQD[,6])[ "2013" ]
b = (as.vector(tail(a, n=1)) / as.vector(head(a, n=1))) - 1
names(b) = c("SPY", "TLT", "LQD")
b2 = round(b[order(b)] * 100)
barplot( b2, names.arg=names(b2) )
text(1:3, 1, paste(b2, "%", sep=""))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment