Skip to content

Instantly share code, notes, and snippets.

@mjbommar
mjbommar / archiveTwitter.py
Created February 26, 2011 19:49
Archive tweets from a search term going backwards through search.
'''
@author Michael J Bommarito II
@date Feb 26, 2011
@license Simplified BSD, (C) 2011.
This script demonstrates how to use Python to archive historical tweets.
'''
import codecs
import csv
@mjbommar
mjbommar / analyzeWIUNION.r
Created February 22, 2011 01:46
Plot some figures for the #wiunion Twitter tag.
# @author: Michael J Bommarito II
# @date: Feb 21, 2011
# @email: [email protected]
# @packages: ggplot2
library(ggplot2)
setwd('/data/workspace/blog/wiunion/')
# Load and pre-process #tweets_wiunion
@mjbommar
mjbommar / plotCN220Network3D.py
Created February 21, 2011 17:39
Plot the network of the first 1000 #cn220 tweets with igraph and cairo.
'''
@author Michael J Bommarito II
@contact [email protected]
@date Feb 21, 2011
@license Simplified BSD, (C) 2011.
Plot the network of the first 1000 #cn220 tweets with igraph and cairo.
'''
import cairo
@mjbommar
mjbommar / archiveHashtag.r
Created February 21, 2011 05:57
Archive a twitter hashtag.
#@author Michael J Bommarito
#@contact [email protected]
#@date Feb 20, 2011
#@ip Simplified BSD, (C) 2011.
# This is a simple example of an R script that will retrieve
# public tweets from a given hashtag.
library(RJSONIO)
# This function loads stored tag data to determine the current max_id.
# @author: Michael J Bommarito II
# @date: Feb 20, 2011
# @email: [email protected]
# @packages: gridExtra, ggplot2
library(gridExtra)
library(ggplot2)
setwd('/data/workspace/blog/cn220/')
@mjbommar
mjbommar / NLTK_TM_doR.r
Created February 16, 2011 14:57
Comparison of NLTK and tm.
#@author Michael J Bommarito II
#@date Feb 16, 2011
library(tm)
# Load the tweets
tweets <- unique(read.table('data/tweets_25bahman.csv', sep="\t", quote="", comment.char="", header=FALSE, nrows=100000, stringsAsFactors=FALSE))
names(tweets) <- c("id", "date", "user", "text")
# Build the corpus and then apply the tm pre-processing methods
@mjbommar
mjbommar / NLTK_TM_doNLTK2.py
Created February 16, 2011 14:56
Compare speeds of NLTK and tm.
'''
@author Michael J Bommarito II
@date Feb 16, 2011
'''
import codecs
import dateutil.parser
import multiprocessing
import nltk
@mjbommar
mjbommar / updatePOMO.py
Created October 29, 2010 11:24
Update Permanent Open Market Operation data directly from NYFRB
import csv
import datetime
import dateutil.parser
import lxml, lxml.etree
import urllib2
# Setup date-related variables
today = datetime.date.today()
todayString = today.strftime('%m/%d/%Y')
rangeString = '20050825_{0}'.format(today.strftime('%Y%m%d'))
%% Initialize
clear all;
startDate = datenum('2005-08-25');
endDate = datenum('2010-10-20');
dateRange = busdays(startDate, endDate);
%% Load SPY data
csvFile = fopen('data/SPY.csv', 'r');
csvFields = textscan(csvFile, '%s %f %f %f %f %f %f',-1,'delimiter',',','HeaderLines',1);
fclose(csvFile);
@mjbommar
mjbommar / processPOMO.py
Created October 26, 2010 13:45
Process the Permanent Open Market Operation (POMO) XML data from the NY Federal Reserve Bank.
import csv
import dateutil.parser
import lxml, lxml.etree
rangeString = '20050825_20101025'
xmlRoot = lxml.etree.parse("data/pomo_{0}.xml".format(rangeString)).getroot()
xmlData = xmlRoot.getchildren()[1]
pomoData = []