Skip to content

Instantly share code, notes, and snippets.

@even4void
even4void / power.R
Created August 11, 2011 10:05
A simple animated demonstration of Power Analysis
mha <- 1 # mean under the alternative
es <- 2 # observed effect (deviation from mean under H0)
x <- seq(-6, 6, length=1000)
dh0 <- dnorm(x, 0, 1)
show.it <- function(es, mha, verbose=FALSE) {
dh1 <- dnorm(x, mha, 1)
plot.new()
plot.window(xlim=range(x), ylim=c(0,.6))
@marcelcaraciolo
marcelcaraciolo / multlin.py
Created October 28, 2011 03:57
multivariate linear regression
from numpy import loadtxt, zeros, ones, array, linspace, logspace, mean, std, arange
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
from pylab import plot, show, xlabel, ylabel
#Evaluate the linear regression
def feature_normalize(X):
'''
Returns a normalized version of X where
@timelyportfolio
timelyportfolio / MAImp.r
Created November 29, 2011 15:31
Improved Moving Average R Function
# Function to implement a version of the improved moving average functionality
# introduced and tested in:
#
# Papailias, Fotis and Thomakos, Dimitrios D.,
# "An Improved Moving Average Technical Trading Rule,
# (September 11, 2011). Available at SSRN: http://ssrn.com/abstract=1926376
#
# Original code written by Kent Russell @ timelyportfolio.com
#
# Cross-checked by Dimitrios Thomakos on 11/29/2011, @ quantf.com
@bradmontgomery
bradmontgomery / ShortIntroToScraping.rst
Created February 21, 2012 02:00
Really short intro to scraping with Beautiful Soup and Requests
@mikesmullin
mikesmullin / chromedriver.sh
Created May 8, 2012 16:08
easily install chromedriver on linux/osx
sudo apt-get install unzip;
wget -O /tmp/chromedriver.zip http://chromedriver.googlecode.com/files/chromedriver_linux64_19.0.1068.0.zip && sudo unzip /tmp/chromedriver.zip chromedriver -d /usr/local/bin/;
@jeromyanglim
jeromyanglim / example-r-markdown.rmd
Created May 17, 2012 04:23
Example of using R Markdown
This post examines the features of [R Markdown](http://www.rstudio.org/docs/authoring/using_markdown)
using [knitr](http://yihui.name/knitr/) in Rstudio 0.96.
This combination of tools provides an exciting improvement in usability for
[reproducible analysis](http://stats.stackexchange.com/a/15006/183).
Specifically, this post
(1) discusses getting started with R Markdown and `knitr` in Rstudio 0.96;
(2) provides a basic example of producing console output and plots using R Markdown;
(3) highlights several code chunk options such as caching and controlling how input and output is displayed;
(4) demonstrates use of standard Markdown notation as well as the extended features of formulas and tables; and
(5) discusses the implications of R Markdown.
@dreikanter
dreikanter / get-hashtags.py
Created May 25, 2012 10:18
Extract hashtags from a string (w/o regexps) #python
text = """Sample #line of #text to demonstrate #hashtags
extraction. Here is some duplicate ones: #text #hashtags #tags."""
def get_hashtags(text, order=False):
tags = set([item.strip("#.,-\"\'&*^!") for item in text.split() if (item.startswith("#") and len(item) < 256)])
return sorted(tags) if order else tags
print "\n".join(get_hashtags(text, True))
require(quantmod)
require(PerformanceAnalytics)
require(xtsExtra)
require(RColorBrewer)
#unfortunately don't feel like fighting IP lawyers so I cannot share this index data
portfolio <- read.csv("C:\\Users\\Kent.TLEAVELL_NT\\Documents\\old\\R\\lbustruu with tbill.csv",stringsAsFactors=FALSE)
portfolio <- portfolio[2:NROW(portfolio),2:NCOL(portfolio)]
portfolio <- portfolio[,c(1,3,5)]
@mbostock
mbostock / .block
Last active July 30, 2024 03:51
The Gist to Clone All Gists
license: gpl-3.0
@ddd1600
ddd1600 / CIKgetter.R
Created October 22, 2012 20:39
get SEC CIK number from ticker symbol
getCIK = function(ticker) {
stopifnot(is.character(ticker))
uri = "http://www.sec.gov/cgi-bin/browse-edgar"
response = getForm(uri,CIK=ticker,action="getcompany")
html = htmlParse(response)
CIKNode = getNodeSet(html, "//acronym[@title=\"Central Index Key\"][text() = \"CIK\"]")
CIKNodeText = sapply(CIKNode, function(x) xmlValue(getSibling(getSibling(x))))
CIK = sub(" .*","",CIKNodeText)
CIK = sub("^0*","",CIK)