This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import glob | |
import tqdm | |
import requests | |
import json | |
import yaml | |
import subprocess | |
import os | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy | |
import scipy.optimize | |
import pandas | |
def probability_constraint(x): | |
j, n = x.shape | |
Aeq = numpy.ones([1, j]) | |
beq = numpy.array([1.]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import multiprocessing | |
import numpy | |
import functools | |
import tqdm | |
def _escapable_child(f, args): | |
# help prevent any forking issues with seeding the RNG | |
numpy.random.seed() | |
try: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
convert -density 150 input.pdf -colorspace gray -linear-stretch 3.5%x10% -blur 0x0.5 -attenuate 0.25 +noise Gaussian -rotate 0.5 temp.pdf | |
gs -dSAFER -dBATCH -dNOPAUSE -dNOCACHE -sDEVICE=pdfwrite -sColorConversionStrategy=LeaveColorUnchanged dAutoFilterColorImages=true -dAutoFilterGrayImages=true -dDownsampleMonoImages=true -dDownsampleGrayImages=true -dDownsampleColorImages=true -sOutputFile=output.pdf temp.pdf |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas | |
import numpy | |
import scipy.optimize | |
# based upon rules set out at https://allocatesmartly.com/adam-butler-gestaltu-adaptive-asset-allocation/ | |
tickers = ['spy', 'ezu', 'ewj', 'eem', 'vnq', 'rwx', 'ief', 'tlt', 'dbc', 'gld'] | |
# assumes tickers are .csv files in the same folder as the code | |
# with a column named 'adjusted_close' with daily adjusted closing prices | |
data = {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import urllib2 | |
months = ["F","G","H","J","K","M","N","Q","U","V","X","Z"] | |
years = ["04","05","06","07","08","09","10","11","12"] | |
for year in years: | |
for month in months: | |
filename = "CFE_" + month + year + "_VX.csv" | |
url = "http://cfe.cboe.com/Publish/ScheduledTask/MktData/datahouse/" + filename | |
try: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# A Density-Based Algorithm for Discovering Clusters in Large Spatial Databases with Noise | |
# Martin Ester, Hans-Peter Kriegel, Jörg Sander, Xiaowei Xu | |
# dbscan: density based spatial clustering of applications with noise | |
import numpy as np | |
import math | |
UNCLASSIFIED = False | |
NOISE = None |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; zip a string | |
(def s "aslgajskghkajsghkjasgjhajsghjags") | |
(def ostream (java.io.ByteArrayOutputStream.)) | |
(def gzip_ostream (java.util.zip.GZIPOutputStream. ostream)) | |
(clojure.java.io/copy s gzip_ostream) | |
(.close gzip_ostream) | |
(def bytes (java.io.ByteArrayInputStream. (.toByteArray ostream))) | |
(def gzip_istream (java.util.zip.GZIPInputStream. bytes)) |