Skip to content

Instantly share code, notes, and snippets.

@jonromero
jonromero / on_off.py
Created August 2, 2017 01:03
turn on and off wemo
from ouimeaux.environment import Environment
def on_switch(switch): print switch.name
env = Environment(on_switch, on_switch)
env.start()
print env.discover()
print env.list_switches()
switch = env.get_switch('Aeroponics plug')
print "State->", switch.get_state()
switch.on()
@jonromero
jonromero / hug.eth
Created August 25, 2016 21:56
HugCoin Address
CONTRACT ADDRESS: 0x6B365Fe592881E916dc77Ef410e5f9CE4654369A
JSON INTERFACE: [ { "constant": true, "inputs": [], "name": "name", "outputs": [ { "name": "", "type": "string", "value": "HugCoin" } ], "type": "function" }, { "constant": true, "inputs": [], "name": "totalHuggers", "outputs": [ { "name": "", "type": "uint256", "value": "1" } ], "type": "function" }, { "constant": true, "inputs": [ { "name": "", "type": "address" } ], "name": "balanceOf", "outputs": [ { "name": "", "type": "uint256", "value": "0" } ], "type": "function" }, { "constant": false, "inputs": [ { "name": "receipient_name", "type": "string" }, { "name": "_to", "type": "address" } ], "name": "giveHugTo", "outputs": [ { "name": "success", "type": "bool" } ], "type": "function" }, { "constant": false, "inputs": [], "name": "destroy", "outputs": [], "type": "function" }, { "constant": true, "inputs": [], "name": "symbol", "outputs": [ { "name": "", "type": "string", "value": "🤗" } ], "type": "function" }, { "constant": false, "inputs": [ { "n
Import numpy as np
from sklearn.cluster import MeanShift, estimate_bandwidth
data = open('f.csv', 'r').read().splitlines()
x = np.asarray(map(lambda x: float(x.split(',')[2]), data))
X = np.array(zip(x,np.zeros(len(x))), dtype=np.float)
bandwidth = estimate_bandwidth(X, quantile=0.1)
ms = MeanShift(bandwidth=bandwidth, bin_seeding=True)
ms.fit(X)
def run_algo(data):
row_iterator = data.iterrows()
(i, previous_price) = row_iterator.next()
for (timestamp, current_price) in row_iterator:
if not in_trade and (previous_price['Buy']['high'] - previous_price['Buy']['low'] > pips(strategy_data['pips_to_trigger'])):
# Triggered
# place a sell order, a TP and a SL
add_order(order_book, timestamp, current_price['Sell']['open'], "SELL")
in_trade = True
@jonromero
jonromero / simple_backtesting.py
Last active April 29, 2018 16:48
Simple but awesome
def main(strategy_file):
order_book = []
strategy_data = read_strategy(strategy_file)
# read csv files with daily data per second
data = pandas.read_pickle("../Data/EUR_USD.csv-OHLC-1M.pkl")
stats_days = run_algo(order_book, strategy_data, data)
print_stats(stats_days)
@jonromero
jonromero / for_looper.py
Created December 14, 2015 07:02
Simple (but working) backtesting function
def loop(config, oanda, strategy_data, last_price, in_trade):
response = oanda.get_prices(instruments="EUR_USD")
current_price = response.get("prices")[0].get("ask")
log_trade(config, datetime.now(), current_price, "info")
trade_id = None
if not in_trade:
if (last_price - current_price) > pips(strategy_data['pips_to_trigger']):
in_trade = True
@jonromero
jonromero / beta_calc.py
Created August 5, 2015 17:26
Calc beta of ETFs
"""
Creates db that contains the aggregated/calculated data of stocks
Jon V (darksun4@gmail.com)
07/24/2014
"""
import sys, os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", ".."))
import numpy as np
se agapaw k eisai to lakouvaki mou
@jonromero
jonromero / schema.clj
Last active December 20, 2015 22:19
Experimental schema for cljtrader
;; Returns a list of tokenized elements
(tokenizer #(.split % ":")))
;; the mapping is done here
(columns |time| |open| |high| |low| |close| |volume|)
@jonromero
jonromero / schema-live.lql
Created June 30, 2013 14:00
experimental process (in progress)
(columns (define-field "ver" 0)
(define-field "tag" 1)
(define-field "phone-model" 2)
(define-field "manufacturer" 3)
(define-field "os-ver" 4)
(define-field "app-ver" 5)
(define-field "country" 6)
(define-field "timestamp" 7)
(define-field "uuid" 8)
(tokenize (separator ":")))