Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View mbusigin's full-sized avatar

Matt Busigin mbusigin

View GitHub Profile
@mbusigin
mbusigin / copy-code.sh
Last active March 31, 2024 05:00
MacOS X shell script to recursively copy a code base into a single OSX paste buffer so we can paste it into GPT-4 or Claude.
#!/bin/sh
for x in `find . | grep -v .git | grep -v node_modules | grep -v '~' | grep -v package-lock.json | grep -v package.json | grep -v png | grep -v ico | grep -v "backend/db.sqlite" | grep -v .mp3 | grep -v .ogg | grep -v uploads | grep -v .db | grep -v .svg | grep -v log.txt`
do
echo "<code filename=\"$x\">"
cat $x
echo "</code>"
done | pbcopy
@mbusigin
mbusigin / cyclical_adjustment.R
Created September 7, 2017 00:42
R function to return cyclically-adjusted series using labour & GDP output gaps
labour_output_gap = function()
{
if ( exists("UNRATE") == FALSE ) { fred("UNRATE", environment()) }
if ( exists("NROU") == FALSE ) { fred("NROU", environment()) }
a = na.trim(na.locf(merge(UNRATE, NROU)))
a = a[endpoints(a)]
return(UNRATE - NROU)
}
@mbusigin
mbusigin / multiplot.R
Created September 2, 2017 17:13
R function for multiplotting (overplotting), either on the same, or differing axes.
multiplot = function(r, legend.loc="topleft", legend.cex=1, overplot=F, plotSecondAxis=F, s_lty=1, plotfunc=recplot, legend=T, pointMax=F, pointLast=F, legendLast=F, legendLastRoundDigits=0 )
{
r = na.omit(r)
for ( x in names(r) )
{
n = r[,x]
m = n
r[,x] = m
}
@mbusigin
mbusigin / MultiComboBox.js
Last active August 9, 2017 15:31
A multi-selection ComboBox for Qooxdoo.
/*
* This is a multi-select dropdown combobox deriviative!
*
* I had seen that some other folks had been looking for similar functionality, and although the Qooxdoo
* community was helpful, and explained what kinds of things they'd have to do to implement it, no finished class
* emerged. So, I had the need, and here it is. Please spin any improvements back to me!
*
* Matthew Busigin, CIO @ Hover Networks, Inc (mbusigin <at> hovernetworks <dot> com)
*
* We're overriding a bunch of stuff here:
@mbusigin
mbusigin / Baa-spread-impute.R
Created October 10, 2016 22:00
Impute the Baa Spread using LQD, IEF and inverted 10s.
##
## Unfortunately, FRED no longer will be providing a whole bunch of interest rate series, principally Moody's.
## I use the Baa spread as the bedrock of my analysis, and although I can get a colleague to export the data from a BB terminal,
## I really needed to create a proxy so I can get data more quickly than that.
##
## The idea here is to impute the Baa spread from market inputs that we still have access to: 10s30s (because Baa spread has a
## duration spread embedded in it), the IEF/LQD ratio, and inverted 10s, in order to correct for convexity.
##
## The result is pretty decent: from 1986-2016, we get an R^2 of 0.9, RMSE of 0.26. I'm sure it could be improved upon, so let me know
## if you have any other ideas.
function()
{
if ( exists("CPIAUCSL") == FALSE ) { fred("CPIAUCSL", environment()) }
if ( exists("MCOILWTICO") == FALSE ) { fred("MCOILWTICO", environment()) }
if ( exists("CUSR0000SEHC") == FALSE ) { fred("CUSR0000SEHC", environment()) }
recplot( (MCOILWTICO/CPIAUCSL)*-1.5736 + Delt(CUSR0000SEHC, k=12*5)* 6.5426 + 1.5954 )
lines( cagr(dlag(CPIAUCSL, k=12*5), 5), col="dodgerblue3" )
}
@mbusigin
mbusigin / multiplot.R
Created July 12, 2015 14:23
Plot xts object with multiple columns
multiplot = function(r, legend.loc="topleft", legend.cex=1, overplot=F, plotSecondAxis=F, s_lty=1, plotfunc=recplot, legend=T, pointMax=F, pointLast=F, legendLast=F, legendLastRoundDigits=0 )
{
r = na.omit(r)
for ( x in names(r) )
{
n = r[,x]
m = n
r[,x] = m
}
@mbusigin
mbusigin / fred.R
Created July 12, 2015 12:48
R function to retrieve FRED series as xts object
##
## 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)
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
@mbusigin
mbusigin / RV vs FV
Created October 12, 2014 18:11
Relating Future Volatility with Realized Volatility
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 ) )