Skip to content

Instantly share code, notes, and snippets.

Avatar

Ran Aroussi ranaroussi

View GitHub Profile
@ranaroussi
ranaroussi / redison.py
Last active Oct 6, 2020
Redison - extension for redis to get/set json objects
View redison.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Redison - an extension for redis to get/set json objects
# https://gist.github.com/ranaroussi/90268aca3bf438d1aabfdb918288c6a9/edit
#
# Copyright 2020 Ran Aroussi
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
View Clone-Github-Wiki-Pages.sh
hanxue-mac:Github hanxue$ git clone https://github.com/AppScale/appscale.wiki.git
Cloning into 'appscale.wiki'...
remote: Counting objects: 1745, done.
remote: Compressing objects: 100% (1733/1733), done.
remote: Total 1745 (delta 1089), reused 10 (delta 4)
Receiving objects: 100% (1745/1745), 267.93 KiB | 35.00 KiB/s, done.
Resolving deltas: 100% (1089/1089), done.
Checking connectivity... done
hanxue-mac:Github hanxue$ ls appscale.wiki/
.git/
@ranaroussi
ranaroussi / riskfree.py
Created Jun 28, 2020
Daily Risk Free Rate (based on 3-Month US Treasury Bills Rates)
View riskfree.py
import yfinance as yf
import pandas as pd
# de-annualize yearly interest rates
def deannualize(annual_rate, periods=365):
return (1 + annual_rate) ** (1/periods) - 1
def get_risk_free_rate():
# download 3-month us treasury bills rates
annualized = yf.download("^IRX")["Adj Close"]
@ranaroussi
ranaroussi / tradehook.py
Last active Mar 14, 2020
Tradologics - example algo
View tradehook.py
# mycode.py
import tradologics
def tradehook(payload):
payload = tradologics.parse(payload)
# is this a "data" payload?
if payload.event == "data":
for asset in payload.data:
@ranaroussi
ranaroussi / multi-mysqli.php
Last active Jan 9, 2020
Multi-Server MySQLi class
View multi-mysqli.php
<?php
/**
* Multi-Server MySQLi class
* https://gist.github.com/ranaroussi/64a26c9a2ec6d69c62ba7c650f49a8a0
*
* Copyright 2013-2020 Ran Aroussi
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@ranaroussi
ranaroussi / optimizeparams.py
Created Dec 3, 2019
Strategy param optimizer module
View optimizeparams.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import matplotlib as _mpl
import matplotlib.pyplot as _plt
from mpl_toolkits.mplot3d import Axes3D as _Axes3D
import numpy as _np
import pandas as _pd
@ranaroussi
ranaroussi / nasdaq_premarket.py
Last active Aug 30, 2020
gets premarket prices from nasdaq
View nasdaq_premarket.py
import requests
def get_premarket(ticker):
"""
gets premarket prices from nasdaq
usage:
>> price, volume = get_premarket('spy')
"""
@ranaroussi
ranaroussi / resampler.py
Created Sep 18, 2019
QTPyLib timeseries resampler
View resampler.py
import pandas as pd
def resample(data, resolution="1T", tz=None, ffill=True, dropna=False):
"""
>>> resample(df, '500K') # resample 500 ticks (by counting trades)
>>> resample(df, '500V') # resample ~500 volume (by counting volume)
"""
def __finalize(data, tz=None):
# figure out timezone
@ranaroussi
ranaroussi / runner.py
Created Aug 19, 2019
Python Job Runner
View runner.py
#!/usr/bin/env python
import subprocess
import time
import sys
import logging
class Job:
"""
monitors that a job is running and executing it when it's not
@ranaroussi
ranaroussi / get_active_contracts.py
Created May 20, 2019
get active futures contract
View get_active_contracts.py
#!/usr/bin/env python
from dateutil.parser import parse as parse_date
import datetime
import requests
import pandas as pd
def get_contracts(url):
html = requests.get(url, timeout=5)