Skip to content

Instantly share code, notes, and snippets.


Joshua Ulrich joshuaulrich

View GitHub Profile
joshuaulrich / parse_crsp_file.awk
Created Dec 12, 2020
Parse CRSP file into separate files by symbol
View parse_crsp_file.awk
#!/usr/bin/awk -f
# GNU Awk 3.1.8
# Tutorial:
BEGIN{ FS=","; OFS=","; filename="" }
if(NR==1) { # the first record/line is the header
header=substr($0,8) # store to write to each symbol file
joshuaulrich / intraday-sp500.R
Last active Jan 28, 2022
Track the S&P 500 throughout the trading day
View intraday-sp500.R
do_chart <- function(symbol) {
quote <- getQuote(symbol)
quote$Close <- quote$Last
xts(OHLCV(quote), quote[,"Trade Time"],
pct_change = quote[,"% Change"])
filename <- "intraday-sp500.rds"
View update-daily-data-with-quote.R
update.realtime <-
function(ticker, history = NULL)
if (is.null(history)) {
history <- getSymbols(ticker, from = "2018-01-01", auto.assign = FALSE)
today <- getQuote(ticker, src = "yahoo")
now <- as.Date(today[,"Trade Time"])
cn <- c("Open", "High", "Low", "Last", "Volume", "Last")
live <- xts(today[, cn], now)
joshuaulrich /
Created Nov 21, 2019 — forked from aortbals/
Squash and Merge on the Command line

With the introduction of GitHub's Squash and Merge feature, this has become less prevelant, however it's still useful in scenarios where GitHub's interface is unavailable.

Let's talk through two ways to do a squash and merge on the command line.

Take 1: Interactive Rebase

When to use it

  • When you have not merged master into your feature branch
  • There are no merge conflicts
joshuaulrich /
Created Sep 14, 2019
Because keybase told me to

Keybase proof

I hereby claim:

  • I am joshuaulrich on github.
  • I am joshuaulrich ( on keybase.
  • I have a public key ASDcjSYFiNY5lotsu7tcXthTsae6mRwUHF1G48R03YG-AQo

To claim this, I am signing this object:

joshuaulrich /
Last active Feb 16, 2019 — forked from evandrix/gist:1076041
Check password against known hashed password and salt
# Usage: read -s PASSWORD && ./
use Crypt::Eksblowfish::Bcrypt;
# Read password and salt from environment variables
$password = $ENV{PASSWORD};
$salt = "lfVQ/T2N3dhFVvvPro2Hfu"
$encrypted = encrypt_password($password, $salt);
# Extract bcrypt version, cost, salt, and hashed password
joshuaulrich / bench.R
Last active Mar 29, 2018 — forked from jimhester/bench.R
getOption benchmark
View bench.R
getOptionOld <- function(x, default = NULL) {
if(missing(default) || x %in% names(options()))
getOptionNew <- function(x, default = NULL) {
ans <- .Internal(getOption(x))
if(is.null(ans)) default else ans
joshuaulrich / do_gc.c
Created Jan 28, 2018
Force an R garbage collection from C
View do_gc.c
void do_gc(SEXP env) {
SEXP s, t;
PROTECT(s = t = allocList(1));
SETCAR(t, install("gc")); t = CDR(t);
PrintValue(eval(s, env));
joshuaulrich / 10y-oscillator.R
Last active Aug 27, 2017 — forked from mbusigin/10y-oscillator.R
Generate chart with 10y yield oscillator (10y yield minus 260d moving average), +/- 1 stdev dashed lines
View 10y-oscillator.R
recplot <- function(var, rec.ind, maintitle = "", ylab = "", ylim = NULL)
# Give each recession a separate number, so we can split data by recession
# and calculate the necessary values to pass to addPolygon() for shading
r <- rle(as.integer(rec.ind))
r$values[r$values > 0] <- seq_len(sum(r$values))
rec <- xts(inverse.rle(r), index(rec.ind))
# Merge variable and recession data, as a left-join so we do not have
# observations that only exist in the recession indicator data
joshuaulrich / detect_outliers.c
Created Aug 4, 2017
Detect outliers in 'real-time' using Richard Olsen's method in "High Frequency Finance"
View detect_outliers.c
* Copyright (C) 2017 Joshua M. Ulrich
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of