Best execution

29 June 2021

In this article we are going through a best execution sample using our API within our web cloud-based JupyterLab environment. A step-by-step explanation of commonly used best execution approaches illustrated using tick data and execution performance measurements.

Best execution aims to measure the performance of executed trades, an execution algorithm or an execution venue. However building best execution analytics on-the-fly from raw provider tick data can be time consuming and costly. One way to overcome this challenge is to adopt managed-service from the tick data collection to analytics and reports generation.

In this article we are going through a step-by-step explanation of how to request market snapshot and compute execution metrics using Ganymede, our web and cloud-based JupyterLab environment, and our API.

Performance measurement accuracy relies on the input data quality and consistency. We use tick by tick data to make sure that we process each and every market event.

Getting started

We assume you aim to evaluate the performance of a given list of private trades. To that end, we will use common fields like timestamp, price and size. In our coming articles, we will focus on more specific use-cases that require more fields such as: How to highlight the exact private trades within public exchange data?

For this sample, we assume you will use Python with the following Systemathics package:

PyPI version

We will be using a set of Systemathics modules in addition to Opensource modules as follows:

# open source modules
import os
import grpc
import pandas as pd
import mplfinance as mpf
from datetime import datetime
import google.protobuf.duration as duration
# systemathics modules to handle input parameters' types
import systemathics.apis.type.shared.identifier as identifier
# systemathics modules to instantiate the tick best execution
import systemathics.apis.services.tick.best_exec as best_exec
import systemathics.apis.services.tick.best_exec_grpc as best_exec_service

Our API exposes a BestExecutionService to directly request best execution tick data and to compute on-the-fly execution analytics. Explore the full API documentation to learn more about our extensive list of analytics.

Import input trades

The following code snippet enables to import input trades from a csv file and creates a dataframe out of it:


df_input = pd.read_csv("input_trades.csv")
df_input = df_input.sort_values(by="Timestamp")
df_input

Request parameters


# set instrument identifier
ticker = 'AAPL'
exchange = 'BATS'

# set the time window in minutes to delimit each input trade
window = 5

Note that we are delimiting a time window around each input trade to:

  • Highlight input trade within occured market trades
  • Compute execution metrics
  • Benchmark input trades performance

Create the request

Now that we selected the input parameters we proceed to the request creation:

# generate the tick best execution request
my_request = best_exec.BestExecRequest(
identifier = identifier.Identifier(exchange = exchange, ticker = ticker),
window = duration.Duration(minutes = my_window),
inputs = my_input_trades
)

Process the request

The services use gRPC channel in order to:

  • overcome performance issues usually encountered when retrieving high volumes of data
  • support different programming language to call the API, create data requests and process replies
  • The requests contain a token to grant authorization to users:

  • over a period of time
  • for a specfic history depth
  • for a given watchlist: tickers, exchanges...
  • # instantiate the tick best execution service
    my_service = best_exec_service.BestExecServiceStub(channel)
    
    # process the tick best execution request and get tick trades
    trades, limits, metrics = []
    my_metadata = [('authorization', token)]
    for trade in service.TickTrades(request= my_request, metadata = my_metadata):
    trades.append(trade)
    

    Retrieve data

    # prepare the dataframe content out of the best execution response, tick trades
    timestamps = [datetime.fromtimestamp(t.timestamp) for t in trades]
    prices = [t.price for t in trades]
    sizes = [t.size for t in trades]
    flags = [t.flag for t in trades]
    
    # create a pandas dataframe, occured trades within time windows surrounding each input trade
    d = {'Timestamp': timestamps, 'Price': prices, 'Size': sizes, 'Flag' : flags}
    df = pd.DataFrame(data=d)
    df
    

    Best execution analytics

    Best execution service enables to retrieve market trades that occured within the given time window around every input trade. Results can be exported to various file formats, integrated within 3rd party tools and displayed for visualization and reporting requirements.

    You can use libraries of your choice for graph plotting, in this example we are using an open-source library mplfinance to highlight input trades within market snapshot.

    Extensive best execution interval analytics can be requested to benchmark a trade performance as compared to average interval metrics:

    In addition to comparing the input trades to market trades, the best execution service enables to get book limits for a specific point-in-time. For this sample, best limits are requested for the given input time window surrounding the input trades:

    Reach out to try our solutions

    In this article, we request tick best execution data by calling a dedicated API service within Ganymede, our web and cloud-based JupyterLab environment, and our API. You can use it as-is and/or call directly our API within your internal tools and start immediately retrieving on-demand financial data.

    To get the full sample and discover more data analytics samples and building blocks navigate to our public Github →

    ← Back to Blog