You are on page 1of 11

Emeric Crué Python in Quantitative Finance May 2019

Back-Testing: Ichimoku
Trading Strategy
Using Python.

Introduction

The goal of this project was to implement the well-known Ichimoku trading system under
Python to test whether it is a reliable and profitable strategy. In fact, many books, papers and web-site
describe this how Ichimoku works, but it is difficult to obtain records its proficiency, especially about
after transaction costs. Since “we are never better serve than by ourselves”, I decided to test the so
called “Ichimoku”.

In order to be as close as possible to the reality, each position taken represents 100 shares of the stock,
and each transaction costs 0.025% of the capital invested.

Literature review

The Ichimoku trading system has been published in 1969 by a Japanese news-paper man named
Goichi Hosoda (1898 – 1982). The aim of this publication was to provide to trader an indicator for:

- Supports and resistances lines


- Entry and Exit position values
- Tendency direction
- Strength of the signals

Goichi Hosoda has publish seven books about Ichimoku between 1969 and 1980. However, none
of them have never been translated in English. It only exist several popularization books about this
technic.

For more information about Ichimoku, please visit:

http://www.kumotrader.com/ichimoku_wiki/index.php?title=Main_Page
Emeric Crué Python in Quantitative Finance May 2019

Data set description

To perform this empirical test I used the stock SAAB-B.ST, listed on the Stockholm stock
exchange and denominated in SEK. The first data set named “In Sample” starts from 2000-06-05, and
end on 2009-06-05, which represent 2315 trading days. The second data set named “Out Of Sample”
starts from 2009-06-06 to 2018-06-01, for a total of 2264 trading days.

I decided to use this asset for its fluctuation over the two data sets because I wanted to see how the
Ichimoku trading system reacts to strongly different tendencies.

The left graph represent the evolution of the stock price for the “In Sample” data set, and the right
graph stands for the “Out Of Sample”.

Methodology

Ichimoku is a system of moving averages that describe tendencies and provides buy/sell (short)
signals from weak to strong passing by neutral. The set of moving averages is as follow:

Tenkan Sen:

max[𝑖, 𝑖 − 1, … 𝑖 − 9] − 𝑚𝑖𝑛[𝑖, 𝑖 − 1, … 𝑖 − 9]
𝑇𝑒𝑛𝑘𝑎𝑛 𝑆𝑒𝑛 =
2

Where, 𝑖 is the price of the asset.


Kijun Sen:

max[𝑖, 𝑖 − 1, … 𝑖 − 26] − 𝑚𝑖𝑛[𝑖, 𝑖 − 1, … 𝑖 − 26]


𝐾𝑖𝑗𝑢𝑛 𝑆𝑒𝑛 =
2

Senkou Span A:
Emeric Crué Python in Quantitative Finance May 2019

𝑇𝑒𝑛𝑘𝑎𝑛 𝑆𝑒𝑛 + 𝐾𝑖𝑗𝑢𝑛 𝑆𝑒𝑛


𝑆𝑒𝑛𝑘𝑜𝑢 𝑆𝑝𝑎𝑛 𝐴 =
2

Please note that a shift of 26 periods in the future is added.

Senkou Span B:

max[𝑖, 𝑖 − 1, … 𝑖 − 52] − 𝑚𝑖𝑛[𝑖, 𝑖 − 1, … 𝑖 − 52]


𝑆𝑒𝑛𝑘𝑜𝑢 𝑆𝑝𝑎𝑛 𝐵 =
2

Please note that a shift of 26 periods in the future is added.

Chikou Span:

𝐶ℎ𝑖𝑘𝑜𝑢 𝑆𝑝𝑎𝑛 = 𝑖

Please note that a shift of 22 or 26 periods in the past is added. This difference (22 or 26) will be
discussed in the “Results” section.

Kumo:

The Kumo is the graphical representation of the two lines, the Senkou Span A, and the Senkou Span B.
It is often called the “could”.

The Long position occurs when:

𝐶ℎ𝑖𝑘𝑜𝑢 𝑆𝑝𝑎𝑛 > 𝑇𝑒𝑛𝑘𝑎𝑛 𝑆𝑒𝑛 > 𝐾𝑖𝑗𝑢𝑛 𝑆𝑒𝑛 > 𝑆𝑒𝑛𝑘𝑜𝑢 𝑆𝑝𝑎𝑛 𝐴 > 𝑆𝑒𝑛𝑘𝑜𝑢 𝑆𝑝𝑎𝑛 𝐵

The Short position occurs when:

𝐶ℎ𝑖𝑘𝑜𝑢 𝑆𝑝𝑎𝑛 < 𝑇𝑒𝑛𝑘𝑎𝑛 𝑆𝑒𝑛 < 𝐾𝑖𝑗𝑢𝑛 𝑆𝑒𝑛 < 𝑆𝑒𝑛𝑘𝑜𝑢 𝑆𝑝𝑎𝑛 𝐴 < 𝑆𝑒𝑛𝑘𝑜𝑢 𝑆𝑝𝑎𝑛 𝐵

In other cases, no position is taken, and current position is liquidated.

Results
In sample data set

The graphical representation of the Ichimoku system (with shift of -26 periods for the Chikou Span) is
as follow:
Emeric Crué Python in Quantitative Finance May 2019

The results of the in sample are as follow:

The graphs represents the gross return of the strategy over the period. The left one stands for a shift
of -22 periods for the Chikou Span, and the right one stands for a shift of -26 periods for the Chikou
Span:

The shift of -22 periods for the Chikou Span offers better results in terms of gross return, net return,
standard deviation, Sharp ratio and worst trade value. However, the number of transactions is greater,
so their costs too, and the mean of returns is slightly lower than with -26 periods.

The performances of the stock over the In Sample period is stored in the following table:

The following graph represents the performance of the stock over the period:
Emeric Crué Python in Quantitative Finance May 2019

We can easily identify that the strategy over performed the stock itself. The Sharp ratio and the
standard deviation are the best proof that the strategy protect against large losses.

Out of sample data set

The graphical representation of the Ichimoku system (with shift of -26 periods for the Chikou Span) is
as follow:

The results of the Out Of sample are as follow:


Emeric Crué Python in Quantitative Finance May 2019

The graphs represents the gross return of the strategy over the period. The left one stands for a shift
of -22 periods for the Chikou Span, and the right one stands for a shift of -26 periods for the Chikou
Span:

The shift of -22 periods for the Chikou Span offers better results in terms of gross return, net return,
mean of returns, Sharp ratio and worst trade value. However, the number of transactions is greater,
so their costs too, the standard deviation is slightly lower, and the best trade is lower than with -26
periods.

The performances of the stock over the In Sample period is stored in the following table:

The following graph represents the performance of the stock over the period:

Concerning the Out Of Sample data set, Ichimoku strategy provides smaller returns than a buy and
hold strategy. However, the standard deviation is slightly reduced by half, the mean of returns is ten
times bigger, and worst trade is lower.

Python code
See next page
Emeric Crué Python in Quantitative Finance May 2019

Continue on next page


Emeric Crué Python in Quantitative Finance May 2019
Emeric Crué Python in Quantitative Finance May 2019

Continue on next page


Emeric Crué Python in Quantitative Finance May 2019

Continue on next page


Emeric Crué Python in Quantitative Finance May 2019

You might also like