Calculate information ratio from daily active returns with pandas.
Published: 2025-12-27
URL: https://pyquantnews.substack.com/p/measure-your-trading-skill-the-right
Each week, I send out one Python tutorial to help you get started with algorithmic trading, market data analysis, and quant finance. Upgrade to a paid plan to access the code notebooks. Subscribe now In today’s post, you’ll compute an information ratio for a simple portfolio and judge it against QQQ.
What it is The information ratio measures how much excess return your portfolio earns per unit of active risk versus a benchmark. The idea grew out of active management research linking skill to consistent outperformance over a reference index.
It is popular in equity and multi-asset shops because it turns messy relative results into a single, comparable score across managers. How pros use it Today, teams compute daily active returns by subtracting benchmark returns from portfolio returns, then annualize mean and volatility to get a clean, comparable metric. They align timestamps, handle corporate actions with adjusted prices, and compute returns as the change in portfolio value divided by the prior day’s value. They often annualize the information ratio by multiplying the daily mean over daily standard deviation by the square root of 252, and they watch tracking error because it governs how much the portfolio can deviate from the index.
Desks run the same calculation at multiple horizons to catch regime shifts, then they attribute active return to names and factors to see what actually drove the score. Why it matters to you If you are learning Python for trading, this gives you a clear test for whether active work beats a passive ETF after risk.
It also builds the habit of clean benchmarking, which reduces noise in backtests and prevents sloppy comparisons that hide overfitting. You will learn to fetch data, compute portfolio returns correctly, align with a benchmark, and produce one number that supports a simple decision. If your information ratio is negative or unstable, you can pause tinkering and consider moving to the benchmark until you have a stronger idea. Let’s see how it works with Python. Library installation Install the libraries needed to fetch market data, manipulate time series, and render plots in this notebook.
We install yfinance for Yahoo Finance data and pandas for vectorized time series work. Matplotlib is included so pandas can render the comparison chart via .plot() without extra imports. Imports and setup We use pandas for time-series data manipulation and plotting integration, and yfinance to download adjusted price history from Yahoo Finance.
These two libraries cover the full workflow here: fetching adjusted prices, computing returns, and preparing a clean benchmark comparison. Keeping dependencies lean makes it easier to reproduce and debug results as you iterate on your process. Fetch and align market data Download adjusted close data for QQQ (benchmark) and the two holdings, then compute the benchmark’s daily returns. Using adjusted prices accounts for splits and dividends so our return math is coherent. We compute daily percentage changes on QQQ to form the benchmark series we’ll subtract from the portfolio later.
Clean, aligned daily returns are the foundation for any reliable active risk/return metric. Build portfolio and compute returns Create an equal-share portfolio in AAPL and AMZN, compute daily PnL from position changes, and turn that into a daily return series. Equal shares are simple and make it clear how price moves translate into PnL, but note this is not equal risk or equal weight. We use shift() to base PnL on changes from the prior close, avoiding lookahead.
In production, verify the return denominator (many desks use prior-day value) and bake that check into tests so a small bug can’t flip your sign or scale. Visualize performance and compute ratio Build cumulative growth of $1 for the portfolio and benchmark, then plot them to visually sanity-check alignment before scoring.
The result is a chart that looks like this. A quick cumulative plot often surfaces obvious issues like missing data, date misalignment, or unexpected drift. We start both series at 1 so visual differences reflect compounded performance.
This pre-check saves time by catching data problems before we compress everything into one number. Define and compute the information ratio from daily active returns to quantify skill per unit of active risk.
The function subtracts benchmark returns to form active returns, then divides their mean by their volatility (tracking error). Ensure both inputs share the same dates; misalignment will dilute or distort the signal. If you want an annualized figure, multiply the daily ratio by the square root of 252, and monitor tracking error because it governs how far you can stray from the index. Your next steps Now you can fetch data, compute clean portfolio and benchmark returns, align them, and produce an annualized information ratio against QQQ.
Use it to decide if your active work beats the ETF after risk, stop when it doesn’t, and keep your process honest across regimes.