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.
Best,
Derek Melchin
Want to invest in QuantConnect as we build the Linux of quant finance? Checkout our Wefunder campaign to join the revolution.
Newoptionz
Hi
Thanks, that is great. Would you please create a YouTube video explaining the code in more depth? I guess anyone can make the video, I could even give it a go. That might make it easier for people to attempt to understand what is happening in it.
Thanks
Newoptionz
Well done, and I did give u a reward.
Santa24
Hi Derek Melchin cool, is this data being updated or will you integrate this into QC soon? Before everyone jumps ahead writing their own scrapers….
Derek Melchin
Hi Santa24,
We intend to integrate bls.gov data into QC, but don't have an ETA at this time. For now, members may use the CPIData class in the attached backtest to import the data into algorithms.
Best,
Derek Melchin
Want to invest in QuantConnect as we build the Linux of quant finance? Checkout our Wefunder campaign to join the revolution.
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Santa24
Derek Melchin sounds great. Does the Dropbox file also update with new data so it could be live traded?
Derek Melchin
Hi Santa24,
No, the Dropbox file should only be used for backtests.
Best,
Derek Melchin
Want to invest in QuantConnect as we build the Linux of quant finance? Checkout our Wefunder campaign to join the revolution.
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Gianluca Albino
Hi everyone, i saw that fred CPI data now are in the dataset, I'm I mistaken?
Ashutosh
Hi Gianluca Albino
The CPI data is not currently integrated into the Dataset Market. In the code developed by Derek the data points are fed into the algorithm via a custom data class which takes in data from the Dropbox file.
This piece of code imports data from the data.py file into the main algorithm.
The implementation of data.py is attached below:
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Ashutosh
Hi Gianluca Albino
You can import the file with the code and it should work fine.
Best,
Ashutosh
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Renjie Huang
Do you have tool or script to automatically update the file in dropbox?
Derek Melchin
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!