Skip to content

Instantly share code, notes, and snippets.

@guilespi
guilespi / pm.h diff update
Created July 28, 2012 02:05
Compile latest igb driver on debian squeeze 2.6.32-5-amd64
#When presented with failure
igb-3.4.8/src/igb_main.c:193: error: implicit declaration of function SET_RUNTIME_PM_OPS
#Add the following macro to
#/usr/src/linux-headers-2.6.32-5-common/include/linux/pm.h
#ifdef CONFIG_PM_RUNTIME
#define SET_RUNTIME_PM_OPS(suspend_fn, resume_fn, idle_fn) \
.runtime_suspend = suspend_fn, \
.runtime_resume = resume_fn, \
@guilespi
guilespi / get-NYSE-days.clj
Created October 29, 2012 02:05
QSTK Get days there was trading at the NYSE
(defn get-NYSE-days
"Create a set of timestamps between startday and endday
that correspond to the days there was trading at the NYSE"
[start-date end-date time-of-day]
(let [dates-file (str *QS* "/qstkutil/NYSE_dates.txt")
NYSE-dates (incanter.io/read-dataset dates-file)
fmt (formatter "MM/dd/yyyy")
dates (incanter.core/$map #(parse fmt %) :col0 NYSE-dates)]
(set (filter (fn [d] (within? (interval start-date end-date) d))
(map #(plus % time-of-day) dates)))))
@guilespi
guilespi / Tutorial1.py
Created October 29, 2012 02:07
QSTK Tutorial 1
'''
(c) 2011, 2012 Georgia Tech Research Corporation
This source code is released under the New BSD license. Please see
http://wiki.quantsoftware.org/index.php?title=QSTK_License
for license details.
Created on September, 12, 2011
@author: Tucker Balch
@contact: [email protected]
@guilespi
guilespi / get-data.clj
Created October 29, 2012 02:25
Build a matrix from stock datasets
(defn select-value
"Given a dataset indexed by date, returns the value corresponding to a specified column
if existent for a specific date"
[ds column date]
(let [row (ds {:Date date})]
(when-not (nil? row) (incanter.core/$ 0 column row))))
(defn get-data
"Given a list of `symbols`, its data and a list of specific `timestamps`, builds a matrix(sequence)
with each column corresponding to a stock and the value extracted using `column`
@guilespi
guilespi / get_data_hardread.py
Created October 29, 2012 02:28
QSTK Reading stock info from disk
def get_data_hardread(self, ts_list, symbol_list, data_item, verbose=False, bIncDelist=False):
'''
Read data into a DataFrame no matter what.
@param ts_list: List of timestamps for which the data values are needed. Timestamps must be sorted.
@param symbol_list: The list of symbols for which the data values are needed
@param data_item: The data_item needed. Like open, close, volume etc. May be a list, in which case a list of DataFrame is returned.
@param bIncDelist: If true, delisted securities will be included.
@note: If a symbol is not found then a message is printed. All the values in the column for that stock will be NaN. Execution then
continues as usual. No errors are raised at the moment.
'''
@guilespi
guilespi / row-operation.clj
Created October 29, 2012 02:59
Iterating over a dataset to apply specific functions to each row
(defmacro apply-filtered
"Given two sequences, apply a function to each pair of elements when condition is met
anaphoras n and m exists for each indexed element
e.g. (apply-filtered / [1 2 3] [1 0 3] when (> m 0)) => (1 nil 1)
"
[op a b & condition]
`(for [x# (range (count ~a))]
(let [n# (nth ~a x#)
@guilespi
guilespi / run.clj
Created October 29, 2012 03:02
Running the QSTK tutorial in clojure
(defn run
[]
(let [symbols ["AAPL","GLD","GOOG","$SPX","XOM"]
start-day (date-time 2012 1 1)
end-day (date-time 2012 12 31)
time-of-day (hours 16)
timestamps (get-NYSE-days start-day end-day time-of-day)
symbols-data (read-symbols-data "Yahoo" symbols)
adj-close-data (incanter.core/to-dataset
(get-data timestamps symbols (keyword "Adj Close") symbols-data time-of-day))]
@guilespi
guilespi / qstk-tutorial1.clj
Created October 29, 2012 03:05
QSTK Tutorial 1 in Clojure
(ns qstk.tutorial1
(:use [clj-time.core :exclude 'extend])
(:use clj-time.format)
(:use clj-time.coerce)
(:require incanter.io)
(:require incanter.core))
(def ^{:dynamic true} *QS* (get (System/getenv) "QS"))
(defn get-NYSE-days
@guilespi
guilespi / questions by category.sql
Created October 31, 2012 01:42
How many language questions are in each difficulty category
DECLARE @tagname varchar(20) = ##language:string##
select DifficultyGroup, Count(1) Total,
avg(cast(ResponseTime as bigint)) as Average,
stdev(cast(ResponseTime as bigint)) as StandardDev
from
(SELECT
Questions.CreationDate,
Questions.Title,
Tags.TagName,
@guilespi
guilespi / response time by hour.sql
Created October 31, 2012 01:43
StackOverflow response times by language, grouped by hour
DECLARE @tagname varchar(20) = ##language:string##
select ResponseHour,
avg(cast(ResponseTime as bigint)) as Average,
stdev(cast(ResponseTime as bigint)) as StandardDev
from
(SELECT
Questions.CreationDate,
Questions.Title,