Katkat

Implement Stock Price Query APIs

Lead BankSoftware Engineer · Technical Screen

Last updated

This question evaluates skills in time-series data modeling, API and data-structure design, transactional (atomic) batch updates, concurrency control, and date/time parsing for stock price records.

You are given an initial collection of stock price records. Each record contains:

  • symbol: a stock name or ticker string
  • timestamp: initially a calendar date at daily granularity
  • price: a decimal price

Design and implement an in-memory StockPriceStore. You may define the exact function signatures and return types, but the behavior must be clear and testable.

Support the following operations:

  1. get_price(symbol, date): return the price of the given stock on the given date, or an appropriate missing-value result if no price exists.
  2. get_change(symbol, start_date, end_date): return the price change for the given stock between two dates. Use a custom formula supplied by the interviewer, for example formula(start_price, end_price). Handle cases where either price is missing or the formula cannot be applied.
  3. update_prices(symbol, start_date, end_date, new_prices): update the prices for the given stock over an inclusive date range and return whether the update succeeded. If any price in that range for that stock has already been updated before, the entire update should fail. The update should be atomic: either all requested prices are updated, or none are.
  4. The timestamp granularity changes from daily to hourly. Add an operation get_hourly_prices(symbol, day) that returns all hourly prices for the given stock within that calendar day, ordered by time.

Clarify and handle edge cases, including duplicate initial records, missing symbols, missing dates, invalid date ranges, repeated updates, partial update failures, and date/time parsing. Write representative test cases for your implementation.