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
| library(quantmod) | |
| library(PerformanceAnalytics) | |
| # getSymbols(c("SPY", "TLT", "LQD")) | |
| bars = 60 | |
| a = merge(Delt(SPY[,6], k=bars), Delt(TLT[,6], k=bars), Delt(LQD[,6], k=bars)) | |
| b = last(a) | |
| names(b) = c("SPY", "TLT", "LQD") | |
| b2 = round(as.vector(b), digits=2) | |
| barplot( b2, names.arg=names(b) ) | |
| text(1:3, 0, paste(b2, "%", sep="")) |
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
| cdf_pdf <- function(v, legend.loc="topleft", legend.cex=1, name="") | |
| { | |
| if ( name == "" ) | |
| { | |
| name = names(v)[1] | |
| } | |
| a = as.vector(v) | |
| lv = as.numeric(last(v)) | |
| hist(v, col="grey90", main="", xlab="", ylab="", ) |
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
| library(quantmod) | |
| getSymbols( c("LNU00000012", "LNS12000091"), src="FRED" ) | |
| plot(diff(LNU00000012, lag=12*5)*1.93+ 385.70445) | |
| lines(lag(diff(LNS12000091, lag=12*5), k=-12*20), col="blue", lty=4) | |
| points(last(na.omit(lag(diff(LNS12000091, lag=12*5), k=-12*20))), pch=16, col="blue") | |
| legend("topright", c("5y Demographic projection of Growth of 35-44 employees", "5y Actual Growth of 35-44 employees"), col=c("black", "blue"), lty=c(1, 4), cex=.6) |
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
| #!/usr/bin/perl -W | |
| # From populationpyramid.net's data source https://github.com/madewulf/PopulationPyramid.net/tree/master/static/data/generated | |
| # Takes the JSON as stdin, returns a CSV with the M/O ratio | |
| use strict; | |
| use JSON; | |
| use Data::Dumper; | |
| my $json = JSON->new; |
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
| getSymbols(c("M12MTVUSM227NFWA", "CNP16OV", "CLF16OV"), src="FRED") | |
| a = na.omit(merge(Delt(M12MTVUSM227NFWA, k=12), Delt(CNP16OV, k=12), Delt(CLF16OV, k=12))) | |
| plot(as.vector(a[,2]), as.vector(a[,1]), type="p", xlim=c(-.01, .04), ylim=c(-0.04, .08), pch=14, cex=.5, col="red", xlab="x", ylab="M12MTVUSM227NFWA %-y/y") | |
| m2 = lm(a[,1] ~ a[,2]) | |
| abline(m2, col="red") | |
| points(as.vector(a[,3]), as.vector(a[,1]), pch=16, col="dodgerblue3", cex=.5) | |
| m3 = lm(a[,1] ~ a[,3]) | |
| abline(m3, col="dodgerblue3") | |
| legend("topleft", c("x = CNP16OV %-y/y (r=0.326)", "x = CLF16OV %-y/y (r=0.55)"), col=c("red", "dodgerblue3"), pch=c(14, 16), cex=0.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
| ## | |
| ## Creates graphs like: | |
| ## https://twitter.com/mbusigin/status/483370672828055553 | |
| ## | |
| colourized_scatter <- function(a) | |
| { | |
| plot(matrix(a, ncol=2), type="l", xlab=names(a)[1], ylab=names(a)[2]) | |
| points(matrix(a, ncol=2), col=rainbow(nrow(a)), pch=16, cex=.5) | |
| lines(lowess(a), lty=3) |
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
| create.portfolio <- function( tickers=c('SPY', 'AGG', 'TLT', 'GLD'), weights=NULL, er=NULL, ev=NULL ) | |
| { | |
| e = new.env() | |
| getSymbols(tickers, from="1950-01-01", env=e) | |
| a = NULL | |
| for ( i in 1:length(tickers) ) | |
| { | |
| a = cbind(a, annualReturn( get(tickers[i], e) )) | |
| } | |
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
| getSymbols("^GSPC", from="1950-01-01") | |
| p = 10 | |
| a = na.omit(merge( volatility(GSPC, n=p)*100, lag(volatility(GSPC, n=p), k=-p)*100 )) | |
| names(a) = c("hv", "rv") | |
| medianvalues = c() | |
| meanvalues = c() | |
| maxvalues = c() | |
| minvalues = c() | |
| keys = c() | |
| for ( x in seq( 0, max(a$hv), 2 ) ) |
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
| plotNeoclassicalGrowth = function() | |
| { | |
| if ( exists("GDP") == FALSE ) { getSymbols("GDP", src="FRED") } | |
| if ( exists("GDPC96") == FALSE ) { getSymbols("GDPC96", src="FRED") } | |
| if ( exists("CLF16OV") == FALSE ) { getSymbols("CLF16OV", src="FRED") } | |
| if ( exists("GPDI") == FALSE ) { getSymbols("GPDI", src="FRED") } | |
| if ( exists("COFC") == FALSE ) { getSymbols("COFC", src="FRED") } | |
| a = na.omit(merge(Delt(CLF16OV, k=12), (GPDI-COFC)/GDP, Delt(GDPC96, k=4) - Delt(CLF16OV, k=12) - ((GPDI-COFC)/CPIAUCSL)/GDP)) * 100 | |
| z = a |
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
| ## | |
| ## The quantmod function, getSymbols.FRED(), has been broken by the recent upgrade to FRED to https only. | |
| ## I've taken that function and tweaked it to work. | |
| ## | |
| fred <- function (Symbols, env, return.class = "xts", ...) | |
| { | |
| importDefaults("getSymbols.FRED") | |
| this.env <- environment() | |
| for (var in names(list(...))) { | |
| assign(var, list(...)[[var]], this.env) |