
How to use the information coefficient to measure your alpha
During my master's program, my professors gave me a lot of theories I couldn't use.
I remember my interest rate derivatives professor telling me:
"None of what I'm going to teach you actually works in practice."
Now the context behind that statement was negative interest rates during the Great Financial Crisis.
But the point remains.
Of all the theories I couldn't use, there were a few bright spots of practical wisdom.
One of those bright spots was factor investing and associated performance monitoring with the information coefficient.
One of my professors was a portfolio manager at a large hedge fund and he spent all his time building factor models and measuring their performance.
He spent the entire semester showing us exactly how.
It took me many months and several hundred lines of MATLAB code to get it right.
Fortunately, there is an open-source tool that does it in a few lines of Python.
How to use the information coefficient to measure your alpha
The information coefficient measures the correlation between a stock's returns and the predicted returns from an alpha factor.
It's a metric used to evaluate the effectiveness of an alpha factor in generating returns.
The information coefficient was first introduced by Fama and French in 1992, and it's been widely used in quantitative finance ever since.
The information coefficient is important for retail traders, algorithm developers, and data analysts because it helps them determine which alpha factors are worth using in their trading strategies. Quants use the information coefficient to measure the predictive power of an alpha factor and to optimize their trading strategies.
Now you can too.
You will extend the momentum strategy you built last week by adding short positions to the portfolio and tracking the factor's rank. These changes will let you use AlphaLens to assess the performance of the alpha factor.
Start with the imports. Define two constants, N_LONGS and N_SHORTS, which will be the number of securities the strategy will go long and short in the portfolio.
After the imports, load the Zipline extension and download data. You'll need a free API from Nasdaq Data Link, which you can get here.
Create a custom momentum factor and build the pipeline
Now, create a custom factor to calculate the momentum and define the pipeline for our trading algorithm.
The factor divides the first price in the window by the last price. In other words, if the last price in the window is greater than the first price, there is momentum.
Define a function that creates a pipeline with two momentum calculations: one for 20-day momentum and another for 30-day momentum.
The Pipeline returns the top and bottom trending stocks that have positive momentum. It also returns their factor ranking.
Implement the trading strategy
Implement the trading strategy by initializing the pipeline, scheduling the rebalancing function, and executing the trades.
The before_trading_start function gets the pipeline output before every trading session. The initialize function attaches the pipeline and schedules the rebalancing function to run at the start of each week at market open.
The rebalance function gets the pipeline output, filters the assets to go long and short, and figures out which assets to divest. It then executes the trades using the exec_trades function.
In the exec_trades function, loop through the assets and check if they are tradable and if there are no open orders. If both conditions are met, place an order targeting the specified percentage of the portfolio.
And finally, run the algorithm.
Assess the factor performance with AlphaLens
Manipulate the price and factor data so AlphaLens can read them.
Construct a DataFrame where each column is a stock and each row is a date. Do this by concatenating the DataFrames, each of which corresponds to a stock. Then convert the column names to strings and normalize the dates to midnight, UTC.
Now, do the same for the factor data.
This time, create a MultiIndex DataFrame with the date as the first index and the asset as the index column. The column has the factor ranking.
Finally, you can analyze the factor returns using AlphaLens.
This is a utility function that creates holding period returns of 5, 10, 21, and 63 days. It includes the factor ranking and the factor quantile.
Now, you can get the information coefficient for each lagged return. For example, this is the historic information coefficient for a 5 day lag.

This chart shows how the information coefficient changes over time but is generally positive. This implies the momentum factor predicts returns.
You can also see the mean information coefficient of the factor for each holding period for each year.

Throughout the backtest period, the momentum factor performed best on shorter time periods.
Professional money managers from Blackrock to Vanguard use factors to invest. Building factors and measuring their performance used to be reserved for the quants at these institutions. Now, you can use the same techniques they do.