Exemple #1
0
 def plot_statistics_sizes(self, type='order', bins=10):
     """
     Sizes statistics
     :param self:
     :param type:
     :return:
     """
     if self.day is None:
         raise NameError('Montly data are not loaded')
     if type == 'execution':
         fig = plt.figure(figsize=(12, 8))
         ax = sns.distplot(capped_prices(
             self.statistics['sell']['executionsize']),
                           kde=False,
                           bins=bins,
                           hist=True,
                           color='r',
                           label='Sell')
         ax = sns.distplot(capped_prices(
             self.statistics['buy']['executionsize']),
                           kde=False,
                           bins=bins,
                           hist=True,
                           color='g',
                           label='Buy')
         plt.title(
             f'Sell/Buy execution sizes distribution {self.itchday} {self.stock}',
             fontsize=20)
         plt.legend()
     elif type == 'order':
         fig = plt.figure(figsize=(12, 8))
         ax = sns.distplot(capped_prices(
             self.statistics['sell']['ordersize']),
                           kde=False,
                           bins=bins,
                           hist=True,
                           color='r',
                           label='Sell')
         ax = sns.distplot(capped_prices(
             self.statistics['buy']['ordersize']),
                           kde=False,
                           bins=bins,
                           hist=True,
                           color='g',
                           label='Buy')
         plt.title(
             f'Sell/Buy orders sizes distribution {self.itchday} {self.stock}',
             fontsize=20)
         plt.legend()
Exemple #2
0
    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))
        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))
        ax = sns.distplot(np.log10(lexecutionsB), kde=True, norm_hist=True)
        plt.title('Log plot of Buy execution time ' + day)
    for stock in sorted(sstock.get_list_stocks()):
        for day in ITCH_days[year]:
            if os.path.isfile(datapath + '/Results/' + day + '-' + stock + '-MessageAnalysis.pkl'):
                print(day, stock)
                wfile = open(datapath + '/Results/' + day + '-' + stock + '-MessageAnalysis.pkl', 'rb')
                ddata = pickle.load(wfile)
                wfile.close()

                fig = plt.figure(figsize=(12,8))
                ax = sn.distplot(np.log10(ddata['DeltaTimeExecSell']), kde=True, norm_hist=True)
                plt.title('Log plot of Sell execution delta time ' + day)
                plt.show()
                plt.close()

                fig = plt.figure(figsize=(12,8))
                ax = sn.distplot(capped_prices(ddata['PriceOrderSell']),  kde=True, norm_hist=True)
                plt.title('Orders Sell price ' + day)
                plt.show()
                plt.close()

                fig = plt.figure(figsize=(12,8))
                ax = sn.distplot(np.log10(ddata['DeltaTimeExecBuy']),  kde=True, norm_hist=True)
                plt.title('Log plot of Buy execution time ' + day)
                plt.show()
                plt.close()

                fig = plt.figure(figsize=(12,8))
                ax = sn.distplot(capped_prices(ddata['PriceOrderBuy']),  kde=True, norm_hist=True)
                plt.title('Orders Buy price ' + day)
                plt.show()
                plt.close()
Exemple #4
0
def plot_statistics(statistics):
    """
    Some plot of the results
    :param statistics:
    :return:
    """
    fig = plt.figure(figsize=(12, 8))
    ax = sns.distplot(np.log10(statistics['sell']['executiondeltatime']),
                      kde=True,
                      norm_hist=True)
    plot_tscale()
    plt.title(f'Log plot of Sell execution delta time {itchday} {args.stock}',
              fontsize=20)
    plt.show()

    fig = plt.figure(figsize=(12, 8))
    ax = sns.distplot(capped_prices(statistics['sell']['executionprice']),
                      kde=True,
                      norm_hist=True)
    plt.title(f'Orders Sell price {itchday} {args.stock}', fontsize=20)
    plt.show()

    fig = plt.figure(figsize=(12, 8))
    ax = sns.distplot(np.log10(statistics['buy']['executiondeltatime']),
                      kde=True,
                      norm_hist=True)
    plot_tscale()
    plt.title(f'Log plot of Buy execution time {itchday} {args.stock}',
              fontsize=20)
    plt.show()

    fig = plt.figure(figsize=(12, 8))
    ax = sns.distplot(capped_prices(statistics['buy']['executionprice']),
                      kde=True,
                      norm_hist=True)
    plt.title(f'Orders Buy price {itchday} {args.stock}', fontsize=20)
    plt.show()

    fig = plt.figure(figsize=(12, 8))
    ax = sns.distplot(np.log10(statistics['buy']['deletedeltatime']),
                      kde=True,
                      norm_hist=True,
                      label='Buy')
    ax = sns.distplot(np.log10(statistics['sell']['deletedeltatime']),
                      kde=True,
                      norm_hist=True,
                      label='Sell')
    plot_tscale()
    plt.legend()
    plt.title(f'Log plot of deletion time (Buy/Sell) {itchday} {args.stock}',
              fontsize=20)
    plt.show()

    fig = plt.figure(figsize=(12, 8))
    ax = sns.distplot(np.log10(statistics['sell']['executiondeltatime']),
                      kde=True,
                      hist=False,
                      color='r',
                      label='Exec Buy')
    ax = sns.distplot(np.log10(statistics['buy']['executiondeltatime']),
                      kde=True,
                      hist=False,
                      color='g',
                      label='Exec Sell')
    ax = sns.distplot(np.log10(statistics['buy']['deletedeltatime']),
                      kde=True,
                      hist=False,
                      color='b',
                      label='Del Buy')
    ax = sns.distplot(np.log10(statistics['sell']['deletedeltatime']),
                      kde=True,
                      hist=False,
                      color='k',
                      label='Del Sell')
    plt.legend()
    plot_tscale()
    plt.title(f'Sell/Buy/Deletion time {itchday} {args.stock}', fontsize=20)
    plt.show()

    fig = plt.figure(figsize=(12, 8))
    ax = sns.distplot(capped_prices(statistics['sell']['orderprice']),
                      kde=True,
                      hist=False,
                      color='r',
                      label='Sell')
    ax = sns.distplot(capped_prices(statistics['buy']['orderprice']),
                      kde=True,
                      hist=False,
                      color='g',
                      label='Buy')
    plt.legend()
    plt.title(f'Sell/Buy orders prices distribution {itchday} {args.stock}',
              fontsize=20)
    plt.show()

    fig = plt.figure(figsize=(12, 8))
    ax = sns.distplot(capped_prices(statistics['sell']['ordersize']),
                      kde=False,
                      hist=True,
                      color='r',
                      label='Sell')
    ax = sns.distplot(capped_prices(statistics['buy']['ordersize']),
                      kde=False,
                      hist=True,
                      color='g',
                      label='Buy')
    plt.title(f'Sell/Buy orders sizes distribution {itchday} {args.stock}',
              fontsize=20)
    plt.legend()
    plt.show()

    fig = plt.figure(figsize=(12, 8))
    ax = sns.distplot(capped_prices(statistics['sell']['executionprice']),
                      kde=True,
                      hist=False,
                      color='r',
                      label='Sell')
    ax = sns.distplot(capped_prices(statistics['buy']['executionprice']),
                      kde=True,
                      hist=False,
                      color='g',
                      label='Buy')
    plt.legend()
    plt.title(f'Sell/Buy execution prices distribution {itchday} {args.stock}',
              fontsize=20)
    plt.show()

    fig = plt.figure(figsize=(12, 8))
    ax = sns.distplot(capped_prices(statistics['sell']['executionsize']),
                      kde=False,
                      hist=True,
                      color='r',
                      label='Sell')
    ax = sns.distplot(capped_prices(statistics['buy']['executionsize']),
                      kde=False,
                      hist=True,
                      color='g',
                      label='Buy')
    plt.title(f'Sell/Buy execution sizes distribution {itchday} {args.stock}',
              fontsize=20)
    plt.legend()
    plt.show()

    fig = plt.figure(figsize=(14, 8))
    plt.plot(statistics['sell']['ordertime'],
             statistics['sell']['orderprice'],
             color='r')
    plt.plot(statistics['buy']['ordertime'],
             statistics['buy']['orderprice'],
             color='g')
    plt.scatter(statistics['sell']['executiontime'],
                statistics['sell']['executionprice'],
                marker='o',
                color='y',
                s=statistics['sell']['executionsize'])
    plt.scatter(statistics['buy']['executiontime'],
                statistics['buy']['executionprice'],
                marker='o',
                color='b',
                s=statistics['buy']['executionsize'])

    plt.title(f'Order Sell/Buy price evolution ', fontsize=20)
    plt.show()