Hi everyone!

We created a strategy that monitors the changes in CPI values and selects a subset of the SPY constituents in order to optimize the Sharpe ratio of the portfolio. Our hypothesis was that some stocks would perform better in periods of rising inflation while some would perform better in periods of disinflation. So, given the latest CPI values, we could select the subset of stocks that have a history of outperformance in the current environment.

As input to the strategy, we used the unadjusted 12-month percentage change CPI data. Since this data isn't currently integrated into the Dataset Market, we gathered the data points from a chart on the US Bureau of Labor Statistics website and we were able to get the release dates of the data points from their archived news releases. We uploaded the data to Dropbox and created a custom data class to feed the data into the algorithm.

To implement the strategy, we set the universe to an ETF constituents universe. When the algorithm receives a new CPI value or when the universe changes, we rebalance the portfolio. During each rebalance, we compare the most recent CPI value to the CPI value that preceded it. If the CPI value increased over the last two releases, we classified the current environment as having rising inflation. Otherwise, we classified the current environment as being disinflationary. 

With the current inflation environment determined, we then determine the periods of time in the trailing year where the CPI direction (rising/falling) matches the current CPI direction. Over these time periods, we measure the annualized Sharpe ratio of all the assets in the universe and of the SPY. We then select the subset of assets that demonstrated a higher annualized Sharpe ratio over these periods of time than the SPY. Of the assets that remain, we buy the 25% of assets with the highest Sharpe ratio over the trailing periods of time, scaling their positions by their market cap to match the S&P 500 index methodology.

We tested the strategy from September 2009 to September 2022, which was the longest period of time we could choose where we had all the required data. During this time period, the strategy outperformed, achieving a 0.743 Sharpe ratio while the SPY benchmark achieved a 0.692 Sharpe ratio over the same time period.

See the attached backtest for reference.

Derek Melchin

Want to invest in QuantConnect as we build the Linux of quant finance? Checkout our Wefunder campaign to join the revolution.