Process CSV for portfolio returns and metrics
DRWMachine Learning Engineer · Online AssessmentLast updated
This question evaluates a candidate's competency in time-series data manipulation, financial return computation, portfolio analytics, numerical stability, modular software design (clear function boundaries and unit tests), and algorithmic complexity analysis within the Data Manipulation (SQL/Python) domain.
Given one or more CSV files containing daily asset prices or returns and optional portfolio weights, write Python (pandas) code to: a) load, clean, and align by date; b) handle missing values and outliers with documented choices; c) compute individual asset returns (simple and log) from prices if needed; d) compute a time series of portfolio returns given weights, supporting fixed-weight and periodic rebalancing; e) calculate cumulative return, annualized return, annualized volatility, Sharpe ratio (risk-free rate provided), maximum drawdown, and rolling-window metrics; f) support multiple portfolios and output a tidy summary table plus a CSV of metrics and a plot-ready time series; g) ensure numerical stability, clear function boundaries, and unit tests for edge cases (non-overlapping dates, zero weights, NaNs); h) report algorithmic complexity and justify design choices.
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.