Turtle trading is a well known trend following strategy that was originally taught by Richard Dennis. The basic strategy is to buy futures on a day high breakout and sell on a day low, although the full set of rules is more intricate. I've modeled the meat of the strategy in Quantopian and used it to trade exchange-traded funds ETFs , in this case just some silver and copper securities. I used rules from here. From what I have seen, the rules of turtle trading slightly vary from source to source, however what's outlined in that PDF seems well-guided and reliable.
If you want to adjust the rules you can clone this and it should be fairly straightforward from there. I've also added an option in the code if you only want to long and not short. To trigger buys and sells, the code calculates the goal amount of shares then works from there to determine how many to buy or sell.
This method for determining order amount works well for things like risk-adjusted portfolio sizes. This is a pretty fundamental strategy and it seems to work well. There are a few different parameters to play with, so clone this and see if you can get some good results or even add to the code in any way. If you want to experiment with adding different ETFs, you can get ideas from a list of futures like this one.
From there just Google for whatever ETFs, like "corn etfs", and add the respective symbols to the code. 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 , 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. Great work Gus, thanks for forwarding this my way. I used to run a strategy that was very similar to the Turtle Trading strategy. The most important part of the strategy though is the pyramiding of the position coupled with the matrix of which assets you could hold together and in what size.
The money management aspect of the strategy was almost more important than the basic momentum algo. I'm wondering when Quantopian will allow that kind of detailed money management. Either way, this is a great start, and I'm sure others will build on it in the future, that's the value of this platform, people working together to build interesting stuff. Unfortunately that stuff you mentioned is difficult to implement in a dynamic way.
IMO the order of importance of designing this system is 1 the markets you will trade, 2 position sizing, 3 exit strategy, 4 entry strategy. It needs to be well diversified to work well across stock markets, commodities, currencies and bonds. You'd also probably want to keep each category from taking up more than 25 percent of the portfolio. Keep the position size no more than percent of equity. The problem I've run into using the turtle strategy on ETFs is leverage.
You may not be able to take all the signals because of margin requirements, which you don't have with futures. This is great and I have tried to work with your sample as a way to learn how to use the interface and Quantopian.
I've adapted parts to make a modified strategy with an EMA requirement and also a trailing stop loss. Somewhere in my modification it went wrong and I get a run time error. Your help would be greatly appreciated. Mason, you should just go ahead and put up a new thread post. FYI, if you ran a "full backtest" on a previous working version, that backtest includes a copy of the code as it was then. It might help to decipher what went wrong.
Hey Mason, glad to hear you like this. I'm not sure where that error is coming from. You can do as Dan suggested and I'll try to help. Thanks for sharing this Turtle strategy. I am quite new to coding and having trouble implementing a few more rules specifically with regards to placing sell stop orders when a trade is triggered and placed.
SJ - I suggest that you attempt to make the code, and then make a new post that explains what is working and what isn't working. You'll get more help that way. Asking a question on an old thread, unfortunately, doesn't work very well. I'll try to get you started though in case you just need a bump to get going. You can call your stop order by doing something like:. So if you just want that to trigger when something happens when some random variable a is greater than 3, for example: First, the testing commodity is uranium?
Is WW3 going to happen so Uranium is a liquid commodity to trade? Second, most of system components are missing: I was amazed first by Turtle system can be implemented with lines of concise code and then I figure out it's probably just an intern who wants to get his assignment done. Because of how Quantopian works right now, it is not possible to use the exact turtle trading rules.
As I said in the code comments, this is a sample template to share with the community. I am new to this and was playing with your code but I am lost on the tickers. There are two easy lookup methods to find stocks in the IDE. You can use the sid method or the symbol method , either of which should pop up an autocomplete window for you on the open parenthesis.
The sid number is a unique identifier on our platform, as trading symbols can be reused on the exchanges. Then just start typing the ticker you are looking for and you should see it show up in the autocomplete list see screenshot below. I'm not a programmer. I have traded futures and options but prefer stocks and ETFs.
There was a misconception a couple of comments back that needs correcting. All Turtle System 1 entries are at 20 days and exits at 10 days. All Turtle System 2 entries are at 55 days and exits at 20 days against your position; long or short. I didn't look back on this thread to see if anyone has mentioned it before. Hope this is helpful to someone. Gus this is a great start. However I have notice that in your algo you are not adding units if you are in the good side of the trend.
This is what it would make the strategy more solid and move the stops as the trend is moving up or down. Do you have any plans to complete the algo to include these rules? EG, I am not a programmer and usually only trade the long side. It pays well, but requires more patience. Others might be interested in seeing it both ways. Hey Erick, the algorithm does that, but maybe not to the level you desire. You can see in this line from my original code:.
As our account grows, the amount we buy or sell should grow too. I would love to this worked on more. The system is really cool. Ordered a book on it, reading the pdf tonight. I used System 2 for entries 55 day breakout and exits 20 day breakout. Here is my understanding of the Turtle Trading System System Some things not included The problem I always found with the position sizing for the Turtle strategies was that for things which didn't move much, it required an obscene amount of cash to be placed in one position, preventing other positions from being open and hence, the possibility for uncorrelated returns.
I assume this is fine for futures since its already leveraged but is not the case for stocks. Michael Covel has said that trend following strategies do work for ETFs, but I've yet to work out how. He did link to a nice paper. They give a definition for a trend following signal -- if I remember, the position size is relative to the strength of the signal, based on the theoretical returns for trading the previous month.
The important part here is that you don't have too many lots of the same type of highly correlated assets. James thanks for sharing the paper. I agree, the cash required makes the strategy difficult because it limits the number of entry signals you can take, which drastically effects the results of the strategy.
That being said, I believe Leigh is right that the 'risk' is the same per position because they are equalized by the day ATR. I'm new to trading, what leverage should I aim to use? What's viable for live trading? I see the Quantopian contest sets a limit at 3. I will give the paper a read. My next step is to play with the strength of signals based on other trends and to reduce the taking of multiple signals in highly correlated markets.More...