Exemple #1
0
    def history_to_string(self, last=True):
        """

        Generates a string representing the recorded history of an order
        :return:
        """
        s = ''
        if last:
            if self.type in ['A', 'F', 'U']:
                lasttype = self.history[-1][
                    0]  # Type of the last order applied to the order
                if lasttype == 'C':
                    s += 'Last: ' + lasttype + ' DeltaT: ' + nanoseconds_to_time(self.history[-1][1] - self.otime) +\
                         ' SZ:' + str(self.history[-1][2]) + ' P:' + str(self.history[-1][3])
                if lasttype == 'E':
                    delta = self.history[-1][1] - self.otime
                    s += f'Last: {lasttype}' + \
                         f' DeltaT: {nanoseconds_to_time(delta)}' + \
                         f' SZ: {self.history[-1][2]}'
                    if delta < 1_000_000:
                        s = '**' + s
                    if delta < 1_000_000_000:
                        s = '*' + s
                    h = 'HIST = '
                    for o in self.history:
                        h += f'{o[0]}->'
                    s += f'\n{h}'

                if lasttype == 'X':
                    s += 'Last: ' + lasttype + ' DeltaT: ' + nanoseconds_to_time(self.history[-1][1] - self.otime) +\
                         ' SZ:' + str(self.history[-1][2])

                if lasttype == 'D':
                    s += 'Last: ' + lasttype + ' DeltaT: ' + nanoseconds_to_time(
                        self.history[-1][1] - self.otime)

                if lasttype == 'U':
                    s += 'H: ' + lasttype + ' DeltaT: ' + nanoseconds_to_time(self.history[-1][1] - self.otime) +\
                         ' SZ:' + str(self.history[-1][2]) + ' P:' + str(self.history[-1][3])

        return s
Exemple #2
0
    def process_order(self, order):
        """
        Updates the counter
        :param order:
        :return:
        """
        if order.type in self.selected:
            if self.counter[order.type][0] == int(order.otime/self.granularity):
                self.counter[order.type][1] += 1
            else:
                self.countertime[order.type].append(self.counter[order.type][0])
                self.countervalue[order.type].append(self.counter[order.type][1])
                self.countertick[order.type].append(nanoseconds_to_time(self.counter[order.type][0]*self.granularity, prec=self.precision))
                self.counter[order.type] = [int(order.otime/self.granularity), 1]


        if self.counter['Z'][0] == int(order.otime/self.granularity):
            self.counter['Z'][1] += 1
        else:
            self.countertime['Z'].append(self.counter['Z'][0])
            self.countervalue['Z'].append(self.counter['Z'][1])
            self.countertick['Z'].append(nanoseconds_to_time(self.counter['Z'][0]*self.granularity, prec=self.precision))
            self.counter['Z'] = [int(order.otime/self.granularity), 1]
Exemple #3
0
def log_process(statistics, log=False):
    """
    Some logging of the results

    :param statistics:
    :return:
    """
    if log:
        print('N Buy orders:', len(statistics['buy']['ordertime']))
        print('N Sell orders:', len(statistics['sell']['ordertime']))
        print('N Order Executions Sell:',
              len(statistics['sell']['executiondeltatime']))
        print(
            'Mean time to execution:',
            nanoseconds_to_time(
                np.mean(statistics['sell']['executiondeltatime'])))
        print(
            'Max time to execution:',
            nanoseconds_to_time(
                np.max(statistics['sell']['executiondeltatime'])))
        print(
            'Min time to execution:',
            nanoseconds_to_time(
                np.min(statistics['sell']['executiondeltatime'])))
        print('N Order Executions Buy:',
              len(statistics['buy']['executiondeltatime']))
        print(
            'Mean time to execution:',
            nanoseconds_to_time(
                np.mean(statistics['buy']['executiondeltatime'])))
        print(
            'Max time to execution:',
            nanoseconds_to_time(np.max(
                statistics['buy']['executiondeltatime'])))
        print(
            'Min time to execution:',
            nanoseconds_to_time(np.min(
                statistics['buy']['executiondeltatime'])))
Exemple #4
0
 def log(self):
     """
     Data info
     :return:
     """
     if self.day is None:
         raise NameError('Montly data are not loaded')
     print('N Buy orders:', len(self.statistics['buy']['ordertime']))
     print('N Sell orders:', len(self.statistics['sell']['ordertime']))
     print('N Order Executions Sell:',
           len(self.statistics['sell']['executiondeltatime']))
     print(
         'Mean time to execution:',
         nanoseconds_to_time(
             np.mean(self.statistics['sell']['executiondeltatime'])))
     print(
         'Max time to execution:',
         nanoseconds_to_time(
             np.max(self.statistics['sell']['executiondeltatime'])))
     print(
         'Min time to execution:',
         nanoseconds_to_time(
             np.min(self.statistics['sell']['executiondeltatime'])))
     print('N Order Executions Buy:',
           len(self.statistics['buy']['executiondeltatime']))
     print(
         'Mean time to execution:',
         nanoseconds_to_time(
             np.mean(self.statistics['buy']['executiondeltatime'])))
     print(
         'Max time to execution:',
         nanoseconds_to_time(
             np.max(self.statistics['buy']['executiondeltatime'])))
     print(
         'Min time to execution:',
         nanoseconds_to_time(
             np.min(self.statistics['buy']['executiondeltatime'])))
Exemple #5
0
                    ltimeEB.append(order.otime)
                    lpriceEB.append(trans.price)
                    lsizeEB.append(trans.size)

            # Non-displayable orders
            if order.type in ['P']:
                ltimeEP.append(order.otime)
                lpriceEP.append(order.price)
                lsizeEP.append(order.size)

        print('Stock:', stock, 'Day:', day)
        print('N Buy orders:', len(ltimeOB))
        print('N Sell orders:', len(ltimeOS))
        print('N Order Executions Sell:', len(lexecutionsS))
        print('Mean time to execution:',
              nanoseconds_to_time(np.mean(lexecutionsS)))
        print('Max time to execution:',
              nanoseconds_to_time(np.max(lexecutionsS)))
        print('Min time to execution:',
              nanoseconds_to_time(np.min(lexecutionsS)))
        print('N Order Executions Buy:', len(lexecutionsB))
        print('Mean time to execution:',
              nanoseconds_to_time(np.mean(lexecutionsB)))
        print('Max time to execution:',
              nanoseconds_to_time(np.max(lexecutionsB)))
        print('Min time to execution:',
              nanoseconds_to_time(np.min(lexecutionsB)))
        print('N Hiden Executions:', len(ltimeEP))

        ddata = {}
Exemple #6
0
            lpriceEP.append(float(data[7].strip()))
            lsizeEP.append(int(data[6].strip()))

        i += 1
        if i % 10000 == 0:
            print('.', end='', flush=True)

    print()
    print('Stock:', stock)
    if cpny.get_company(stock) is not None:
        print(cpny.get_company(stock))
    print('N Buy/Sell orders:', norders)
    if len(lexecutionsS) != 0:
        print('N Order Executions Sell:', len(lexecutionsS))
        print('Mean time to execution:',
              nanoseconds_to_time(np.mean(lexecutionsS)))
        print('Max time to execution:',
              nanoseconds_to_time(np.max(lexecutionsS)))
        print('Min time to execution:',
              nanoseconds_to_time(np.min(lexecutionsS)))
        ax = sns.distplot(np.log10(lexecutionsS), kde=True, norm_hist=True)
        plt.title('Log plot of Sell execution time ' + day)
        plt.show()
        plt.close()
        ax = sns.distplot(capped_prices(lpriceOS), kde=True, norm_hist=True)
        plt.title('Orders Sell price ' + day)
        plt.show()
        plt.close()

    if len(lexecutionsB) != 0:
        print('N Order Executions Buy:', len(lexecutionsB))