Presentation given at DuckCon #6 2025

This presentation will give you 2 takeaways:

  1. An overall impression of how DuckDB can be used in Finance.
  2. Show you QStudio a free SQL client first released in 2013 and that today integrates DuckDB.




If you want to run these demos yourself, download QStudio.

Bank Trading and Data Flow

bank trading data flow

  • Trading departments within Banks are large entities that consume data and either conduct trades for clients or on their own behalf on global markets
  • The left-hand side of this diagram shows
    • Exchanges - LSE - London Stock Exchange, NYSE, XHKG, Euronext. Basically marketplaces where very large firms can trade with each other.
    • Market Data Providers - Bloomberg, refinitiv, yahoo, polygon. That aggregate various exchanges and sources for you, rather than you having to negotiate a contract with each one.
    • Alternative Data Sources
  • The three middle blocks: Data Platforms -> Analysis -> Trading represent the bank itself.
  • Finally the right-hand side represents the bank taking actions and interacting externally with clients of conducting trades on external markets.
  • Example Finance Use-cases

    1. Historical market data storage and analysis. e.g. Backtesting. Exchange Data Arrives -> Stored on Big Data Platform -> Used as part of framework to replay a trading strategy to predict its' profitability or risk profile.
    2. Local quant analysis e.g. Liquidity analysis, PnL analysis, profitability per client.
      Prices aka quotes arrive from the market, the bank holds onto some stock but regularly resells it to clients via a trading platform (Like your local supermarket but at much higher speed). An analyst could be tasked with:
      1. Examining the exchange data and the orders to see if they were executed well.
      2. Examining everything that each client bought and sold and trying to find the profit or loss the bank made for that particular customer.
    3. Real-time Streaming Calculation Engines e.g. Streaming VWAP, Streaming TCA

    Local Quant Analysis

    DuckDB is a powerful tool for local data analysis and I believe that's currently where it could best be used in finance. So let's look at real examples:

    Loading the NYSE TAQ Trade Data

    1. Download the data at https://ftp.nyse.com/Historical%20Data%20Samples/DAILY%20TAQ/,
      in particular the EQY_US_ALL_TRADE_20240702.gz and unzip the file.
    2. Download QStudio which bundles DuckDB and go to File menu -> New DuckDB Database.
    3. Run the below SQL code to load the data into a table and to add a ttime column of the correct type.

    Querying the Data

    column_name column_type null key default extra
    TimeVARCHARYES
    ExchangeVARCHARYES
    SymbolVARCHARYES
    Sale ConditionVARCHARYES
    Trade VolumeBIGINTYES
    Trade PriceDOUBLEYES
    Trade Stop Stock IndicatorVARCHARYES
    Trade Correction IndicatorVARCHARYES
    Sequence NumberBIGINTYES
    Trade IdBIGINTYES
    Source of TradeVARCHARYES
    Trade Reporting FacilityVARCHARYES
    Participant TimestampVARCHARYES
    Trade Reporting Facility TRF TimestampVARCHARYES
    Trade Through Exempt IndicatorBIGINTYES
    ttimeTIMEYES

    VWAP Volume Weighted Average Price

    DuckDB Pivot

    Pivot tables allow exploring data easily. QStudio allows click and select to change pivots, leveraging the power of duckdb pivots and allowing you to (4) copy the pivot query.

    Pivot Table DuckDB

    Candlesticks are easy with window functions

    DuckDB Candlestick

    How to make money with window functions

    DuckDB Buy Sell Stock Signal DuckDB Profit