def find_data_based_trading_opportunities(candidates=[ ]): if len(candidates)==0: for q_id in summarizequestions.by_id.keys(): if opinions.has_key(q_id): continue if q_id in DO_NOT_TRUST_CONSENSUS: continue q = summarizequestions.by_id[q_id] if q['question']['settlement_at'] == None: settled_at = datetime(2050,1,1,0,0,0) else: settled_at = datetime.strptime(q['question']['settlement_at'][0:19], "%Y-%m-%dT%H:%M:%S") if settled_at < datetime.now() + timedelta(2): continue if q['trade_count']>60: candidates.append(q_id) candidates = list(set(candidates)) candidates.sort(key=lambda q_id: summarizequestions.by_id[q_id]['trade_count'], reverse=True) candidates = candidates#[:60] # (my_final_score, credit, final_standing, estdeb, s) output = [ ] for candidate in candidates: res = determine_trade_from_data(candidate) if res: output.append(res) output.sort(key=lambda x: x[3], reverse=True) for score, credit, final_standing, estdeb, v, steps in output: if estdeb > 0.666 or VERBOSE: print v
comment_range[1] = max(comment_range[1], q['comment_count']) by_id[ q['question']['id'] ] = q if options.show_stats: print "questions:", len(data) print "trade range:", trade_range print "comment range:", comment_range print "low trade count questions:", len(low_trade_qs) new = set([]) if options.show_new: print "************ NEW QUESTIONS" for q in sorted(low_trade_qs, key=lambda q: (q['trade_count'], q['question']['id'])): qid = q['question']['id'] if opinions.has_key(qid) or (qid in boring): # i'm already aware of this one continue new.add(qid) print "(%i) id %i \"%s\"" % (q['trade_count'], q['question']['id'], q['question']['name']) def outcomes(start, stop): if start>=0.999: start = 0.999 elif start<=0.001: start = 0.001 if stop>=0.999: stop = 0.999 elif stop<=0.001: stop = 0.001 true = 100.0 * math.log(start / stop) / math.log(2.0)
by_id[q['question']['id']] = q if options.show_stats: print "questions:", len(data) print "trade range:", trade_range print "comment range:", comment_range print "low trade count questions:", len(low_trade_qs) new = set([]) if options.show_new: print "************ NEW QUESTIONS" for q in sorted(low_trade_qs, key=lambda q: (q['trade_count'], q['question']['id'])): qid = q['question']['id'] if opinions.has_key(qid) or (qid in boring): # i'm already aware of this one continue new.add(qid) print "(%i) id %i \"%s\"" % (q['trade_count'], q['question']['id'], q['question']['name']) def outcomes(start, stop): if start >= 0.999: start = 0.999 elif start <= 0.001: start = 0.001 if stop >= 0.999: stop = 0.999 elif stop <= 0.001:
if __name__ == '__main__': from optparse import OptionParser parser = OptionParser() parser.add_option("-b", action="store_true", default=False, dest="back_out", help="Back out of existing position?") parser.add_option("-o", action="store_true", default=False, dest="optimal", help="Find optimal, opinion-based, trades") parser.add_option("-d", action="store_true", default=False, dest="data_based", help="Find optimal, data-based, trades") (options, args) = parser.parse_args() args = map(int, args) have_opinions = filter(lambda id: opinions.has_key(id), args) no_opinion = filter(lambda id: not opinions.has_key(id), args) if len(args)>0: if len(have_opinions) and (options.optimal==True or options.data_based==False): find_optimal_trading_opportunities(have_opinions, back_out=options.back_out) if len(no_opinion) and (options.optimal==False or options.data_based==True): find_data_based_trading_opportunities(no_opinion) else: if options.optimal or options.data_based==False: find_optimal_trading_opportunities(back_out=options.back_out) if options.data_based: find_data_based_trading_opportunities()