Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
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
Experiences
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
Build my plan
Rolling 30-Day Volatility Query
00:00
5 left

Rolling 30-Day Volatility Query

MediumSQL · PostgreSQL

Problem

Fidelity Investments uses market data analytics to monitor risk for equities available through Fidelity Active Trader Pro. Write a PostgreSQL query that calculates rolling 30-day volatility for the equities in a specified watchlist.

Use daily closing prices to calculate simple daily returns. Treat the 30-day period as the preceding 30 calendar days, including the current observation. Return volatility only when at least two daily returns exist in the rolling window.

Requirements

  1. Join the watchlist to the security master and daily prices.
  2. Calculate each equity's daily return using LAG.
  3. Calculate sample standard deviation of daily returns over the preceding 30 calendar days using a window function.
  4. Return the ticker, price date, daily return, number of returns in the window, and volatility, ordered by ticker and date.

Schema

requested_equities
ColumnTypeDescription
tickerPKVARCHAR(10)Ticker included in the requested watchlist
equities
ColumnTypeDescription
tickerPKVARCHAR(10)Unique equity ticker
security_nameVARCHAR(100)Equity security name
asset_classVARCHAR(30)Security asset classification
daily_prices
ColumnTypeDescription
tickerPKVARCHAR(10)Ticker for the price observation
price_datePKDATETrading date
close_priceNUMERIC(12,4)Unadjusted daily closing price
Tablesrequested_equitiesequitiesdaily_prices
Interviewer

Your question is Rolling 30-Day Volatility Query. Start with the requirements and the three 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
Sign up free to run your codeLog inLn 1
Run your query to see results here.