def __init__(self, subparsers): data_fetch_cli_parser = subparsers.add_parser('data_fetch', help='Commands for fetching bluetooth logs') data_fetch_cli_parser.add_argument('-s', '--start', action='store_true', help="Start fetching data") data_fetch_cli_parser.add_argument('-t', '--timeout', help="Set timeout for fetching logs") data_fetch_cli_parser.add_argument('-dst', '--destination', help="Set destination for storing logs") data_fetch_cli_parser.set_defaults(func=self.__parse) self.__data_fetch = DataFetch()
def __init__(self): self.df = DataFetch() self.ua = self.df.load_data(USER_AUTHOR) self.ub = self.df.load_data(USER_BLOG) self.ut = self.df.load_data(USER_TAGS) #self.ul = self.df.load_data(USER_LANGUAGE) self.posts = pickle.load(open("posts_dict_all.p", "rb")) self.test_sample = pickle.load(open(TEST_SAMPLE_FILE,"rb")) self.a_coef = 0.33 self.b_coef = 0.33 self.t_coef = 0.33
class DataFetchCli: def __init__(self, subparsers): data_fetch_cli_parser = subparsers.add_parser('data_fetch', help='Commands for fetching bluetooth logs') data_fetch_cli_parser.add_argument('-s', '--start', action='store_true', help="Start fetching data") data_fetch_cli_parser.add_argument('-t', '--timeout', help="Set timeout for fetching logs") data_fetch_cli_parser.add_argument('-dst', '--destination', help="Set destination for storing logs") data_fetch_cli_parser.set_defaults(func=self.__parse) self.__data_fetch = DataFetch() def __parse(self, args): if args.timeout is not None: self.__data_fetch.set_timeout(int(args.timeout)) if args.destination is not None: self.__data_fetch.set_destination(args.destination) if args.start: self.__data_fetch.start()
from db_connection import DBConnection from data_fetch import DataFetch from technical_indicators import TechnicalIndicators from trading_signals import TradingSignals from trade_sim import TradeSimulation from datetime import datetime start = datetime.now() mysql_conn = DBConnection().mysql_engine() data_fetch = DataFetch(mysql_conn) data_fetch.get_equities() data_fetch.get_dividends() tech_ind = TechnicalIndicators(mysql_conn) tech_ind.calc_tech_indicators() trade_sig = TradingSignals(mysql_conn) trade_sig.calc_signals() simulation = TradeSimulation(mysql_conn) simulation.run_simulation() print(datetime.now() - start)
class Predictions: def __init__(self): self.df = DataFetch() self.ua = self.df.load_data(USER_AUTHOR) self.ub = self.df.load_data(USER_BLOG) self.ut = self.df.load_data(USER_TAGS) #self.ul = self.df.load_data(USER_LANGUAGE) self.posts = pickle.load(open("posts_dict_all.p", "rb")) self.test_sample = pickle.load(open(TEST_SAMPLE_FILE,"rb")) self.a_coef = 0.33 self.b_coef = 0.33 self.t_coef = 0.33 def logistic(self): dimx = len(self.ua) dimy = 3 ymat = np.zeros((dimx, dimy)) ctr = 0 for k,v in self.ua.iteritems(): user = k a_val = v try: b_val = self.ub[user] except: b_val = 0.0 try: t_val = self.ut[user] except: t_val = 0.0 ymat[ctr][0] = a_val ymat[ctr][1] = b_val ymat[ctr][2] = t_val ctr+=1 print ymat def no_logic(self, test_sample): # Operate on values without any modification of weights. threshold = 0.00072 predicted_list = [] for (i,j,b,a,t,l) in test_sample: U = str(i) post = str(j) try: P = self.posts[post] A = self.posts[post]["author"] if not None else 0 B = self.posts[post]["blog"] if not None else 0 T = self.posts[post]["tags"] if not None else 0 a_val = 0.0 + self.ua[U][A] b_val = 0.0 + self.ub[U][B] t_val = 0.0 for tag in T: try: t_val+= 0.0 + self.ut[U][tag] except: t_val+= 0.0 except Exception, e: print "In except" print e print len(self.posts) A = a B = b T = t try: a_val = 0.0 + self.ua[U][A] except: a_val = 0.0 try: b_val = 0.0 + self.ub[U][B] except: b_val = 0.0 t_val = 0.0 try: for tag in T: try: t_val+= 0.0 + self.ut[U][tag] except: t_val+= 0.0 except: t_val+=0.0 #print "Values for a_val {}, b_val {} and t_val {}".format(a_val,b_val,t_val) val = 0.0 + (self.a_coef * a_val) + (self.b_coef * b_val) + (self.t_coef * t_val) if val>threshold: label = 1 else: label = 0 predicted_list.append((i,j,l,label)) return predicted_list