Solved: Errors Downloading Stock Price Data from Yahoo Finance

Recently, Yahoo Finance – a popular source of free end-of-day price data – made some changes to their server which wreaked a little havoc on anyone relying on it for their algos or simulations. Specifically, Yahoo Finance switched from HTTP to HTTPS and changed the data download URLs. No doubt this is a huge source of frustration, as many backtesting and trading scripts that relied on such data will no longer work.

Users of the excellent R package quantmod  however are in luck! The package’s author, Joshua Ulrich, has already addressed the change in a development version of quantmod. You can update your quantmod  package to the development version that addresses this issue using this command in R:

devtools::install_github("joshuaulrich/quantmod", ref="157_yahoo_502")

Of course, you need the devtools  package installed, so do install.packages("devtools")  first if you don’t already have it installed.

Once the package updates,  quantmod::getSymbols(src = "yahoo")  should work just as it did prior to the updates on the Yahoo Finance server. I can verify that this worked for me.

Of course, if you don’t want to update quantmod to a version that lives on a Git branch, you can wait until the changes are merged into master and do


I don’t know when that will happen, but I have been using the branch version for a few days now, and all appears to be working as expected.

Update: A user suggested making use of the quantmod::adjustOHLC() function as the adjusted close of Yahoo data is currently incomplete, and doesn’t account for dividends. Example usage:


First time here? Check out our posts on machine learning in finance and our recent review of dual momentum as an investment strategy. Enjoy!

Dual Momentum: A Review

I recently read Gary Antonacci’s book Dual Momentum Investing: An Innovative Strategy for Higher Returns with Lower Risk, and it was clear to me that this was an important book to share with the Robot Wealth community. It is important not only because it describes a simple approach to exploiting the “premier anomaly” (Fama and French, 2008), but because it is ultimately about approaching the markets with a critical, inquisitive mindset, while not taking oneself too seriously. I think we can all do with a dose of that sometimes.

Gary’s style is unique: this is the work of a free and critical thinker who is not afraid to question the status quo. While articulately drawing from a range of sources, from Shakespeare to Bacon and Einstein to Buffet (even Thomas Conrad’s 1970 book Hedgemanship: How to Make Money in Bear Markets, Bull Markets and Chicken Markets While Confounding Professional Money Managers and Attracting a Better Class of Women, which has got to be the greatest title in the history of trading books), Gary comes across as playful and slightly eccentric (which is wonderfully refreshing in a book about the markets). He derides economists who take themselves and their models too seriously (the line “for followers of CAPM, the real world was an annoying special case” almost made me fall off my chair), and importantly, he does this from the perspective of someone who has won the right to do so through hard-fought and won practical experience.

In this post I’ll describe some of the highlights from the book, including a description of Dual Momentum and Gary’s modular approach for exploiting it. I’ll also describe a variation of this approach and of course illustrate the performance of both approaches with some equity curves. Robot Wealth members have access to the code for implementing these systems and a research framework for additional experimentation.

There is a lot more to Gary’s book than the results I’m showing here, including detailed discussions around the existing momentum literature, the basis for momentum (it’s always nice to have a tangible reason for an anomaly to exist before committing capital to it) and suggestions for other Dual Momentum implementations. The book is highly recommended.

Momentum, Relative and Absolute

The seminal work of Jagadeesh and Titman (1993) showed that relative momentum – that is, the returns of an asset in comparison to other assets – provides profitable trading opportunities which are largely robust to the parameters of the trading strategy that might be used to exploit them. They showed that the returns of relative momentum outperformed benchmark returns, however in order to harvest this out-performance, one must typically endure significant volatility, often only marginally better than the benchmark itself. For many active investors and managers, the reward may not justify the risk.

Antonacci (2012) published an extremely simple yet highly effective extension to relative momentum. He also looked at the absolute momentum of an asset – that is, the momentum of the asset relative to itself – and found that by combining the two types of momentum, he could reap the rewards of relative momentum investing while vastly reducing the volatility of the approach.

Antonacci’s Dual Momentum is extremely simple to implement and manage, requiring at most a few positional adjustments each month. This combined with its history of low volatility out-performance in my opinion makes it the perfect place to start for people who are new to trading, prior to investigating more complex strategies. It won’t shoot the lights out and make you rich overnight, but it has proven itself over time to be a robust way to outperform the market in the long term.

So why isn’t everyone doing this? My theory is that it is too simple. Most folks who decide they want to beat the markets like an intellectual challenge. They like to apply advanced quantitative methods or perform in-depth research into the fundamentals. Of course, I really like doing this too, and these methods can be handsomely profitable. But they take a huge amount of effort and usually a lot of frustration to get them right. Dual Momentum is like low hanging fruit. When you’re starting out, it makes sense to work on something that is both simple and robust, even if it doesn’t exactly satisfy that intellectual itch, and at least start getting some results. One learns a lot in the process.

Dual Momentum Explained

Before we go any further, I’ll explain what is meant by “Dual Momentum” and how it might be applied.

Dual Momentum is about selecting assets that have both historically outperformed and also themselves generated a positive return. The first step in applying Dual Momentum is to compare the assets of interest against one another. If an asset has a higher return than another over the time period of interest, then it has positive relative momentum. We select the assets which have positive relative momentum for further analysis. Relative momentum thus acts as the initial filter.

Next, we look at the absolute momentum of individual assets. That is, we look at the performance of individual assets compared only to themselves. In simple terms, if an asset has a positive return over the time period of interest, its absolute momentum is positive, and if its return is negative, its absolute momentum is negative. Taking our assets with positive relative momentum, we would only consider buying those assets whose absolute momentum is also positive.

It is possible for an asset to have positive relative momentum and negative absolute momentum. For example, if the whole market was going down, the best performer in such a bear market would have positive relative momentum, but it might have negative absolute momentum. That is, it might have lost less than its peers. The Dual Momentum approach would prevent us buying such assets. Likewise, an asset might be going up and have positive absolute momentum, but if other assets performed better, it would have negative relative momentum. The Dual Momentum approach would force us into the assets that had both gone up and outperformed their peers.

In the description above, I referred to the long side only, but of course Dual Momentum could be applied to the short side in the same way. In my experience, a long only Dual Momentum strategy seems to perform better when applied to equities (which makes sense given the long-term upward bias in that asset class), but you may be able to apply it in a different way that I haven’t thought of, or apply it to a different asset class, in order to take advantage of the short side too.

Implementing Dual Momentum

There are many ways to build a strategy that implements the Dual Momentum approach. Gary’s research shows that momentum works best when applied to geographically diversified equity indices. This research was backed up by Geczy and Samonov (2015), by way of a 215-year backtest!

We can’t easily invest directly in an index, so in this examination of Dual Momentum, we used Exchange Traded Funds (ETFs) that track the indices of interest. While this analysis is constrained by the formation date of the individual ETFs, we found that the results are generally in line with Gary’s results over the same period. Gary’s backtests using indices date back to 1974 and demonstrate a greater degree of out-performance than is evident across the relatively short (~10 years) backtest used here.

Below are the results of an ETF-based version of the modular approach described in Antonacci (2012), as well as a sector-rotation approach. Transaction costs and ETF distributions have not been included in these simulations, however would likely not have a significant impact on results given the typical holding period and trade frequency.

Modular Dual Momentum

The modular approach to Dual Momentum is the one described in Antonacci (2012). This approach dictates that every month, we compare two related sectors or two parts of a single sector and select the better performer over the formation period (the prior twelve months). If the better performer has positive absolute momentum, we buy that asset. If the better performer has negative absolute momentum, we hold treasury bonds or investment grade bonds.

Gary provides some examples of “modules” to which one might apply Dual Momentum:

  • Equities (US equities – international equities)
  • Bonds (credit bonds – high yield bonds)
  • Economic stress (gold – treasury bonds)
  • REITS (mortgage reits – credit reits)

We could also look within other sectors for more ideas for modularizing Dual Momentum.

Download my R code – used to generate the following three Modular Dual Momentum equity curves  – here.

Here are the results for the equities and bonds modules from 2007 to March 2017. The ETFs used were SPY/CWI and CSJ/HYG respectively. We can see that over this period, Modular Dual Momentum resulted in returns that were comparable with the best performing component but with a fraction of the maximum drawdown. The results are also consistent with Gary’s finding that Dual Momentum tends to underperform during strong bull regimes or when the market rebounds, but thanks to its ability to weather bear markets, has outperformed in the long run. In his paper, Antonacci (2012) provides a backtest that extends back to 1974 and which better captures this long-term outperformance (as stated above, in this ETF implementation, we are constrained by the time that the ETFs have been in existence).

Dual Momentum Equities Module

Duam Momentum Bonds ModuleFinally, here are the performance charts of a Modular Dual Momentum portfolio consisting of a 60-40 split between equities and bonds modules.

60-40 Equities-Bonds Dual Momentum

Dual Momentum Sector Rotation

This is a twist on Antonacci’s modular approach, and is actually the approach I prefer. We choose a universe of ETFs that represent various sectors, regions and asset classes, ranking them based on their return over the formation period and buy up to the best three ETFs whose absolute momentum is also positive. Essentially, this approach results in a sector rotation strategy that leverages the benefits of Dual Momentum. Robot Wealth members have access to the complete research environment for reproducing and experimenting with this Dual Momentum Sector Rotation strategy. Join up here.

The results below are for a Dual Momentum Sector Rotation for the following sectors:

  • Stocks in the Russell 1000
  • Stocks in the S&P 500
  • Stocks listed on the FTSE
  • European equities
  • Japanese equities
  • Asia-Pacific (ex-Japan) equities
  • 7-10 Year Treasury Bonds
  • 1-3 Year Treasury Bonds
  • Gold

And the results using a 6-month formation period:

Dual Momentum Sector Rotation

No doubt you can see why I prefer this approach over the modular one! Although to be fair, the parameters that I used are among the best parameter sets for this particular universe of ETF sectors. A good question to ask now would be “how robust is the strategy to changes in the parameter space?”. After all, the goal of strategy research is to discover robust strategies that perform well in the future, not to create the best backtests. We will soon be adding our suite of robustness testing tools to the members’ area to help answer this question.

Important Caveats

Readers please note that my implementations have some important differences from the approach that Gary describes in his book and on his website. Gary’s equities implementation is called Global Equities Momentum (GEM) and you can see its performance and read the fine print here.  One of the key differences is that the trend of the US market determines the trend of all equities indices. In other words, if the return of the S&P500 is less than the return of short-term treasuries, we hold bonds regardless of the performance of foreign stocks. The reasoning for this is research referenced in Gary’s book that shows the US stock market leading global equities markets. In the short backtest posted here, there is only one month when this makes a difference, but it may be more significant in the long term.

Also, Gary explicitly advises against a sector rotation model. In his backtests back to 1974, he found that sector rotation outperformed the S&P500, but underperformed his GEM model. If you look at Gary’s results here, you can see that sector rotation outperformed GEM only intermittently (including the last few years of the simulation), with GEM coming out well on top over time. However, the sector rotation Gary describes on his website here is, I think, very different to my implementation in that it examines the individual sectors of the US market only. My implementation is more of a “global macro sector rotation”.

Gary is quite explicit that based on his research, the best application of Dual Momentum is the one presented in his book, or a similar one that focuses on equities, which have historically offered the highest risk premium. Readers should certainly familiarize themselves with Gary’s FAQ page in order to get the full story, or better yet, read the book!


This article provided a description of Dual Momentum and presented results for two different implementations of Dual Momentum using ETFs. We found that in general, the results of our approximately 10-year ETF-based simulations were in line with Gary’s much longer index-based simulations, although the latter better demonstrate the long-term outperformance of the Dual Momentum approach. It is recommended to read the FAQ page on Gary’s website,or better yet, the book, to get the full story.

Robot Wealth members have access to the code that was used to generate the backtests shown above, which forms part of a larger research environment that can be easily modified and extended, for example by varying the instruments used in each module, thinking up other modules, and varying strategy parameters like the formation period and the number of ETFs held in the sector rotation version. There is lots of other useful content in the members’ area too, including a machine learning research framework, educational material for learning algorithmic trading, and an active and exclusive forum of like minded individuals. We would love to have you in the community – register here.


Antonacci G. 2012, Risk Premia Harvesting through Dual Momentum

Antonacci G. 2015, Dual Momentum Investing: An Innovative Strategy for Higher Returns with Lower Risk 

Fama, E. and K. French, 2008, Dissecting Anomalies, The Journal of Finance, 63, pg. 1653-1678.

Geczy, C and Samonov, M. 2015, 215 Years of Global Multi-Asset Momentum: 1800-2014 (Equities, Sectors, Currencies, Bonds, Commodities and Stocks)

Jagadeesh N. and Titman S. 1993, Returns to Buying Winners and Selling LosersJournal of Finance, Vol 48, Issue 1, pp.65-69