Skip to content

Instantly share code, notes, and snippets.

View raddy's full-sized avatar

Rad raddy

  • Lagrange 3
View GitHub Profile
@raddy
raddy / addies.py
Last active January 8, 2022 17:35
Fetch addresses out of opcodes dump
import sys
import json
def etherscan_link(addy : str):
return f"https://etherscan.io/address/{addy}"
def formatted_addy(addy : str):
l = etherscan_link(addy)
return f"[{addy}]({l})"
@raddy
raddy / decode191.go
Created August 25, 2021 17:03
Decode personal_sign in Go
package main
import (
"fmt"
"os"
"strings"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/crypto"
@raddy
raddy / usdc_to_susd.csv
Created July 17, 2020 13:56
Curve USDC and USDT to SUSD
We can't make this file beautiful and searchable because it's too large.
,index,from,to,rate,size
3,2020-06-27 04:09:50.067495,USDC,SUSD,1.001588762375985,25000
28,2020-06-27 04:11:11.292177,USDC,SUSD,1.001588762375985,25000
53,2020-06-27 04:12:34.177547,USDC,SUSD,1.0027119623148046,25000
78,2020-06-27 04:13:56.708093,USDC,SUSD,1.003010811424284,25000
103,2020-06-27 04:15:20.536155,USDC,SUSD,1.0028803226935665,25000
128,2020-06-27 04:16:43.109911,USDC,SUSD,1.002789565214155,25000
153,2020-06-27 04:18:06.122941,USDC,SUSD,1.002789565214155,25000
178,2020-06-27 04:19:29.468458,USDC,SUSD,1.0027931408604205,25000
203,2020-06-27 04:20:52.114432,USDC,SUSD,1.0027931408604205,25000
@raddy
raddy / simple_hmm.py
Created September 19, 2018 22:39
simple hmm model
def simple_evaluate(data, states, hi=1.1, lo=0.9):
skip = len(data) - len(states)
chg = data['close'].pct_change()[skip:]
n = max(states) + 1
buys, sells = np.zeros(len(states)), np.zeros(len(states))
for i in range(n):
state = (states == i)
dex = np.append(0, state[:-1])
V = (chg.multiply(dex, axis=0)+1).cumprod()
if V[-1] > hi:
@raddy
raddy / nomics_candles.py
Created September 19, 2018 22:37
Helpers for Nomics API Candles Data
import requests
def nomics_query(q):
API_ROOT = "https://api.nomics.com/"
API_VERSION = "v1"
url = API_ROOT + API_VERSION + '/' + q
return requests.get(url)
def nomics_candles(api_key, interval, currency, start=None, end=None):
q = "candles?key={}&interval={}&currency={}".format(api_key, interval, currency)
if start:
@raddy
raddy / kelly4moments.py
Last active September 16, 2018 18:30
Optimal Kelly Fraction 4 Moments
def kelly_four_moments(mu, sigma, c3, c4):
return (c3/(3*c4) - (c3**2/c4**2 - 3*(mu**2 + sigma**2)/c4)/(3*(-c3**3/c4**3 + 9*c3*(mu**2 + sigma**2)/(2*c4**2) + np.sqrt(-4*(c3**2/c4**2 - 3*(mu**2 + sigma**2)/c4)**3
+ (-2*c3**3/c4**3 + 9*c3*(mu**2 + sigma**2)/c4**2 - 27*mu/c4)**2)/2 - 27*mu/(2*c4))**(1/3))
- (-c3**3/c4**3 + 9*c3*(mu**2 + sigma**2)/(2*c4**2) + np.sqrt(-4*(c3**2/c4**2 - 3*(mu**2 + sigma**2)/c4)**3
+ (-2*c3**3/c4**3 + 9*c3*(mu**2 + sigma**2)/c4**2 - 27*mu/c4)**2)/2 - 27*mu/(2*c4))**(1/3)/3)
@raddy
raddy / sample_higher_moments.py
Created September 12, 2018 02:09
Sample from a distribution with known skew and kurtosis
import statsmodels.sandbox.distributions.extras as extras
import scipy.interpolate as interpolate
import numpy as np
def generate_normal_four_moments(mu, sigma, skew, kurt, size=1000, sd_wide = 10):
f = extras.pdf_mvsk([mu, sigma, skew, kurt])
x = np.linspace(mu - sd_wide * sigma, mu + sd_wide * sigma, num=500)
y = [f(i) for i in x]
yy = np.cumsum(y) / np.sum(y)
inv_cdf = interpolate.interp1d(yy, x, fill_value="extrapolate")
@raddy
raddy / wealth_problems.py
Created September 2, 2018 20:34
Simple wealth maximization game
@jit
def game():
flip = np.random.binomial(1, .5)
if flip == 1:
return 1./3
return -3./10
@jit
def repeated_game(S0, f, plays=1000):
games = [game() for i in range(plays)]
@raddy
raddy / convert_equation.py
Created August 24, 2018 16:33
Convert Latex Equations to PNG (For Medium posts)
import os
import subprocess
import argparse
import shlex
FIXED = r"""\documentclass{standalone}
\usepackage{xcolor}
\usepackage{amsmath}
\usepackage[utf8]{inputenc}
\usepackage[charter]{mathdesign}
@raddy
raddy / gdax_ws.py
Last active April 13, 2018 16:49
gdax websocket simple
""" Simple websocket client wrapper """
import asyncio
import ujson
import websockets
from logging import getLogger
l = getLogger('websocket_client')
class WebsocketClient: