from tradersbot import TradersBot '''t = TradersBot('mangocore.pw:10914', '*****@*****.**', 'never-open-students')''' t = TradersBot('localhost', 'trader0', 'trader0') C = ['EUR', 'USD', 'CHF', 'JPY', 'CAD'] id = {'EUR': 0, 'USD': 1, 'CHF': 2, 'JPY': 3, 'CAD': 4} LP = {} for cur in C: LP[cur] = {} for cur2 in C: LP[cur][cur2] = 0.0 def conv(a, b): if id[a] > id[b]: a, b = b, a return a + b count = 0 def f(msg, order): global count count += 1 if count < 10: count += 1 return else: count = 0
import mibian ''' c = mibian.GK([1.4565, 1.45, 1, 2, 30], volatility=20) print c.callPrice ''' from tradersbot import TradersBot import time t = TradersBot('mangocore.pw', '*****@*****.**', 'never-open-students') '''t = TradersBot('localhost', 'trader0', 'trader0')''' P = {90: 0.0, 95: 0.0, 100: 0.0, 105: 0.0, 110: 0.0} C = {90: 0.0, 95: 0.0, 100: 0.0, 105: 0.0, 110: 0.0} TMX = 100.0 vols = {90: 0.0, 95: 0.0, 100: 0.0, 105: 0.0, 110: 0.0} prices = [90, 95, 100, 105, 110] endTime = time.time()+450 def calc(): global TMX global endTime for K in prices: c = mibian.BS([TMX, K, 0.0, (endTime-time.time())/15.0], callPrice = C[K]) VOL = c.impliedVolatility print VOL vols[K] = VOL print count = 0 def upd(msg, order):
'sold': False, 'done': False, 'dark_at_news': None, 'dark_at_eval': None, 'dark_advantage': None } pending_orders.append(new_order) except: print('Unable to parse headline: Unknown error') DEBUG = True algo_bot = None if len(sys.argv) >= 4: algo_bot = TradersBot(host=sys.argv[1], id=sys.argv[2], password=sys.argv[3]) # DEBUG = False CANCEL_TRADES = False else: algo_bot = TradersBot('127.0.0.1', 'trader0', 'trader0') algo_bot.onAckRegister = onAckRegister algo_bot.onMarketUpdate = onMarketUpdate algo_bot.onTraderUpdate = onTraderUpdate algo_bot.onTrade = onTrade algo_bot.onAckModifyOrders = onAckModifyOrders algo_bot.onNews = onNews if not DEBUG: def f(*args):
from tradersbot import TradersBot from assignQValue import estimate_distribution_mean #initialize tradersbot t = TradersBot('localhost', 'trader0', 'trader0') buzz = {'TRA': [], 'DER': [], 'SA': [], 'TM': [], 'IT': []} assoc = {'TRA': [], 'DER': [], 'SA': [], 'TM': [], 'IT': []} alpha = {'TRA': [], 'DER': [], 'SA': [], 'TM': [], 'IT': []} god = {'TRA': [], 'DER': [], 'SA': [], 'TM': [], 'IT': []} buzz_time = [] assoc_time = [] alpha_time = [] god_time = [] #gets estimation data from news def news_Callback(msg, TradersOrder): temp = msg["news"]["body"].split(";") tempTRA = temp[0].split(" ") tempDER = temp[1].split(" ") tempSA = temp[2].split(" ") tempTM = temp[3].split(" ") tempIT = temp[4].split(" ") if msg["news"]["source"] == 'Buzzfeed': buzz['TRA'].append(float(tempTRA[-1])) buzz['DER'].append(float(tempDER[-1])) buzz['SA'].append(float(tempSA[-1])) buzz['TM'].append(float(tempTM[-1])) buzz['IT'].append(float(tempIT[-1]))
from model import ridge_model_comp from tradersbot import TradersBot import numpy as np hostname = 'mangocore.pw' username = '******' password = '******' t = TradersBot(hostname, username, password) ridge = ridge_model_comp() news = [] def updatePredict(msg, order): newsBody = msg["news"]["body"] newsBody = str(newsBody).split(' ') vals = [float(item.replace(';','')) for item in newsBody if ';' in item] vals.append(float(newsBody[-1])) news.append(vals) print 'Data ', news if len(news) >= 2: x = [] d1 = np.array(news[-2]) d0 = np.delete(np.array(news[-1]),[2]) x = np.append(x, d0) x = np.append(x,d1) print 'Prediction: ', ridge.predict([x])[0] t.onNews = updatePredict def hi(msg,order): print "hey"
from tradersbot import TradersBot import argparse import csv import pandas as pd import statsmodels.formula.api as smf import math ### TRADERSBOT INITIALIZATION parser = argparse.ArgumentParser(description='Run a TradersBot') parser.add_argument('--addr', help='IP/URL', default='127.0.0.1') parser.add_argument('--user', help='Username', default='trader0') parser.add_argument('--pw', help='Password', default='trader0') args = parser.parse_args() t = TradersBot(args.addr, args.user, args.pw) ### GLOBAL VARIABLES case_meta = {} model = {} res = {} outcry_data = [] pred_counter = 1 ### HELPER FUNCTIONS def center_data(lst): # center data to mean 0, variance 1 mean = sum(lst) / float(len(lst))
from tradersbot import TradersBot import math from scipy.stats import norm import datetime import time import random t = TradersBot('127.0.0.1', 'trader0', 'trader0') START_TIME = time.time() def exp_time(): global START_TIME return (time.time() - START_TIME) / (7.5 * 60 * 12) DELTA_MAX = 1000 VEGA_MAX = 9000 INTEREST_RATE = 0 TRADE_FEE = 0.005 OPTIONS_LIM = 5000 FUTURES_LIM = 2500 # 1. Exploit inconsistencies in implied volatility across different strike prices # 2. Market make when spreads are large, without becoming overly exposed to risk # 3. Hedge positions to reduce risk # Our portfolio. Keeps track of: # List of our securities # - all default information
from tradersbot import TradersBot t = TradersBot('127.0.0.1:10914', 'trader0', 'trader0')
from tradersbot import TradersBot import numpy as np import random from math import * t = TradersBot(host='127.0.0.1', id='trader0', password='******') tick = 0 dx = .01 tickers = ['USDCHF','USDJPY','EURUSD','USDCAD','CHFJPY','EURJPY','EURCHF','EURCAD' ] public_ticker = {'USDCAD','EURUSD','USDCHF','USDJPY'} dark_tickers = {'EURCAD','EURJPY','EURCHF','CHFJPY'} price_list = {} for tc in tickers: price_list[tc] = [] def on_update(msg,order): global tick ms = msg['market_state'] tck = ms['ticker'] last_price = msg['market_state']['last_price'] price_list[tck].append(last_price) #if tck in dark_tickers: print(ms) if len(price_list[tck]) > 5: sma = np.mean(np.array(price_list[tck][-6:-1])) diff = abs(sma - last_price)/last_price diff *= (10/0.015)
from tradersbot import TradersBot '''t = TradersBot('mangocore.pw:10914', '*****@*****.**', 'never-open-students')''' t = TradersBot('localhost', 'trader0', 'trader0') def showNews(msg, order): a = msg['news']['body'].split() val = [] for word in a: word = word.strip(';') try: num = float(word) val.append(num) except: continue print val idx = t.onNews = showNews t.run()
from tradersbot import TradersBot from spread import calc_spread from buy import update from volatility import ack_register, calc_reg t = TradersBot('127.0.0.1', 'trader0', 'trader0') def main(): t.onAckRegister = ack_register t.onMarketUpdate = calc_reg t.onTrade = update t.run() if __name__ == "__main__": main()
from tradersbot import TradersBot t = TradersBot('mangocore.pw', '*****@*****.**', 'never-open-students') '''t = TradersBot('localhost', 'trader0', 'trader0')''' def showNews(msg, order): a = msg['news']['body'].split() val = [] for word in a: word = word.strip(';') try: num = float(word) val.append(num) except: continue print val idx = 1007.000526+0.003418564*(val[0])+0.625699427*(val[1])+0.000172214*(val[3])-0.332956566*(val[4])+0.886297842*(val[5])-0.000955673*(val[6])-0.003855885*(val[7])-0.001290652*(val[8])-0.005253481*(val[9]) print 'Estimated index: ' + str(idx) t.onNews = showNews t.run()
### IMPORTS from tradersbot import TradersBot import argparse import time ### TRADERSBOT INITIALIZATION parser = argparse.ArgumentParser(description='Run a TradersBot') parser.add_argument('--addr', help='IP/URL', default='127.0.0.1') parser.add_argument('--user', help='Username', default='trader0') parser.add_argument('--pw', help='Password', default='trader0') parser.add_argument('--threshold', help='Arbitrage Threshold', default=0.005) args = parser.parse_args() t = TradersBot(args.addr, args.user, args.pw) ### GLOBAL VARIABLES case_meta = {} orderbook = {} cash = {'USD': 100000, 'JPY': 0, 'EUR': 0, 'CHF': 0, 'CAD': 0} cycles = [['EURCHF', 'CHFJPY', 'EURJPY'], ['USDCAD', 'EURUSD', 'EURCAD'], ['CHFJPY', 'USDCHF', 'USDJPY']] time_last_order = time.time() # prevent order overflow time_last_clear = time.time() time_last_threshold_update = time.time() arb_threshold = float(args.threshold) pnl_deltas = [0 for _ in range(5)] current_pnl = 1 transaction_fee = 0.0001
import math import time import argparse import scipy.optimize import matplotlib.pyplot as plt from scipy.stats import norm ### TRADERSBOT INITIALIZATION parser = argparse.ArgumentParser(description='Run a TradersBot') parser.add_argument('--addr', help='IP/URL', default='127.0.0.1') parser.add_argument('--user', help='Username', default='trader0') parser.add_argument('--pw', help='Password', default='trader0') args = parser.parse_args() t = TradersBot(args.addr, args.user, args.pw) ### GLOBAL VARIABLES case_meta = {} orderbook = {} total_time = 450 elapsed_time = 0 implied_vols = { 'T100C': 1, 'T110P': 1, 'T105C': 1, 'T105P': 1, 'T110C': 1, 'T110P': 1, 'T90C': 1,
from tradersbot import TradersBot t = TradersBot('160.39.148.119', 'trader0', 'trader0')