Skip to content

Instantly share code, notes, and snippets.

View shabbychef's full-sized avatar
tcb

Steven Pav shabbychef

tcb
View GitHub Profile
@shabbychef
shabbychef / monthly_spy_anova.R
Created May 20, 2012 04:12
ANOVA on monthly GSPC returns
# * Sat May 19 2012 21:04:56 Steven E. Pav <shabbychef@gmail.com>
# from https://github.com/milktrader/rfinance2012/blob/94e6dd0452b16697ad10f9bc7e0e7431c95d9020/xts/.Rhistory
require(quantmod)
getSymbols('^GSPC', from='1950-01-01')
G <- monthlyReturn(Cl(GSPC))
G$monnum <- .indexmon(G)
# try ANOVA on the monthly returns
@shabbychef
shabbychef / ipython_magics.py
Created December 12, 2012 21:06
demonstrate R and octave 'magics' in ipython.
# to get the R<->python magic
%load_ext rmagic
# now you can code in R:
%%R
library(survival)
amod <- coxph(Surv(lung$time,lung$status) ~ lung$sex + lung$ph.karno)
print(summary(amod))
# done
@shabbychef
shabbychef / ipython_test.ipynb
Created December 12, 2012 21:22
testing ipython notebook and magic.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@shabbychef
shabbychef / moy_effect.ipynb
Created January 4, 2013 01:38
month of year effects in SPY since 1950, lack thereof.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
# * 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.'