Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

SQL Rolling Average by Asset Class

MediumSQL · PostgreSQL00:00
Practice interviewer
In session
5 left
00:00

Your question is SQL Rolling Average by Asset Class. Start with the requirements and the one table on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Point72's trading analytics team wants to monitor short-term changes in transaction volume across its market data. Write a PostgreSQL query that calculates a seven-day moving average for each ticker, while keeping asset classes separate.

Requirements

  1. Aggregate transaction volume by asset_class, ticker, and trade_date before applying the window function.
  2. Calculate the moving average using the current date and the preceding six calendar days. Include only dates present in the daily aggregate; do not create missing calendar dates.
  3. Partition the window by both asset_class and ticker, and order each partition chronologically by trade_date.
  4. Return the asset class, ticker, trade date, daily volume, and moving average, ordered by asset class, ticker, and trade date.

A NULL volume should be ignored by SUM and AVG, consistent with PostgreSQL aggregate behavior.

Schema

transactions
ColumnTypeDescription
transaction_idPKINTUnique transaction identifier
tickerVARCHAR(10)Ticker or traded instrument symbol
asset_classVARCHAR(20)Asset class of the traded instrument
trade_dateDATEDate on which the transaction occurred
volumeDECIMAL(14,2)Transaction volume
Tablestransactions
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results