Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

OOP Program Demonstration

MediumPython00:00
Practice interviewer
In session
5 left
00:00

Your question is OOP Program Demonstration. Start with the requirements on the right.

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.

Problem

DTCC CTM receives trade instructions for multiple asset classes. Implement an object-oriented validator that uses abstraction and polymorphism to apply the correct validation rules without placing all asset-specific logic in one conditional-heavy function.

Create an abstract TradeRule class with a validate(trade) method. Implement EquityRule, BondRule, and OptionRule subclasses. The validate_trades function must select the appropriate rule for each instruction and return validation results in the original order.

Formal Specification

Input trades is a list of dictionaries. Every dictionary contains id, asset_type, quantity, price, and settlement_days. Option trades also contain strike.

Return a list of dictionaries with id, valid, and errors. valid is true only when no rules are violated. Error messages must use the exact strings defined below.

  • Equity: quantity must be positive, price must be positive, and settlement must be 1 or 2 days.
  • Bond: quantity must be positive, price must be between 0 and 100 inclusive, and settlement must be between 1 and 3 days.
  • Option: quantity must be positive, price must be nonnegative, strike must be positive, and settlement must be exactly 1 day.
  • Unknown asset types produce one error: Unknown asset type.

Constraints

  • 1 <= len(trades) <= 10^4
  • Each trade contains the required fields for its asset type
  • Numeric values fit standard Python integer or floating-point ranges
  • Asset types are case-sensitive
  • Output order must match input order

Function Signature

def validate_trades(trades):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output