Skip to content

Instantly share code, notes, and snippets.

@zackster
zackster / process_8k.rb
Created August 29, 2016 16:48
Script for processing SEC 8-K filings en masse
require 'nokogiri'
require 'pg'
require 'json'
require 'parallel'
require 'timeout'
def score( array )
array.each_with_object(Hash.new(0)){|key,hash| hash[key] += 1}
end
@zackster
zackster / download_8k_indexes.rb
Created August 29, 2016 16:08
Download 8-K filings from the SEC
require 'posix/spawn'
require 'pry'
require 'active_support/all'
years = (2010..2016).to_a
quarters = (1..4).to_a
@zackster
zackster / StockTwits_API_SQS_worker .rb
Last active July 19, 2016 03:03
This worker will post messages from an Amazon SQS queue via the StockTwits API. It requires you to have an access_token (obtained via the Stocktwits API) and an SQS queue with messages containing the contents of your StockTwits messages. It respects the StockTwits API rate limitations through an exponential backoff algo.
require 'aws-sdk'
require 'unirest'
require 'pp'
STOCKTWITS_QUEUE_URL = 'PATH TO YOUR QUEUE GOES HERE...' # looks like https://sqs.REGION.amazonaws.com/######/name
STOCKTWITS_API_URL = 'https://api.stocktwits.com/api/2/messages/create.json?access_token=ACCESS_TOKEN_OF_STOCKTWITS_USER_TO_POST'
Aws.config.update({
region: 'REGION',
credentials: Aws::Credentials.new('ACCESS KEY', 'SECRET')
# credit to this person for a js implementation of the function, http://stackoverflow.com/users/3473058/user3473058
def find_local_maxima(input_array)
goAsc = false # ascending move
goDesc = false # descending move
local_maxima = []
index = 0
while (index < (input_array.length - 1)) do
require 'mysql2'
client = Mysql2::Client.new(:host => "localhost", :username => "*USERNAME*", :password => "*PASSWORD*", :database => "*DATABASENAME*", :local_infile => true)
puts 'Downloading EOD data'
system('curl -J -L -oeod https://www.quandl.com/api/v3/databases/EOD/data?auth_token=**AUTHTOKEN**')
puts 'UnZIPPING EOD Data'
system('unzip -p eod > eod2')
puts 'Filtering out EOD Data before 2014'
system('awk -F, \'$2 > "2014" {print}\' eod2 > eod_since_2014')
puts 'Dropping the EOD table'
client.query("DROP TABLE adj_eod")
hermione@localhost:/var/www/laduree/current$ ls -la public/assets/
total 836
drwxrwxr-x 11 hermione hermione 4096 Feb 20 01:10 .
drwxrwxr-x 3 hermione hermione 4096 Feb 20 01:07 ..
-rw-rw-r-- 1 hermione hermione 493891 Jan 29 21:38 application-96cd30a6dfe95592f924694e874e8ac3.js
-rw-rw-r-- 1 hermione hermione 132384 Jan 29 21:38 application-96cd30a6dfe95592f924694e874e8ac3.js.gz
-rw-rw-r-- 1 hermione hermione 105384 Feb 20 00:23 application-d5d25d4b43c2c8534e0fedfdc933c0d4.css
-rw-rw-r-- 1 hermione hermione 18242 Feb 20 00:23 application-d5d25d4b43c2c8534e0fedfdc933c0d4.css.gz
drwxrwxr-x 2 hermione hermione 4096 Feb 20 01:10 blue-on-light
drwxrwxr-x 2 hermione hermione 4096 Feb 20 01:10 brand_logos
Zackattack::Application.configure do
# Settings specified here will take precedence over those in config/application.rb
# Code is not reloaded between requests
config.cache_classes = true
# Full error reports are disabled and caching is turned on
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
csv:
time, price
read in csv; populate array:
price_data = [[time,price],[time,price]]
sort array on time
pct_aggregate = [];
pct_aggregate_summed = [];
sample input
vol, time, price
10, 1:00pm, 5
10, 1:01pm, 5.05
10, 1:03pm, 5.025
10, 1:04pm, 4.99
10, 1:05pm, 4.99499
should give output of...
root@localhost:/usr/local/rvm/gems/ruby-2.0.0-p0/gems# gem install memcached
Building native extensions. This could take a while...
ERROR: Error installing memcached:
ERROR: Failed to build gem native extension.
/usr/local/rvm/rubies/ruby-2.0.0-p0/bin/ruby extconf.rb
extconf.rb:7:in `<main>': Use RbConfig instead of obsolete and deprecated Config.
extconf.rb:7:in `<main>': Use RbConfig instead of obsolete and deprecated Config.
extconf.rb:8:in `<main>': Use RbConfig instead of obsolete and deprecated Config.
extconf.rb:10:in `<main>': Use RbConfig instead of obsolete and deprecated Config.