Back to Community
USO/GLD (Oil/Gold) Pairs Trading Algo using real price of Gold

This is an update of Justin Lent’s original GLD/USO pairs trading algorithm taken from Ernie Chan’s book, Algorithmic Trading. Pairs Trading is a market-neutral type of trading strategy that waits for an irregularity in the correlation between two highly correlated securities, and then goes short on the over-performer and long on the under-performer. A full tutorial on Pairs Trading is available through the Quantopian Lecture series.

Different from the original backtest, this algorithm uses the price of gold from Quandl to calculate spreads rather than the GLD ETF. However, in both algorithms, the GLD ETF is used to hold positions in gold. You can find more datasets like VIX, macroeconomic indicators, news & social media sentiment, and more on Quantopian Data.

A quick note on the backtest date periods: USO/GLD is a good mechanical pair but is not a profitable trade. However this algo should be able to serve as a template to test other interesting pairs trades - would love to see others post suggestions!

Other Quandl Data Examples:

Clone Algorithm
Backtest from to with initial capital
Total Returns
Max Drawdown
Benchmark Returns
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
# Backtest ID: 56ccd0806389270de4051879
We have migrated this algorithm to work with a new version of the Quantopian API. The code is different than the original version, but the investment rationale of the algorithm has not changed. We've put everything you need to know here on one page.
There was a runtime error.

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 Quantopian. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. No information contained herein should be regarded as a suggestion to engage in or refrain from any investment-related course of action as none of Quantopian nor any of its affiliates is undertaking to provide investment advice, act as an adviser to any plan or entity subject to the Employee Retirement Income Security Act of 1974, as amended, individual retirement account or individual retirement annuity, or give advice in a fiduciary capacity with respect to the materials presented herein. If you are an individual retirement or other investor, contact your financial advisor or other fiduciary unrelated to Quantopian about whether any given investment idea, strategy, product or service described herein may be appropriate for your circumstances. All investments involve risk, including loss of principal. Quantopian 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.

1 response

Ya, def not a good pair. Just doing a current 1-year backtest, this also gets crushed.