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
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
Compute Portfolio Greeks
00:00
5 left

Compute Portfolio Greeks

HardPython

Problem

Write a function to calculate the Greek values of a portfolio.

Assume every position is a European call or put valued with the Black-Scholes model. Return the portfolio-level delta, gamma, vega, theta, and rho by multiplying each position's Greeks by its signed quantity and summing across positions.

The function accepts a list of position dictionaries and returns a dictionary of five floating-point Greek values. Inputs use annualized time, volatility, and interest rate. For positions at expiry, use intrinsic-value delta, with delta 0.5 for an at-the-money option, and return zero for the other Greeks.

Signature: def calculate_portfolio_greeks(portfolio):

Each position contains type, quantity, spot, strike, time_to_expiry, volatility, and rate. Quantities may be negative for short positions.

Constraints

  • 0 <= len(portfolio) <= 10000
  • Each position type is either "call" or "put"
  • Quantities are signed integers
  • spot > 0 and strike > 0
  • time_to_expiry >= 0
  • volatility > 0 when time_to_expiry > 0
  • rate is an annualized continuously compounded risk-free rate
  • All time, rate, and volatility values use annualized units

Function Signature

def calculate_portfolio_greeks(portfolio):
Interviewer

Your question is Compute Portfolio Greeks. Start with the requirements 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.
CodePython 3
Sign up free to run your codeLog inLn 2
Run your code to see test output here.