Skip to content
Switch branches/tags

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time

Workflow for TMX project

1. Market-maker labels and risk-sharing results.

  • All the Python codes below can be run (in order) from batch file Code\

1.1 Generate market-maker labels

  1. Run to get a list of trading accounts. Saves resulting panel at ProcessedData\account.csv.
  2. Run to obtain a trader-stock-day panel with Kirilenko, Kyle, Samadi and Tuzun (2017, JF) variables -- net position, number of trades/volume traded, standard deviation of inventory. Saves a panel at ProcessedData\account_EODdata.csv.
  3. Run to obtain a panel with each traders' time share at best bid and ask (or both ask and bid). Saves the panel at ProcessedData\BBO_presence_MM.csv.
  4. Run to assign labels for market makers (using KKST-based methodology and presence at the BBO) as well as HFT labels based on TMX information. Saves file with labels at ProcessedData\mm_hft_labels.csv.

1.2 Study market-maker inventories

  1. Run to get inventory panels for each market maker at various frequencies (e.g., 30 second, 1 minute, 30 minutes, 1 hour). Panels are saved in ProcessedData/Inventories/inventory_panel_FREQUENCY.csv.
  2. Run to estimate inventory half-life (in minutes) for each market-maker using an AR(1) process. Half-life panel saved as ProcessedData/inventory_halflife.csv.
  3. Run to generate a two-panel figure of BBO presence and inventory half-lives across market makers. Figure is saved as Output/BBOshares_Halflife_MM.png.

1.3 Study risk-sharing by market-makers

  1. Run to obtain the average pairwise correlation between MM inventory based on 30-second inventory panel. Output saved as ProcessedData/Inventories/InvCorrelations.csv.
  2. Run to obtain estimates of MM risk-sharing inefficiency (based on a quadratic inventory model). Inefficiency panel saved as ProcessedData/Inventories/InvInefficiency.csv.
  3. Run to plot the average pairwise correlation and risk-sharing inefficiency. Output saved as Output/mm_risksharing.png

2. Generate the snapshot-trader marginal quote panel and snapshot depth panel.

  • All the codes below can be run (in order) from batch file Code\
  1. Run on the raw data to generate a folder with marginal quote panels for all traders (ProcessedData\MarginalQuotePanels\). The code uses auxiliary functions from
  2. Run to take each marginal quote panel and:
    1. Assign quantities of zero on the no-quote side for traders active on one side of the book. Such zero-quantities enter the book "as if" they are at the lowest priority.
    2. Merge the trader IDs with the market-maker or HFT label.
    3. Resample the panels every 30s (to avoid double-counting quotes)
    4. Save the resulting panels in ProcessedData\MarginalQuotePanels_ZF\
  • Running takes a lot of time. The folder Code\ForSlurm\ includes a slightly modified version and a SLURM script to run the code in parallel on the Rotman Research Node. Panels need to be manually transferred to the repo, using e.g., WinSCP.
  1. Run to only select the market-maker quotes and save to file ProcessedData\mquotes_ZF_mm.csv. This is the main panel for regressions.
  2. Run to build a panel with 30-second order book snapshots and correlation coefficients between inventory and queue position. Save file as ProcessedData\depth_snapshots.csv. The file also generates two representative figures: Output/depth_correlation.png (impact of inventory-queue correlation on depth) and Output/rho_distribution.png (distribution of inventory-queue correlations).
  3. Use to generate the figures for adverse selection (Output/queue_quantities.png) and inventory (Output/inventory_concerns.png).
  4. Run to generate mquotes_mm.csv which is the same as but without zero quantities filled.
  5. Run to obtain a panel with marginal inventories for MMs as a function of their relative priority level in the book. Panel is saved at ProcessedData/pivot_quotes_inventories.csv.

3. Econometric analysis

  1. Use RegressionCode/summary_stats.R to produce summary stats tables for market-makers (Output/Tables/mmstats.tex), non-market makers (Output/Tables/nonmmstats.tex) and for all quote snapshots (Output/Tables/sumstats.tex)
  2. Use RegressionCode/regression_tests.R for econometric analysis on mquotes_ZF_mm.csv. Output is a table with structural regression estimates: Output/Tables/ASICtable_main.tex
  3. Use RegressionCode/depth_tests.R for econometric analysis on depth_snapshots.csv. Output is a table with estimates on depth effects: Output/Tables/Depth_main.tex.
  4. Use RegressionCode/inventory_order_depth.R for econometric analysis on pivot_quotes_inventories.csv. Output is a table with the marginal impact of inventory as a function of queue position: Output/Tables/Depth_Ordering.tex.

4. Miscellenea

  1. Use to generate theory-supporting figures Output/theory_example_params.png and Output/marginal_impact_queue.png.
  2. Use to estimate the average trade size in the data.


Code and data example for Garriott, van Kervel, and Zoican (2022). The data is randomly generated, while preserving the structure of the proprietary Montreal Exchange data.







No releases published


No packages published