Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
ExperiencesCoaching
New
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
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

Output details

  • Round rolling_5_min_avg_price to two decimal places.

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

Whenever you're ready, walk me through your approach or go straight to the code. The requirements and the two tables are in the Question tab.

You need to log in / sign up to run or submit.
CodePostgreSQL
Sign up free to run your codeLog inLn 1
Run your query to see results here.