Portfolio Risk Engine

Hard ● Live C++ Rust Java Python

The Problem

Analyze a portfolio of N assets with D days of historical returns. Compute comprehensive risk metrics: portfolio volatility, Sharpe ratio, Value-at-Risk (VaR), Conditional Value-at-Risk (CVaR), maximum drawdown, and asset correlation matrix.

Scale: 50 assets, 2520 days (~10 years of daily data = 500K data points). Handle large financial datasets efficiently while maintaining numerical accuracy.

Evaluation Criteria

Correctness (70%)

All risk metrics computed correctly. Tolerance: 0.001 for VaR/CVaR/volatility/Sharpe/drawdown; 0.01 for correlations.

Performance (30%)

Wall-clock time on the 500K data point dataset. Memory usage must not exceed 256 MB.

Input Format

First line
N D where N = number of assets, D = number of trading days.
Second line
N weights (sum to 1) - the current portfolio weighting.
Next D lines
each is N returns (decimal, e.g., 0.0040 = 0.4%).
Production scale
N=50, D=2520 (~10 years).

Output Format & Sample

Sample input (first 8 lines, full file linked below):

5 20
0.1530295311 0.2860889326 0.0638790800 0.1438406222 0.3531618342
-0.0100366910 -0.0250240866 -0.0109378051 0.0117757652 -0.0079889820
-0.0134936596 0.0180259052 0.0099497196 -0.0042169790 -0.0016099298
0.0311712229 -0.0117215857 0.0058807138 0.0100631574 0.0131721201
0.0090259594 -0.0197471563 0.0039064539 -0.0065307798 0.0047461850
-0.0243164261 0.0023513982 -0.0095027779 -0.0109069766 -0.0149782567
0.0059657482 -0.0031979695 0.0085983319 -0.0054953968 0.0044407148
... (more)

Expected output for that sample (first 8 lines):

0.136151
-3.911555
0.014154
0.015918
0.015036
0.015918
0.052450
1.000000 0.054903 0.319107 0.271337 0.754767
... (more)

↓ download full sample input  |  ↓ download expected output

Test your solution locally: ./your_solution < input.txt | diff - output.txt

Common Pitfalls

Performance Tier Thresholds (applied by the grader)

LanguageGoldSilverBronzeTier 4
C++<500ms<2000ms<10000mselse PASS
Rust<500ms<2000ms<10000mselse PASS
Java<1000ms<4000ms<15000mselse PASS
Python<5000ms<15000ms<60000mselse PASS

Submission Rules

Challenge Stats

Assets: 50
Days: 2520
Data points: 500,000
Metrics: 7 (+ correlation matrix)

Starter Templates

↓ skeleton.cpp ↓ skeleton.rs ↓ Skeleton.java ↓ skeleton.py

Submit Your Solution

You can submit multiple times. Best result per language counts.

Resources

Leaderboard →