Pairs trading gold and silver

Hello, I am very new to Quantopian and Algorithm Trading. So, I want to share what I pairs trading gold and silver done and learn from all of you. The Strategy It is a pairs trading gold and silver reversion strategy that tries to capitalize the mean-reverting feature of the spread between gold and silver.

Run every day First of all, I extracted 1 year around, I don't know how to make it exactly a year of the price of gold and silver. Then using 20 days moving windows, I calculate the slope and intercept from the linear regression between the two assets. I stored the calculated spreads should have number of spread, approximately. Entry Run every day I checked the entry after market started by using the schedule function.

If the current spread is higher than 1. If the current spread is lower than MEAN - 1. That means the program will continue entering the position if conditions are met. The reason for doing this is that I cannot pick the exact top but I am sure that it will revert to the mean. So, I keep adding positions. Exit Run every minute If the current spread reverted to the mean, I will close all positions.

However, it is difficult to catch the exactly equal. One problem I got is that I don't know why sometimes, even the 5 opened positions reverted to the mean, I still have negative return. Also take a look at some others that trade GLD: Onleverage hit a new high of 2. It's fine if intended, if accidental can ruin one's day. Sorry, something went wrong. Try again or contact us by sending feedback. 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 pairs trading gold and silver 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 ofas 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 pairs trading gold and silver unrelated to Quantopian about pairs trading gold and silver 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.

I have attached the backtest for your reference. There was an error loading this backtest. Backtest from to with initial capital. 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.

There was a runtime error. Sorry for the inconvenience. Try pairs trading gold and silver the built-in debugger to analyze your code.

If you would like help, send us an email. Thanks for your reply! What do you mean by Max Lvrg: Please sign in or join Quantopian to post a reply. Already a Quantopian member? Algorithm Backtest Live Algorithm Notebook. Sorry, research is currently undergoing maintenance.

Pairs trading gold and silver check back shortly. If the maintenance period lasts longer than expected, you can find updates on status. Sorry, something went wrong on our end. Please try again or contact Quantopian support.

You've successfully submitted a support ticket. Our support team will be in touch soon. Send Error submitting support request.

Build your first trading algorithm on Quantopian.