Пример #1
0
def find_orders(job):
    buyers = []
    with open("../" + trader_utils.trader_orders_filepath()) as f:
        reader = csv.reader(f)
        for row in reader:
            if row[0][0] == job and row[0] not in buyers:
                buyers.append(row[0])
    return buyers
Пример #2
0
def find_nongvwy_transactions():
    count = 0
    with open("../" + trader_utils.trader_orders_filepath()) as f:
        reader = csv.reader(f)
        for row in reader:
            if row[2] != row[3]:
                count += 1
    return count    
Пример #3
0
def plot_order_vs_limit(tids,all,job):
    with open("../" + trader_utils.trader_orders_filepath()) as f:
        reader = csv.reader(f)

        traders = {}
        # Keep track of every value so that we can plot more acurately
        points = []
        augmented = False

        for row in reader:
            tid = row[0]
            time = row[4]

            order_price = row[3]
            points.append(float(order_price))
            # if order_price <= 5 or order_price >= 900:
            #     order_price = None

            limit_price = row[2]
            try: points.append(float(limit_price))
            except Exception: pdb.set_trace()

            if len(row) > 5:
                equilibrium = float(row[5])
                points.append(float(equilibrium))
            else:
                equilibrium = None

            if len(row) > 6:
                r = float(row[6])
            else:
                r = None

            if len(row) > 7:
                try:
                    tau = float(row[7])
                except Exception:
                    pdb.set_trace()
            else:
                tau = None

            if len(row) > 8:
                agg_r = float(row[8])
                augmented = True
            else:
                agg_r = None


            if tid in tids:
                if not tid in traders:
                    trader = {}
                    trader['times'] = array([time])
                    trader['orders'] = array([order_price])
                    trader['limits'] = array([limit_price])
                    trader['equilibriums'] = array([equilibrium])
                    trader['rs'] = array([r])
                    trader['agg_rs'] = array([agg_r])
                    trader['taus'] = array([tau])
                else:
                    trader = traders[tid]
                    trader['times'] = vstack((trader['times'],time))
                    trader['orders'] = vstack((trader['orders'],order_price))
                    trader['limits'] = vstack((trader['limits'],limit_price))
                    trader['equilibriums'] = vstack((trader['equilibriums'],equilibrium))
                    trader['rs'] = vstack((trader['rs'],r))
                    trader['agg_rs'] = vstack((trader['agg_rs'],agg_r))
                    trader['taus'] = vstack((trader['taus'],tau))

                traders[tid] = trader

    (all_ts, transactions) = get_transactions()

    # pdb.set_trace()

    maximum = max(all_ts[:,1]) + 50
    minimum = min(all_ts[:,1]) - 50

    xlimit = (all_ts[0,0],all_ts[-1,0]*1.2)

    if augmented: number_of_plots = 3
    else: number_of_plots = 2

    square = int(ceil(sqrt(len(tids))))
    plot_index = 0
    for tid in traders:
        trader = traders[tid]
        
        if all:
            subplot(square, square, plot_index)
        else:
            subplot(number_of_plots, 1, 0)

        ylim((minimum, maximum))
        if not all: xlim(xlimit)
        plot(trader['times'],trader['limits'],'b.')
        
        plot(trader['times'],trader['orders'],'r.')
        plot(trader['times'],trader['equilibriums'],'k-')
        # try:
        #     if 'taus' in trader:
        #         plot(trader['times'],trader['taus'],'r--')            
        # except Exception:
        #     pdb.set_trace()

        plot(all_ts[:,0],all_ts[:,1],'cx',markersize=4)
        xlabel("time")
        ylabel("Price")
        if tid in transactions:
            if count_nonzero(transactions[tid]) == 2:
                plot(transactions[tid][0],transactions[tid][1], 'y*', markersize=10)
            else:
                plot(transactions[tid][:,0],transactions[tid][:,1], 'y*', markersize=10)

        
        if not all:
            legend(['Limit price', 'Order price', 'Equilibrium', 'Target Price', 'Market ts', 'Trader ts'])

            subplot(number_of_plots, 1, 1)    
            xlim(xlimit)   
            if job == 'S':
                title('Seller Trader AAA aggressiveness vs transactions')
            else:
                title('Buyer Trader AAA aggressiveness vs transactions')
            plot(trader['times'],trader['rs'],'b-')

            ylabel("Aggressiveness, r")
            if augmented:
                subplot(number_of_plots, 1, 2)       
                ylabel("Augmented Agg, r")
                plot(trader['times'],trader['agg_rs'],'b--')
            show()

        plot_index += 1

    if all:
        if job == 'S':
            suptitle('Seller Trader AAA transactions overview')
        else:
            suptitle('Buyer Trader AAA transactions overview')

    # while plot_index < square**2:
    #     print plot_index
    #     axes[plot_index].axis('off')
    #     plot_index += 1

    show()