Welcome to QuantHead!

Welcome to QuantHead! I hope you find some interesting ideas here that I've encountered on my journey of learning and share your wisdom with me. Enjoy!

Friday, May 22, 2015

10,000 Page Views!


Today QuantHead reached 10,000 page views since its birth just over 7 months ago.
The U.S. clearly shows the most interest, and I'm happy to see readers from around the world.


Of the strategies presented, the Global Market Rotation model takes the all-time lead, though in the recent months the Modified Dual Momentum model has presented, well - the most momentum!


Thanks again for reading and sharing, and see you at 100,000!

Monday, May 18, 2015

Treasury Yield Curve

Low interest rates pose a major concern for the current market environment, especially as far as rotation strategies are involved. As witnessed by the chart of the 10-year U.S. Treasury Note (^TNX), we've been in a general environment of declining interest rates since the early 1980's, which also has been fueled by the dovish monetary policy of the Federal Reserve over recent years.


The reason this poses a concern is that once the Federal Reserve determines that it will no longer continue its quantitative easing policy, interest rates should start to rise. Especially the bond market will likely be adversely affected by this. Many of the rotation strategies don't have a cash-stop, but rather use (long-term) U.S. Treasuries as a safe-haven when stocks start to underperform. However, in a rising rate environment, especially long-term bonds may no longer act as a safe-haven in case of a pullback, correction or a prolonged bear-market. Therefore it becomes crucial to know when rotation strategies may no longer perform as expected (i.e. when to get out). Even with a buy-and-hold strategy, a typical 60/40 or 70/30 stocks to bonds allocation may no longer work to minimize portfolio drawdowns in a rising rate environment.

I recently came across this chart, provided by LPL Financial Research. It shows how, since 1967, treasury yield curve inversions have marked stock market peaks before a downturn and recession.


Though surprisingly accurate, the yield curve sometimes gives a signal way before the correction, e.g. August 2006 signaled a downturn, which didn't actually start until October 2007.

This made me wonder that maybe if I combined the indicator with the "AdvDecnCumAvg" indicator that I provided a few posts ago, I'd get a more robust signal system.

I analyzed all U.S. bear markets since 1966, listed at Gold-Eagle. Though not an official bear market (> -20%), I also included the correction of July 1990 - October 1990 (~ -15%), which was predicted. Both indicators gave a false positive in December 1978 and the Black Monday crash of 1987 was not predicted. There was no AdvDecn data available for the first bear market of 1966, but the yield curve signaled the downturn very accurately.


Occasionally the yield curve would provide the first signal (yellow), and at other times AdvDecn would provide the first signal. The second (green) signal acts as the final trigger signal.

Though admittedly not that many data points, existing data would suggest that when using these two indicators in conjunction with each other, assuming historical data applies in the future, we can somewhat accurately predict a future major downturn in the stock market without leaving too much on the table by running to the fences prematurely.

A glance at the treasury yield curve today, on May 18, 2015, along with the AdvDecnCumAvg, would suggest that a major market correction isn't looming behind the corner, yet. Please find the link to the automatically updating Google Sheet below.






QH U.S. Treasury Yield Curve

Saturday, May 9, 2015

S&P 500 Smart Money Screener

To continue on our journey of screening for market anomalies, I've created a "smart money" screener for the S&P500. Quantified Alpha recently published an article that identifies market anomalies that have been academically proven to provide alpha (i.e. risk-adjusted outperformance over the overall market), or in English; proven "to work", when systematically exploited.

The first of the identified anomalies is the value anomaly, stating that over the long run, the returns of cheap stocks outperform expensive stocks. My previous post with the value screener may be helpful to identify stocks or sectors that currently identify themselves as good value.

The second anomaly is the momentum anomaly, stating that on average, past winners continue to outperform and past losers will continue to underperform. Most of the QuantHead blog concentrates on the momentum anomaly with providing relative strength (/ absolute strength) rotation models.

The third anomaly is the "smart money" anomaly, which states that when company insiders, financial institutions and short sellers are bullish on a stock, it tends to outperform and vice versa. The article suggests three metrics to focus on: 1) short interest as % of total float, 2) net change in company insider ownership over the last 6 months and 3) net change in institutional ownership over the last 3 months.

By using a similar approach for my smart money screener as the value screener of the previous post, these three metrics are each ranked from 0-100%, summed up and ranked again from 0-100%, providing a "Smart Money Rank". I also provide a "Trending Smart Money Rank", which ranks the top decile (50 stocks) by their 6-month performance. And once again I provide a chart, which I call "Smart Money Sectors". It would seem that as of May 9, Financials and Consumer Goods are in the lead. Please find the link to the spreadsheet below.

The fourth anomaly according to Quantified Alpha is the business quality anomaly, which states that companies that manipulate their earnings in the short-term will vastly underperform in the long-run. I don't have access or haven't been able to find any of the data that they suggest as metrics to focus on: 1) R/D expenses as percentage of assets, 2) earnings accruals as percentage of assets, 3) external financing to assets, 4) depreciation to capital expense ratio. Therefore, I'm not able to build a screener for the fourth anomaly.

The fifth anomaly is the earnings momentum anomaly, which states that companies that have beaten analyst estimates in the past, are likely to keep beating them in the future. The suggested metrics are 1) streak of EPS/revenue beats in a row, 2) last quarter EPS/revenue surprise % and 3) number of estimate beats in the last 3 years. Similar as to the fourth anomaly, I don't currently have access to these metrics, so I won't be able to build a screener for the fifth anomaly.

For anyone interested, it might be possible to build screeners for the fourth and fifth anomalies with Quantshare, Amibroker or Equities Lab, though like Quantified Alpha, these services require a subscription or an upfront fee.


QH S&P 500 Smart Money Screener

Saturday, May 2, 2015

S&P 500 Value Screener

May 4, 2015 Update: The sectors are now inversely weighted according to each sector's weight in the S&P 500, for a better representation of undervalued sectors.

Inspired by Paul Novell's composite value score (VC2) that he bases many of his systems on, including the "Trending Value System", I created a screener that attempts to showcase currently undervalued stocks of the S&P 500. Note that Paul's systems aren't only restricted to S&P 500, but because of the dynamic data pull, Google Sheets isn't too happy with data for thousands of stocks.

Paul bases his composite value score on the insights of several quant researchers (including the book "What Works on Wall Street") that choosing stocks based on a composite of value metrics over time outperforms portfolios based on solely one metric.

Determining a valuation of a company is often difficult, especially when trying to compare valuations across sectors and industry groups. Some like to look at the price-to-earnings ratio (P/E), but a lot of tech stocks often trade at seemingly premium value. Some like price-to-book (P/B), but REITs often trade below their book values. There seems to be trade-off's with each valuation metric.

I've attempted to create a valuation score similar to Paul's composite value metrics, which takes into account price-to-earnings (P/E), price-to-book (P/B), price-to-sales (P/S), price-to-free cash flow (P/FCF), enterprise value-per-earnings before interest, taxes, depreciation and amortization (EV/EBITDA) and dividend yield.

Each metric is ranked by percentage, 100% is granted to the best ranking stock. If data (dynamically pulled from FinViz and Yahoo Finance) for a metric is missing, a value of 50% is assigned for that metric, to reduce an unfair bias against the stock.

All the metrics are then summed up and once again ranked from 0-100% to provide a "Valuation and Yield Rank". The last column: "Trending Value Rank", similar to Paul's "Trending Value System", takes the top decile (50 stocks) of the "Valuation & Yield Rank", and ranks them by their 6-month performance.

I've also added a second sheet, "Undervalued Sectors", which shows the sectors of the 50 currently highest ranked stocks. Whether you decide to sort the stocks (from Z-A) by valuation and yield alone, or also taking into account recent price performance, it would seem that as of May 2, 2015, "Financials" and "Basic Materials" boast some of the best valued stocks of the S&P 500.






QH S&P Value Screener

Thursday, April 30, 2015

May 2015 Allocations




Here's a review of 2015 so far; two of the monthly rotation strategies are currently outperforming the U.S. stock market, and two are lagging.

January-April 2015 cumulative returns
1. MC GMR: +7.5%
2. Simple GMR: +2.7%
3. Buy and hold S&P 500: +1.9%
4. GTCR: -0.6%
5. Modified Dual Momentum: -1.62%

Happy May Day!

Tuesday, April 28, 2015

Advance/Decline Cumulative Average

I've created a new dynamic, automatically updating spreadsheet for following the NYSE Advance Decline Cumulative Average. It's essentially the same as the TOS study I shared in my very first post, but the data now extends all the way into the 1960's. A word of warning; because of the massive data-pull (daily data for approx. 50 years), the spreadsheet easily takes a couple of minutes to load, even with a fast internet connection.

The study draws a line that is the running sum of the daily percent change of the advancing issues compared to declining issues, and another line that is a 252 day moving average (the typical number of trading days over one calendar year).

The study isn't a holy grail by any means, but can give early warning signs as well as early recovery signs, either by the signal line crossing over the moving average (which worked well signaling the beginning and end of the 2008 bear market) or by negative and positive divergences (e.g. during the period of 1998-2003).

In addition to the chart with the AD lines, I've included a chart with the S&P 500 index for comparison purposes.



QH AdvDecCumAvg Spreadsheet

Tuesday, March 31, 2015

April 2015 Allocations

April 1, 2015 Update: Thanks to a reader, updated to reflect the correct allocations.
April 6, 2015 Update: Once again I've updated the GMR allocation, the correct allocation is "FEZ". I believe at the time I checked the allocations (March 31, after market close) Yahoo hadn't yet updated its data. I manually confirmed today that the other monthly strategy allocations should indeed be correct.






Cliff Smith Quarterly TAA signaled to be invested in long-term US treasuries for the 2nd quarter of 2015.

Monday, March 23, 2015

Simple Pair Switching Update

As of March 23, 2015, the "Simple Pair Switching" strategy has given a signal to switch allocations from bonds to stocks. The return for TLT (iShares 20+ Year Treasury Bond ETF) for the previous period is +8.1%, based on the adjusted close prices of November 26, 2014 and March 23, 2015.

Sunday, February 22, 2015

Portfolio Tracker

Feb 27, 2015 Update: The spreadsheet has been updated to show "Today's Change".
April 6, 2015 Update: The spreadsheet has been updated to pull dividend data from FinViz, which is faster, more accurate and more reliable than the GoogleFinanceAddon plugin was.

I've created a portfolio tracker Google spreadsheet that will automatically update unrealized gains and losses, as well as display current annual dividend income, both as a dollar amount and a percentage of the entire portfolio. Pie charts for "Total Allocation" and "U.S. Sector Allocations" are also included. I've provided a template with some sample positions. Make a copy to be able to edit it yourself. Input the appropriate values into the yellow fields: "share quantity" and "average purchase price / share" and select the appropriate category from the dropdown menu, and the spreadsheet will do the rest.

Sometimes the dividend won't be automatically pulled, in which case enter it manually into the "Dividend" column. In the template "MAPIX" is an example of this.

To insert more assets, just add rows below the lowest asset ("TLO" in the template) and copy/paste an existing row into the new rows. Please note that if you have a DRiP (dividend re-investment plan) in place, you'll have to manually update the share quantity and average purchase price / share after a dividend has been re-invested.




QH Portfolio Tracker Template

Monday, February 16, 2015

Sparkline Mini Charts

All rotation strategy spreadsheets and the "Buy the Dips Watchlist" have now been updated to include a mini line-chart of the recent price action, courtesy of the "sparkline" and "googlefinance" functions.





Monday, January 26, 2015

Cliff Smith Quarterly Tactical Asset Allocation

Jan 30, 2015 Update: Thanks to a reader, the spreadsheet has been corrected to use 3-month SMA instead of 63-day SMA as the filter.

Here's another quarterly rotation strategy that Cliff Smith presented on Seeking Alpha and backtested on ETFreplay.com, resulting in a CAGR +28.7% and Max Drawdown of -19.1%. The idea is to invest in the top asset of a basket of seven funds (or their corresponding ETFs) at the beginning of each quarter (January, April, July, October), unless the adjusted close price of the top ranking asset at the time of switching is below its 3-month simple moving average, in which case the allocation is VUSTX (or TLT/TLO).

The rankings are based on 105-day returns (weighted 50%) and 20-day returns (weighted 50%), based on adjusted close data from Yahoo Finance. As usual, I've created an automatically updating, dynamic Google Spreadsheet to help with the rotations.




QH Cliff Smith Quarterly TAA Spreadsheet



Thursday, January 22, 2015

Simple Pair Switching Google Spreadsheet

I've created an automatically updating Google spreadsheet for the previously introduced strategy "Simple Pair Switching", for those that don't have access to the Thinkorswim platform (or like me, who find it slower to login and load to TOS than load a web page).

The numbers in the ranking column don't match the values of TrendXplorer's TOS study. However,
I went back a few years, and the signals are pretty much spot on at the same exact places.

I used non-adjusted daily close data to stay faithful to TX's original study.



QH Simple Pair Switching Spreadsheet

Sunday, January 18, 2015

Universal Rotation System Backtesting Tool v0.51

Feb 02, 2015 Update: Thanks to a reader, the tool has been fixed to correctly display rankings with 7+ assets.

Right then, here it is: "Universal Rotation System Backtesting Tool".

It attempts to execute a similar process as Portfolio Visualizer and the ETFreplay.com, without being limited to backtesting to the end of the previous year, or a subscription fee.

Having already put quite a bit of effort into it, I'm hoping that this will become an open source project, where anyone who wants to take a shot at fixing or making it better, can share their work with others.

In addition to fixes/making it more intuitive, my hope is that folks will want to expand on this, add more variables, including volatility (and weighting for the volatility), multiple aggregation/ performance periods with weightings, as well as "Top 2" and "Top 3" as options, cash stop and moving average filters, or whatever else they might think is useful. If you are inspired to update the latest version in any way, please send me an updated version and I'll upload the latest version for everyone's benefit and to build upon in future updates.

Note that of the yellow fields, which contain variables that can be changed, currently everything but the "Top 1" field is active. ONLY change the data in the yellow fields. Also worth noting is that you have to enter a start/end date that's after the actual start/end date of the aggregation period data point: meaning, if you select 9/1/2014 as the starting date for a monthly strategy, but as the period didn't start until 9/2/2014 because of Labor Day being on the 1/9/2014, you'll get error messages. In which case, you can for example select 9/2/2014 or 9/3/2014 instead, and it'll work fine.

There is enough "space" for 20 years of monthly backtesting, but the space for longer backtest periods may become limited when backtesting weekly strategies (also an area to expand on in the future). You can backtest to an earlier point in time than where all the assets have data from, however these assets are obviously not taken into account before they existed (populating synthetic data for any missing asset data might be an area to expand on in the future). The first asset should in these cases be the oldest asset, since the date is drawn from the "Asset1" tab.

As usual, I don't guarantee any of the data or calculations presented being correct and this tool should only be used as an informational device. Please let me know if you spot any errors, or want to improve on this but need more information on how the tool "does its magic"!


QH Universal Rotation System Backtesting Tool 0.51

Friday, January 16, 2015

Universal Rotation System Backtesting Tool

Here's a little teaser preview of what I've been working on lately:
I started building a dynamic Google spreadsheet to test out rotation strategies.

It currently allows you enter the assets (max.10), aggregation period (weekly, monthly, quarterly), performance period, start date and end date. For example If you select "Monthly" as the aggregation period and enter "3" as the performance period, the backtest will look at the assets' relative performance over 3 months. As soon as any variable is changed, the spreadsheet will pull data from Yahoo Finance, and populate backtest results, showing the allocations for each period, the returns for those allocations and an equity curve and stats for the backtest period. It will also show the equity curve and annual return of SPY as comparison.

The idea is, time and energy allowing, to eventually add more variables, including volatility (and weighting for the volatility), multiple aggregation/performance periods with weightings, as well as "Top 2" and "Top 3" as options.



Thursday, January 8, 2015

Dynamic Google spreadsheets

I've created automatically updating, dynamic Google spreadsheets for various previous strategies, including GMR, GTCR, Simple GMR and Fidelity Sector Rotation. All of these use adjusted close data from Yahoo Finance. Links to the spreadsheets can be found under the corresponding strategies.


Monday, January 5, 2015

Modified Dual Momentum

Jan 6, 2015 Update: The spreadsheet has been updated to take volatility into account in the rankings.
May 9, 2015 Update: Thanks to a reader, the 63-day volatility for TLT now points to the right data.
May 20, 2015 Update: Thanks to Gene Wildhart, the volatility calculations have been changed.

Gary Antonacci recently published a book "Dual Momentum Investing" that has raised quite a bit of discussion in the quantitative investing community. The idea was that he combined relative momentum (how assets are performing compared to each other) and absolute momentum (how assets are performing in comparison to short-term treasuries). He backtested his strategies with decent results over the last almost 40 years, but because the U.S. stock market has been so strong in the last few years, the strategies have lagged, compared to the U.S. stock market. For a lot of people, myself included, the goal is to beat the U.S. stock market and it's hard sticking to a lagging strategy year after year.

Scottsinvestments.com created a strategy inspired by Antonacci's Dual Momentum, but it has also lagged the U.S. stock market in the last few years, providing an annualized return ~ +8% over the last 5 years.

After reviewing Antonacci's book, Lowell Herr from ITA Wealth Management stepped up and modified the dual momentum strategy to have a better performance over the last few years, by increasing the number of securities for inclusion in the portfolio, shortening the look-back period and rebalancing every 33 days, which has the rebalancing date float throughout the month, rather than always at a specific date. Whether these changes are curve-fitted to improve the performance in certain conditions, or improvements leading to a robust strategy, remains to be seen going forward.

In Lowell's model, a 50% weight is assigned to 3 month (quarterly) performance, a 30% weight to 6 month performance and a 20% weight to 63-day volatility. Every 33 days equal amounts are invested in the top 2 ranked securities, unless the ranking is worse than SHY (cash), in which case one or both securities are replaced with SHY (cash). The green curve below is his backtest with these figures, providing ~+20% CAGR over the last 8 years.




I created an automatically updating Google Spreadsheet that shows the current rankings, based on the same weights of performance and volatility as Lowell uses. It will highlight the top 2 assets in green, unless their performance is worse than SHY. All assets ranked below SHY are highlighted in red. All one needs to do is check the spreadsheet every 33 days or so and re-allocate to the (new) green securities.

Schwab commission free substitutes are also provided.






QH Modified Dual Momentum Spreadsheet

Fidelity Sector Quarterly Rotation

Jan 8, 2015 Update: By a reader's request, I've also created an automatically updating Google spreadsheet, which uses adjusted close prices.

On a previous post highlighting Seeking Alpha contributor Varan's strategies, I touched on a strategy called "Fidelity Sector Rotation". This strategy looks at the 8-week performance of 44 Fidelity Sector funds and a Vanguard Long-Term Treasury fund at the close of the first week of each quarter, and invests in the top performer for the following quarter.

Varan backtested the strategy for the period 1991-2011 with CAGR +25% with a maximum annual loss of -11%, beating the S&P500 index in 17 out of 21 years. Forward-testing it up to date, the strategy returned +1.74% in 2012, +38.5% in 2013 and +18% in 2014.

To help with the rotations, I created a ThinkOrSwim study that automatically updates and shows the current leader of the basket. All one has to do is to check this after the close of the first week of each quarter (first week of January, April, July and October). The only difference to Varan's study is that the prices used are close prices and not adjusted close prices (dividends and splits not taken into account).

The funds are commission-free with a Fidelity account, but since I don't have a Fidelity account,
and fund commissions are somewhat bigger for me than ETF commissions, I also created a list of ETF substitutes. It is worth noting though that some of the ETFs track the corresponding fund's performance better than others, so to use the strategy in its most pure way, the sector funds should be used, rather than the ETFs.






QH Fidelity Sector Rotation TOS Study

QH Fidelity Sector Rotation Spreadsheet

Saturday, January 3, 2015

2014 Year in Review

Feb 01, 2015 Update: Thanks to a reader, a couple of typos have been corrected in the GMR returns.

It's time to see what worked and what didn't for 2014, in order to adjust going forward. The disappointing news is that most of the ETF rotation strategies I follow, greatly underperformed, if compared to just holding the US stock market (SPY) or utilizing the "KISS Low Volatility Rotation" strategy, which basically had you invested in SPY for the entire year. The only rotation strategy that narrowly beat the market was "Simple Pair Switching".

Of the other strategies, "Buy the Dips" worked well throughout the year and so did "Hedged Convexity Capture".

Benchmark (SPY): +12%
KISS Low Volatility Rotation: +12%
Global Market Rotation: +3%
Global Transportation with Commodities Rotation: +5%
Simple GMR: +4%
Simple Pair Switching: +13%

A bit disappointing for the rotation strategies that backtested to beat the market every year.
A good lesson for the new year to stay diversified with various strategies and good reminder that
even with rigorous backtesting, past performance doesn't necessarily indicate future performance.

Below is the breakdown of the signals, returns and cumulative returns for the rotation strategies for 2014.