Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
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 feedbackCoaching1:1 coaching with people at your target companiesSuccess 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
Regression With R or Python
00:00
5 left

Regression With R or Python

MediumSQL · PostgreSQL

Problem

How would you use R or Python to run regression and analyze results?

Using PostgreSQL tables, prepare the monthly observations that would be passed to R or Python and calculate the core regression statistics directly in SQL. Exclude incomplete observations and funds with fewer than three valid observations.

Output

  1. One row per qualifying fund with fund_id, fund_name, observations, alpha_monthly, beta, r_squared, and r_squared_rank.
  2. Use excess fund returns and excess benchmark returns, and rank funds by descending r_squared, breaking ties by fund_id.

Schema

funds
ColumnTypeDescription
fund_idPKINTUnique fund identifier
fund_nameVARCHAR(100)Fund name
strategyVARCHAR(60)Investment strategy
portfolio_returns
ColumnTypeDescription
return_idPKINTUnique return record identifier
fund_idINTReferenced fund
month_startDATEFirst day of the return month
return_pctDECIMAL(8,4)Monthly fund return percentage
market_returns
ColumnTypeDescription
month_startPKDATEFirst day of the return month
benchmark_return_pctDECIMAL(8,4)Monthly benchmark return percentage
risk_free_pctDECIMAL(8,4)Monthly risk-free return percentage
Tablesfundsportfolio_returnsmarket_returns
Interviewer

Your question is Regression With R or Python. 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.