Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Rolling 5-Minute Price Average
00:00
5 left

Rolling 5-Minute Price Average

MediumSQL · PostgreSQL

Problem

Write a query or script to calculate the rolling 5-minute average price of a stock asset, handling periods of inactivity where no trades occur for Jane Street’s data.

Use the assets and trades tables and calculate results for the asset with symbol AAPL. Include every five-minute timestamp from the asset observation start through its observation end. A missing average must be represented as NULL, not zero.

Output

  1. One row per five-minute timestamp for AAPL
  2. Columns: asset_symbol, bucket_start, and rolling_5_min_avg_price
  3. Include trades from the preceding five minutes through the timestamp, inclusive, and ignore NULL prices
  4. Order by bucket_start ascending

Schema

assets
ColumnTypeDescription
asset_idPKINTUnique asset identifier
symbolVARCHAR(20)Stock symbol
observation_startTIMESTAMPTZBeginning of the reporting interval
observation_endTIMESTAMPTZEnd of the reporting interval
trades
ColumnTypeDescription
trade_idPKINTUnique trade identifier
symbolVARCHAR(20)Traded stock symbol
trade_timeTIMESTAMPTZTimestamp when the trade occurred
priceNUMERIC(12,4)Trade price
Tablesassetstrades
Interviewer

Your question is Rolling 5-Minute Price Average. Start with the requirements and the two tables in the Question tab.

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.
CodePostgreSQL
You need to log in / sign up to run or submit.Ln 1
Run your query to see results here.