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
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 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 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 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 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 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 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 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("GDP", "CMDEBT"), src="FRED") | |
plot(cumsum(na.omit(diff(GDP) - diff(CMDEBT)))) |
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
llxc = function( a, ll=-12:12, legend.loc="topleft", displayLegend=T, legend.cex=1.0, overplot=F ) | |
{ | |
if ( ncol(a) < 2 ) | |
{ | |
print( "Not enough columns") | |
return; | |
} | |
a = na.omit(a) | |
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
a = -Delt(CPIAUCNS, k=12)*100 | |
a = na.omit( a[endpoints(a, on="years")] ) | |
a = cumprod( (1+(a/100)) ) | |
b = (M2OWN*0.6 - Delt(CPIAUCNS, k=12)*100) | |
b = na.omit( b[endpoints(b, on="years")] ) | |
b = cumprod( (1+(b/100)) ) | |
b2 = (TB3MS*0.6 - Delt(CPIAUCNS, k=12)*100) | |
b2 = na.omit( b2[endpoints(b2, on="years")] ) |