Skip to content

Instantly share code, notes, and snippets.

@creative-quant
creative-quant / git-project-stats.sh
Created April 27, 2016 20:57
a script to get git user and project stats
#!/bin/bash
echo "by $USER"
git log --shortstat --author "$USER" \
| grep "files\? changed" \
| awk '{files+=$1; inserted+=$4; deleted+=$6} END \
{print "files changed", files, "lines inserted:", inserted, "lines deleted:", deleted}'
echo "total"
git log --shortstat \
| grep "files\? changed" \
| awk '{files+=$1; inserted+=$4; deleted+=$6} END \
@creative-quant
creative-quant / str_const.h
Created April 14, 2016 12:00
str_const from Scott Schurr - 2012.cppnow.org -> schurr_cpp11_tools_for_class_authors.pdf
class str_const { // constexpr string
private:
const char* const p_;
const std::size_t sz_;
public:
template<std::size_t N>
constexpr str_const(const char (&a)[N]) : // ctor
p_(a), sz_(N - 1) {
}
constexpr char operator[](std::size_t n) { // []
@creative-quant
creative-quant / ts.turning.points.R
Created March 8, 2016 19:37
An example of finding turning points in a time series using pastecs
require(graphics)
#some data
d <- density(faithful$eruptions, bw = "sj")
#make it a time series
ts_y<-ts(d$y)
#calculate turning points (extrema)
require(pastecs)
tp<-turnpoints(ts_y)
library(xts)
library(ggplot2)
#cad gdp
#curl http://www20.statcan.gc.ca/tables-tableaux/cansim/csv/03790031-eng.zip -o /tmp/ca.gpd.zip && unzip /tmp/ca.gpd.zip -d /tmp
#curl http://www.statcan.gc.ca/cgi-bin/sum-som/fl/cstsaveascsv.cgi?filename=gdps04a-eng.htm&lan=eng -o
#http://www20.statcan.gc.ca/tables-tableaux/cansim/csv/03790031-eng.zip
#Ref_Date,GEO,SEAS,PRICES,NAICS,Vector,Coordinate,Value
if( !exists( "ca.gdp" ) ) {
ca.gdp <- read.csv("/tmp/03790031-eng.csv")
@creative-quant
creative-quant / cad.cpi.R
Created January 26, 2016 00:54
CAD CPI plot
#$ curl -o /tmp/cad.cpi.csv http://www.statcan.gc.ca/daily-quotidien/160122/cg160122a001-eng.csv
# "The 12-month change in the Consumer Price Index (CPI) and the CPI excluding gasoline, 12-month % change"
# ,"CPI","CPI excluding gasoline"
library(ggplot2)
cad.cpi <- read.table( "/tmp/cad.cpi.csv", sep = ",", col.names=c("date", "cpi", "exgas"), skip=2, fill=T )
cad.cpi <- cad.cpi[1:(nrow( cad.cpi ) - 1),]
cad.cpi$date = as.Date( paste( cad.cpi$date, '01' ), "%B %Y %d" )
df <- data.frame(cad.cpi)
[alias]
sstash = "!f() { git stash save $1; }; f"
sshow = "!f() { echo $@; git stash show stash^{/$*} -p; }; f"
sapply = "!f() { git stash apply stash^{/$*}; }; f"
@creative-quant
creative-quant / AlmostEqual.h
Last active August 29, 2015 14:19
Comparing floating point numbers
/*
* AlmostEqual.h
*
*/
#ifndef ALMOSTEQUAL_H_
#define ALMOSTEQUAL_H_
// Usable AlmostEqual function - http://www.cygnus-software.com/papers/comparingfloats/comparingfloats.htm
bool AlmostEqual(float A, float B) {
@creative-quant
creative-quant / cad.employment.R
Created February 6, 2015 22:41
CAD Net Change in Employment
#http://www20.statcan.gc.ca/tables-tableaux/cansim/csv/02820087-eng.zip
@creative-quant
creative-quant / nfp.R
Last active June 4, 2017 21:04
USD Change in Non-farm Payrolls
library(ggplot2)
#curl 'http://research.stlouisfed.org/fred2/series/PAYEMS/downloaddata' --data 'form%5Bnative_frequency%5D=Monthly&form%5Bunits%5D=lin&form%5Bfrequency%5D=Monthly&form%5Baggregation%5D=Average&form%5Bobs_start_date%5D=1939-01-01&form%5Bobs_end_date%5D=2015-01-01&form%5Bfile_format%5D=csv&form%5Bdownload_data_2%5D=' -o /tmp/PAYEMS.csv
nfp <- read.csv("/tmp/PAYEMS.csv")
nfp$DATE <- as.Date( nfp$DATE, "%Y-%m-%d" )
df <- data.frame( change=diff(nfp$VALUE), date=tail(nfp$DATE,-1) )
plot <- ggplot(df,aes(x=date,y=change)) +
geom_area()
plot
@creative-quant
creative-quant / cal.R
Created February 5, 2015 23:30
Forex Economic Calendar
#curl http://www.dailyfx.com/files/Calendar-02-01-2015.csv -o /tmp/Calendar-02-01-2015.csv
cal <- read.csv("/tmp/Calendar-02-01-2015.csv")