Skip to content

Instantly share code, notes, and snippets.

View shabbychef's full-sized avatar
tcb

Steven Pav shabbychef

tcb
View GitHub Profile
# * Fri Feb 24 2012 09:09:10 PM Steven E. Pav <shabbychef@gmail.com>
#
# computation of moments and moment-based statistics
#
# see also:
# * http://www.johndcook.com/blog/2008/09/26/comparing-three-methods-of-computing-standard-deviation/
# * http://www.johndcook.com/standard_deviation.html
# * J. Bennett, et. al., 'Numerically Stable, Single-Pass,
# Parallel Statistics Algorithms,' Proceedings of IEEE
# International Conference on Cluster Computing, 2009.
@shabbychef
shabbychef / realworld_hotelling.R
Last active December 12, 2015 06:28
check out SPY, TLT, GLD, AAPL...
require(quantmod)
getSymbols(c("SPY","TLT","GLD","AAPL"))
allofem <- merge(SPY[,"SPY.Adjusted"],TLT[,"TLT.Adjusted"],GLD[,"GLD.Adjusted"],AAPL[,"AAPL.Adjusted"])
mo.pry <- to.monthly(allofem,OHLC=FALSE)
mo.ret <- diff(log(mo.pry))
sub.ret <- mo.ret[(dim(mo.ret)[1]-59):dim(mo.ret)[1],]
mu <- apply(sub.ret,2,mean,na.rm=TRUE)
Sg <- cov(sub.ret,use="complete.obs")
w <- solve(Sg,mu)
n <- dim(sub.ret)[1]
@shabbychef
shabbychef / replicating_google_trends.ipynb
Created June 18, 2013 20:17
iPython notebook to replicate the paper 'Quantifying Trading Behavior in Financial Markets Using Google Trends.'
We can make this file beautiful and searchable if this error is corrected: It looks like row 9 should actually have 12 columns, instead of 2. in line 8.
Entity Name Title Base Overtime Other (vacation, sick, bonus, etc) Medical/Dental/Visual Employeer Contribution to Pension Employee Contribution to Pension Paid By Employer Employer Contribution to Deferred Compensation (401k) Misc Total Cost of Employment
Bay Area Rapid Transit Dugger, Dorothy General Mgr 298700 0 34500 14951 39521 23324 1869 6796 419661
Bay Area Rapid Transit Crunican, Grace General Mgr 312461 0 3846 19141 37513 17500 1869 7591 399921
Bay Area Rapid Transit Tietz, Forrest Police Sergeant 136746 111902 33921 18200 60630 156 0 1107 362662
Bay Area Rapid Transit Pangilinan, Edgardo Asst Controller 107785 0 214322 10903 13017 7650 1869 5734 361279
Bay Area Rapid Transit Lucarelli, Frank Police Lieutenant 173811 46280 33422 23364 76427 233 0 5019 358556
Bay Area Rapid Transit Collier, Roberta Asst Treasurer 33971 0 289534 1797 4072 2378 1869 4897 338518
Bay Area Rapid Transit Parker, Thomas Exec Mgr Transit System Compl 136544 0 145633 19139 16863 9923 1869 5584 335554
Bay Area Rapid Transit Rai
# see
# http://climateecology.wordpress.com/2013/08/19/r-vs-python-speed-comparison-for-bootstrapping/
# first version#FOLDUP
set.seed(101)
# generate data
x <- 0:100
y <- 2*x + rnorm(101, 0, 10)
@shabbychef
shabbychef / se.ipynb
Created September 30, 2013 05:24
standard error computation
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@shabbychef
shabbychef / conque_tweak.vim
Created November 13, 2013 17:11
code to place in .vimrc to make Conque play nicely with R.
" code to place in .vimrc to make Conque play nicely with R
" (or other languages, though you would have to generalize the
" commands to allow different syntax and filetypes)
"
" to use, place in .vimrc, resource, and issue
"
" :RConque
"
" this will give you a screen session named 'r';
" use R in this session;
#!/bin/bash -e
#
# Created: 2016.02.05
# Copyright: Steven E. Pav, 2016
# Author: Steven E. Pav
# Comments: Steven E. Pav
function finish() {
echo doing cleanup here
}
@shabbychef
shabbychef / server.R
Last active February 23, 2016 17:52
Cramer Rao bound on Markowitz portfolio Monte Carlo shiny app.
# Created: 2015.05.18
# Copyright: Steven E. Pav, 2015
# Author: Steven E. Pav <shabbychef@gmail.com>
# Comments: Steven E. Pav
library(shiny)
library(ggplot2)
library(reshape2)
library(hypergeo)
@shabbychef
shabbychef / yunoparallel.R
Last active March 25, 2016 18:15
y u no work, RcppParallel?
library(Rcpp)
source('yunoparallel.cpp')
x <- rnorm(1e5)
dumbCount_int(x)
dumbCount_int(x)
# seems fine, except ...
replicate(10,dumbCount_int(x))
sd(replicate(100,dumbCount_int(x)))