Signal Backtester

Medium ● Live C++ Rust Java Python

The Problem

Build a backtesting engine for trading signals across 8 assets over 2 years (504 trading days). Handle transaction costs, position sizing, and compute portfolio performance metrics: Sharpe ratio, maximum drawdown, and total P&L.

Test your ability to implement realistic position management, account for slippage and fees, and calculate risk-adjusted returns.

Evaluation Criteria

Correctness (70%)

Position sizing must respect constraints. P&L calculations accurate including transaction costs. Sharpe ratio and drawdown calculations correct to 4 decimal places.

Performance (30%)

Wall-clock time on 504 trading days with 8 assets. Efficient portfolio rebalancing and metric calculation.

Input Format

First line
N = number of rows.
Each row
timestamp,price,signal
Signal
-1 = sell, 0 = flat, 1 = buy.

Output Format & Sample

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

30
1700000002,99.980984,-1
1700000007,99.956401,-1
1700000012,100.145651,-1
1700000017,100.263009,-1
1700000019,100.078771,-1
1700000021,100.193747,-1
1700000024,100.275232,-1
... (more)

Expected output for that sample (first 8 lines):

-1.651294
0
0.000000
1.878034
-1.482249
-1.600342
5

↓ 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++<300ms<1000ms<5000mselse PASS
Rust<300ms<1000ms<5000mselse PASS
Java<600ms<2000ms<10000mselse PASS
Python<3000ms<10000ms<40000mselse PASS

Submission Rules

Challenge Stats

Trading days: 504
Assets: 8
Time period: 2 years
Gold Target: <500ms

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 →