Last post in 2020. See you, 2020. See you, in 2021.
The Turtle Traders experiment was conducted in the early 1980s by Richard Dennis and William Eckhardt to see whether anyone could be taught how to make money in trading. Therefore, the trading strategy that has been taught to these apprentices is named after this experiment as “Turtle Strategy“.
In this post, we’re going to quickly go through the turtle strategy itself, and I’m going to experiment with a few things against the backtesting platform that I’m checking out recently: JoinQuant.
This post will be split into below sections:
- Quick intro
- Objectives
- Backtesting
- Summary
- Reference
- Code Reference
Here is the Chinese version of this post in case anyone is interested: 经典海龟策略-股票多标的-短线趋势长线追击双系统.
Quick intro
I’m going to piggyback the existing posts so I don’t have to repeat the lengthy history of turtle experiment here. You can quickly read through the below posts to get an idea of what turtle strategy is about:
In short, the turtle strategy is a momentum strategy that uses the Donchian channel as the indicator to buy when we spotted the bullish trend and to sell when the trend goes bearish. Turtle strategy also builds two similar systems to capture both strong and weak movements, along with an internal mechanism to manage the risk of loss of capital to 2% in one trading day.
Objectives
Implementing the turtle strategy is not a new thing to the quant industry. Therefore, I would like to instead experiment with a few additional things that might benefit the process of the quant research:
- Most of the quant strategies that you can see in the quant-trading backtest platforms scattered their function definitions and variables all over the places. I’m gonna adopt the
object-oriented programming
concept in this implementation to increase the reusability and readability of the code. - By instantiating the instance of
class TurtleSystemManager()
, we persist the data in this instance across the entire backtesting time span. - To decrease the complexity of the positions, capital, and available cash of these two systems in one algorithm trading script, we use
context.subportfolios
in JoinQuant to simplify the logic and codes.
Backtesting
The setup in my version of implementation are:
- Run every 15 minutes to calculate and inspect the trading signals
- The stock pool updates each month with the latest fundamental data
- The trading target in the original turtle strategy is the stock futures, but we’re looking at the stocks in China stock market. So we need to make several adjustments accordingly:
- risk_ratio
- The leverage_ratio in original turtle strategy is 10 while trading stock futures. Here we make it 0.1 so that our greatest loss per day is limited to 0.1%, and also we’re able to buy more stocks.
- capacity_per_system
- The stock pool that we update each month contains more than 20 stocks. As turtle strategy is about buying positions at several prices along with the price soar (vise versa in the sell/short side), we place a limit of maximum of 8 stocks per system to make sure we place our capital in the stocks we preferred other than spreading the capital in dozens of stocks.
- risk_ratio
- We use
40-day moving average > 200-day moving average
as the secondary trading signal to confirm the bullish trend. - Apply Donchian middle line to replace the Donchian low watermark as the new exit signal.
- As the China stock market policy prevents us from selling the positions that we buy on the same day, we apply another rule in our strategy that we need to hold the stock at least till the next available bar (which is the next day). See detail in 海龟策略应用在中国A股(股票)里的缺陷讨论(按分钟回测).
And here are the results of the backtesting of the turtle strategy:
Backtest 1
Setup:
Run the strategy once per day, and no specific sorting rules in the stock pool.
Result:
Comment:
Ummm… The performance is fairly poor but expected. We trade only once per day on the signal without monitoring the price movement for the rest of the day. It is pretty much like you buy a stock when you see the right price on the TV, and then you go play with your cats and dogs until the next day. If any trader can make money like this, anyone on earth can be a trader and no one lose money in the market.
Backtest 2
Setup:
Run every 15 minutes, no specific sorting rules in the stock pool, and use daily
close price to build the 40-day and 200-day moving average.
Result:
Comment:
The risk control is stronger when you monitor the stock movements every 15 minutes, and you’ll be able to control the daily loss within 2N
as instructed in the turtle experiment. As for the upward trend, the 15-minute interval also helps the program more accurately capture the entry signal to gain profit. However, the log messages also reveal that there are several times that you won’t be able to close your positions on the day. This represents that your position is exposed outside the risk control management system, causing a tremendous loss when the stock price dropping.
Backtest 3
Setup:
Run every 15 minutes, no specific sorting rules in the stock pool, and use 15-minute
close price to build the 40-day and 200-day moving average.
Result:
Comment:
Urgh….. I thought if I increase the granularity of the secondary indicator (40MA > 200MA) from 1 day to 15 minutes, the more accurate entry signals and more profit would be generated. By looking at the diagrams below, more signals do generate as the available cash is lower in the 15-minute scenario.
However, from the log messages you’ll notice that due to the limitation of the China stock market mentioned above, that there are risks that you buy the stock in the morning but things turned sour in the afternoon. Then all you can do is to look at the price go south and sweating all over your face. So we can kind of concluding that using daily
close price would be a mean of smoothing the data to avoid the zig-zag on price movement.
Backtest 4
Setup:
Run every 15 minutes, sort and rank the stock pool monthly, and use daily
close price to build the 40-day and 200-day moving average.
Result:
Comment:
According to what has been described in the book of turtle strategy and the characteristics of volatility of future itself, I sorted and ranked the stocks in Shanghai Shenzhen 300 index in order to identify the stocks that have higher profitability than the others. The rules and the factors that I used are as follow:
- goods_sale_and_service_to_revenue: Of course the sales revenue should represent a higher percentage in the total revenue income, indicating the major business is doing great.
- peg_ratio: A ratio to replace the traditional pe_ratio as Peter Lynch suggested. We’re looking at under-estimated stocks(omitting the stocks that peg_ratio is negative).
- debt_to_equity_ratio: The less debt the better.
- FCF (Free Cash Flow): The more free cash flow the better.
- turnover_ratio: Turtle strategy suggests us to target the markets that have a higher turnover ratio as in essence, turtle strategy is still a momentum strategy that looks for stocks that have high liquidity.
- pb_ratio: Also, we need to find stocks that are underestimated.
I was hoping that my petty trick would work and make the portfolio return better off. Sadly, it didn’t.
Summary
Even though the backtesting results above are not promising nor profitable for us to proceed to live trading, the objectives of this experiment have been achieved. We can use an object-oriented programming way of coding style inside these backtesting platforms. By doing so, the code can be reused when we implement our own automatic trading script later, reducing the time to rewrite everything the second time.
Other than that, we have also identified some limitations of running turtle strategy in the China stock market:
- The China stock market has the policy that restricts day-trading (selling the stocks that you purchased that day), leaving the risk of our positions uncontrolled.
- One lot in China stock market represents 100 shares. Any number of shares that are under 100 are not able to be purchased. This would raise the bar of purchasing stocks whose price are higher as we need to relocate our capital to several stocks in the strategy.
- Monitoring and trading several stocks in one turtle strategy is not preferable since it increases the complexity of managing positions during both bullish and bearish trend.
But there are other thoughts that we still can extend and develop upon the turtle strategy we built:
- We can see that the Donchian channel in turtle strategy is a lag indicator, meaning the momentum might have already passed when our indicators tell us to buy or sell. Therefore we might be able to switch to another indicator such as MACD or RSI so that we can spot the buy/sell opportunities in a quicker fashion.
- We can also reverse the signals to buy when we see sell signals and to sell when we see buy signals. This means that we’re going to use the turtle strategy as a
mean reversion strategy
instead of the originalmomentum strategy
.
To summarize, this strategy is not going toward the live trading stage in the short run. The code can only be used as a template or reference for anyone here to implement their version of the turtle system by overwriting the detail in each class function.
Enjoy! Cheers!
References
- 【量化课堂】海龟策略
- 海龟策略精讲
- The Original Turtle Trading Rules
- Turtle trading rules trend-following investing based on 20 amp 55-day highs
- 唐奇安通道
- 增强版唐奇安通道策略
Code Reference
Click here if you want to checkout the source code
1 | # Inspired from: https://www.joinquant.com/post/1401 |