Design and Scale Quantitative Optimization Workflows
Two SigmaSoftware Engineer · Technical ScreenLast updated
Design a scalable, deterministic quantitative optimization and backtesting platform capable of executing 30,000 portfolio optimization runs with strict point-in-time data correctness and full data lineage.
Context & Problem Statement
You are tasked with designing a quantitative portfolio optimization and simulation platform. The platform serves two primary use cases: running daily production optimizations for wealth management (e.g., automated tax-loss harvesting and multi-account asset location) and running multi-period backtests across thousands of portfolio variations to evaluate alpha models and rebalancing strategies.
Optimizers run complex numerical routines (such as Quadratic Programming or Mixed-Integer Programming) to balance alpha, transaction costs, tax implications (e.g., short-term vs. long-term capital gains, wash sales), and tracking error to a benchmark.
Requirements
Functional Requirements
- Optimization Workflow: Support defining and executing single-period optimizations and multi-period backtests across multiple accounts (e.g., taxable vs. tax-exempt retirement accounts).
- Point-in-Time Correctness: Ensure all inputs (prices, dividends, splits, tax lots, risk models) are strictly as-of the simulation timestamp to prevent look-ahead bias or restatement leakage.
- Lineage & Reproducibility: Record immutable lineage for all runs, including code version, input datasets, solver configuration, and output trades/weights, enabling exact deterministic replays.
- Monitoring & Validation: Automatically detect solver divergence, infeasibility, or anomalous turnover before persisting or routing orders.
Scale & Non-Functional Requirements
- Scale: Execute approximately 30,000 optimizer runs during an end-of-day rebalancing batch window within 90 minutes.
- Job Characteristics: An individual optimizer run typically consumes 1 to 2 CPU cores and takes between 3 to 15 seconds, depending on portfolio constraint complexity.
- Determinism: Given identical inputs and solver seeds, results must be bit-for-bit reproducible.
- Fault Tolerance: The system must tolerate worker crashes or transient solver failures without restarting the entire batch.
What to Cover
- High-Level Architecture: Interaction between the orchestration engine, data services, worker pool, and storage layers.
- Point-in-Time Data Storage & Serving: How to store and efficiently retrieve bitemporal financial data and tax lot states across 30,000 accounts.
- Worker Orchestration & Scaling: Dynamic scheduling, worker pool sizing, caching shared data (e.g., factor covariance matrices), and mitigating the straggler problem.
- Data Lineage & Artifact Storage: Tracking provenance and metadata for auditing and compliance.
- Engineering & Research Trade-offs: Trade-offs between exact MIP formulation vs. heuristics for tax-loss harvesting, and distributed vs. local execution environments.
Hints
Hint 1
Model historical market and account data using bitemporal versioning (valid time vs. transaction time) to guarantee point-in-time isolation.
Hint 2
Decouple heavy, shared inputs (like covariance matrices and universe pricing) via distributed in-memory caches or shared read-only memory maps (e.g., Apache Arrow / Plasma) so workers avoid redundant I/O.
Hint 3
Structure optimizer tasks as pure, stateless functions that take an immutable data snapshot payload and return trade allocations alongside convergence diagnostics.
Follow-up questions
- How would you detect and resolve wash-sale rule violations when optimizing across multiple correlated accounts belonging to the same household?
- If 1% of the 30,000 optimizer runs hit numerical infeasibility or solver timeouts, how should the orchestration engine handle them to prevent pipeline stalling?
- How would you architect a caching and data serialization layer to ensure the 30,000 workers do not overwhelm the underlying database during batch kickoff?
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.