0% found this document useful (0 votes)
39 views8 pages

Optimizing Automated Trading Systems

This document discusses the optimization of automated trading systems, particularly in the context of Binary Options and High Frequency Trading (HFT). It emphasizes the collaboration between economists and computer scientists to enhance trading strategies through mathematical constraints and algorithmic optimization. The authors present a framework for improving trading performance by utilizing indicators like Bollinger Bands and oscillators like the Relative Strength Index, alongside testing and evaluation methods for profitability.

Uploaded by

andrew910309
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views8 pages

Optimizing Automated Trading Systems

This document discusses the optimization of automated trading systems, particularly in the context of Binary Options and High Frequency Trading (HFT). It emphasizes the collaboration between economists and computer scientists to enhance trading strategies through mathematical constraints and algorithmic optimization. The authors present a framework for improving trading performance by utilizing indicators like Bollinger Bands and oscillators like the Relative Strength Index, alongside testing and evaluation methods for profitability.

Uploaded by

andrew910309
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Optimizing Automated Trading Systems

Alessandro Bigiotti(&) and Alfredo Navarra

Department of Mathematics and Computer Science,


University of Perugia, Perugia, Italy
[email protected],
[email protected]

Abstract. In 2016, more than the 80% of transactions in the Forex market
(where the world’s currencies trade) have been directed by robots. The design of
profitable automatic trading systems is becoming a challenging process. This
requires a strong synergy of economists and computer scientists. Our aim is to
provide an optimization framework for trading systems that starting from a
generic strategy, enhances its performances by exploiting mathematical con-
straints. Moreover, the growth of new markets requires suitable solutions inte-
grating computer science tools with economic analysis. In this work, we mainly
refer to an emerging market known as Binary Options. Starting from basic
strategies used every day in the stock markets by professional traders, we show
how optimization issues enhance the outcoming performances. Tests on the
optimized algorithms are conducted on both historical and real time data.

Keywords: Trading system  Algorithmic optimization  Binary Options

1 Introduction

The increasing of computing capacity and the development of sophisticated hardware,


together with the development of the economic science called Technical Analysis [15,
17], are the main ingredients for the birth of High Frequency Trading (HFT) [4]. This
refers to the current trend in the stock markets to program robots that automatically
interact with the market itself in order to sell and buy stock options or commodities.
The frequency of operations is extremely high, impossible to achieve by human beings,
as well as they operate 24 h a day. It implies that even extremely small variations to the
prices of the contracts involved can be remarkable due to the high number of operations
performed. In 2016, more than the 80% of transactions in the Foreign Exchange (FX,
[10]) market - where the world’s currencies trade - have been performed by robots (see
the white paper by the US Commodity Futures Trading Commission [11]). This
phenomenon has increasingly become a central factor in the management of market
fluctuations. The players involved are users, brokers and financial institutions. Users
are anyone who wants to invest. The brokers are responsible for buying the quotations
of some assets and making them available to users. An asset is intended as each thing,
material or immaterial, likely to be evaluated. In the FX market, for instance, an asset is
any currency that can be traded. The financial institutions provide the payments and the
prices of the various assets.

© Springer Nature Switzerland AG 2019


T. Antipova and A. Rocha (Eds.): DSIC 2018, AISC 850, pp. 254–261, 2019.
https://doi.org/10.1007/978-3-030-02351-5_30
Optimizing Automated Trading Systems 255

Fig. 1. Japanese candle definition (left). A possible sequence of candles (right).

Over each asset there are different ways to invest, here we consider the Binary
Options [9, 16]. This is a very young and particular market where who invests does not
buy or sell a contract of an asset, but rather bets on the fluctuations that will occur. The
bets can be CALL or PUT: within a fixed time, CALL (PUT) means that one bets on the
price to increase (decrease). After the bet is placed, one has to wait the fixed amount of
time in order to achieve a gain or a loss. The success of a Binary Option is thus based
on a YES/NO proposition, hence binary. If the bet is successful then the gain is given
by a certain percentage called payout; otherwise the entire investment is lost. Actually,
also nil trades can occur when the price remains unchanged. The payout is not fixed,
but might vary during the price fluctuations. It depends on various factors: the current
volume of trading; the time of the day; the type of betting (1 min, 3 min, 5 min,
30 min). However, the payout variations are closely related to the broker by which one
operates. Reasonable values for the payout are on average around 70%–80%. There are
plenty of strategies [4, 6, 12] to try to predict fluctuations, that have been studied and
experimented. Some are based on the Fundamental Analysis [7], that measures the
quality and the potential growth of a company/asset. However, from the computer
science point of view, more interesting is the Technical Analysis [15, 17] that aims to
predict fluctuations on the basis of historical behaviors. The main rule that governs the
markets is that to some extent history repeats. Starting from a well-known strategy (by
economists), we show how algorithmic optimization can be effective.

2 Notations and Terminology

In this section, we introduce some essential financial resources that we need in order to
describe the trading strategy. The technical analysis is mainly based on bar charts, here
we consider the so-called Japanese candles [14], see Fig. 1.
Given a generic asset A, candles are formed observing the fluctuation of A within a
fixed time period t = [t1, t2]. A candle is defined by four prices: opening (price at time
t1), closure (price at time t2), maximum (maximum price reached in the interval) and
minimum (minimum price reached in the interval). If a candle satisfies the condition
opening < closure (closure < opening) then it is named a bull (bear) candle. We
represent a bull (bear) candle in white (black), a nil candle has no body. A sequence of
white (black) candles is named a bullish (bearish) trend. Figure 1 (right) shows a bar
256 A. Bigiotti and A. Navarra

chart as a sequence of candles. In the example we suppose the time period defining
candle i + 1 has not yet terminated. All candles before i + 1 compose the set X. In
order to obtain forecasts on candle i + 1 we may refer to n candles Xi, suffix of X, for
some constant n. Each candle xi in Xi is identified by a vector with the four prices that
define the candle itself: opening, closure, maximum, minimum. These prices are used
by particular functions, named indicators and oscillators, to forecast fluctuations of the
chosen asset A.

3 Trading Systems

In general, strategies differ between those that follow the current trend (bearish or
bullish), or those that operate counter the current trend. Both approaches make use of
indicators and oscillators. Leaving aside the financial aspects and focusing on the
mathematical ones, we can see indicators and oscillators as particular functions with
several variables defined on the price fluctuations. Indicators aim is to predict the future
trend of the prices. Oscillators are an important category of indicators. Their aim is to
detect points of excess of bearish or bullish, or the weakening of the current trend. They
are named oscillator because their value oscillates between a fixed range. Generally, the
domain of these functions is a price in the set Xi, instead the codomain of these
functions is closely related to the particular indicator or oscillator. In this section, we
need to introduce an indicator and an oscillator that will be used in the strategy we
design for Binary Options. The known strategy presented, is based on the Bollinger
Bands (BB, see [5]) indicator, and on the Relative Strength Index (RSI, see [13])
oscillator.
Bollinger Bands (BB). This indicator provides the calculation of a simple moving
average (SMA) and of two standard deviations r+ and r− from the SMA. We formalize
the indicator as a function: BBfp;wg ðXi Þ :¼ fmai ; ri þ ; ri g, where: i is the index of the
last candle of a bar chart one refers to; p = |Xi| is the period for the moving average
calculation, generally 20 candles; w is a factor for the calculation of the standard
deviations, generally 2. The domain of the indicator is the set of closure prices cj of the
candles xi in Xi, the codomain is a vector fmai ; ri þ ; ri g, where: mai is the moving
average relative to the i-th candle; ri þ :¼ mai þ ðw  ri Þ; ri :¼ mai  ðw  ri Þ, and ri
is the square root of the fraction between the squared differences of the closing prices of
candles j and i, with j = i, …, i − p, and p −1. The idea behind BB is: if the closure
price of the last candle goes over ri þ or under ri , then the market will get in a tense
situation, from which it should reverse the current trend.
Relative Strength Index (RSI). This oscillator provides the calculation of two
moving averages over the differences between the opening and the closure prices of a
given set of bearish candles Xb, and bullish candles Xw. We could formalize the
oscillator as a function RSIfp;os;obg ðXw [ Xb Þ ¼ si , where: i is the index of the last
candle of a bar chart one refers to; Xw and Xb are two sets of the same cardinality of
white and black candles, respectively, before candle xi+1; p = |Xb| = |Xw|: is the period
for the moving average calculation, generally 14 candles; os is the so-called over-sold
Optimizing Automated Trading Systems 257

limit, that is a bound for considering the current trend dictated by ‘too many’ selling
operations; ob is the so-called over-bought limit, that is a bound for considering the
current trend dictated by ‘too many’ buying operations. The domain of the oscillator is
the difference between opening and closure prices of the candles in the sets Xw and Xb,
the codomain is a value si ranging in [0, 100]. Value si is the result of the calculus
100 − (100/(1 + RS)), and RS : ¼ mi þ =mi ; where: mi þ is the moving average of the
absolute value of the difference from opening and closure prices of the last p white
candles, xj in Xw; mi is the moving average of the difference from opening and closure
prices of the last p black candles, xj in Xb. Finally, we need to fix the over-sold and
over-bought limits, generally 30 and 70, respectively. The idea behind RSI is: if the
oscillator breaks over (under) the over-bought (over-sold) limit, then the market should
reverse the current trend.

3.1 BB-RSI Strategy


Algorithm 1 shows the pseudo-code of the strategy we consider for our optimization
intents. At the beginning (Lines 1–3) we need to set some parameters that will be used
by the algorithm. These settings will condition the behavior of the strategy, and our
purpose is to check if it is possible to discover some optimal configurations to enhance
the strategy performance. In Line 1 we set the asset A and the candles time t. In Line 2,
we set the parameters for the BB indicator and the RSI oscillator. In Line 3 we set the
amount bi to invest, and the expire time te of the investment (i.e. the time during which
the order remains on the market). The indicator and oscillator settings will determine
the number of operations that the strategy could make. Lines 4–13 implement the
reversal strategy. The While cycle at Line 4 can run ‘forever’. The While cycle at Line
5 is executed until a new candle is ready. In Lines 6–7, the BB and RSI values are
calculated, respectively. Lines 8 and 11 are devoted to check ‘when send the signal for
the PUT or the CALL orders, respectively.
258 A. Bigiotti and A. Navarra

The If control at Line 8 checks if the price of the closure of a candle (xi) is over the
upper standard deviation (ri þ ), that is a tense situation. The If control in Line 11 checks
if the price of the closure of a candle (xi) is under the lower standard deviation (ri ),
that is another tense situation. Lines 9 and 12 are devoted to a confirmation for the PUT
or the CALL signals, respectively. The If control in Line 9 checks if the value (si) of the
RSI is over the over-bought limit (ob), this is used as a confirmation of the PUT signal
sent by the engine. Similarly, as a confirmation of the CALL signal, there is the If
control in Line 12. Lines 10 and 13 are designed to send an order; result will contain
the outcome of the operation, after the expire time te.

3.2 Evaluation Parameters for a Trading System


In the evaluation of a trading system we are interested in the profitability of the
strategy. This is a central factor, but other parameters must be considered. Let n =
w + l + nil be the sum of winning, losing, and null trades, respectively.
Net Profit (NP): indicates the profit accrued by the strategy. Suppose that each trade
can gain g" or lose g#. As in Binary Options we can assume g" and g# as constants, the
net profit is given by NP:= (w  g") − (l  g#);
Max Draw Down (MDD): indicates the maximal loss of the strategy. Given an initial
balance b1, if the set B ={b1, b2,…, bn} maintains the evolution of the balance during
the strategy execution, then we need to calculate MDD :¼ fmaxbi ;bj in Bðbi  bj Þ
jbi [ bj ; i \ jg;
Profit Factor (PF): indicates the risk of the strategy. It is expressed by the ratio
between the average of the gains and the average of the losses. Since in Binary Options
we assume g" and g# as constants, PF: = (w  g")/(l  g#);
Winning (W%) and Losing (L%): these parameters are strictly related to Binary
Options. W% and L% are simply given by w/n and l/n, respectively.

4 Test and Optimization

Our purpose is to enhance the performance of the strategy provided by Algorithm 1 by


means of optimization issues. In particular, considering W% or L%, we look for
suitable settings of the indicator and oscillator variables. Maximizing W% (or similarly
minimizing L%) may provide reasonable thresholds for judging the strategy as prof-
itable. During our tests we make the following assumptions:
(i) Average Payout (p~a ): suppose an ideal broker pays the trades with some different
payouts p1, p2, …, pk that vary during the fluctuations. We could consider as
weights the frequencies of the payouts w1, w2, …, wk. So the average payout is a
good approximation of the payout;
(ii) Breakeven Level: there is a relation between the average payout p~a and the number
of the winning trades w. With an investment i, each winning (losing) trade pro-
duces a gain g" ¼ i~a (a loss g# = i). To find the minimum level for which the
Optimizing Automated Trading Systems 259

strategy is profitable, we need to guarantee w  g" − l  g# > 0. If p~a ¼ 75%, we


obtain $ (w  i  75/100) − (l  i) > 0, that holds for W% > 0.571.
The testing phase is a simulation of the strategy over a given historical period. We
formalize the test as SfHg ðBBfp;wg ; RSIfp0 ;os;obg Þ ¼ d, where: S is a simulation function,
H is the historical data period ðBBfp;wg ; RSIfp0 ;os;obg Þ are the indicator and the oscillator
used by the strategy, d is an evaluation parameter. The optimization process can be
seen as a system of simulations O(BB, RSI), in which we fix the asset A, the time for the
candles formation t and the historical data period H; then we iteratively execute the
strategy tuning the involved variables. Each simulation SifHg in the system O(BB, RSI)
produces a different di that as first approximation relates to W%. Each execution of the
system generates a set of configurations of type ci ¼ fðpi ; wi Þ; ðpi 0; osi ; obi Þg, con-
cerning BB and RSI settings. Now we are interested in the elements ci maximizing W
%. Note that the search space of the system O(BB, RSI) is rather extensive. Each
variable involved by the strategy varies in a bounded interval. Suppose that p in P, w in
W, p′ in P′, os in OS, ob in OB, then the number of simulations in the system are
exhaustively given by: |P|  |W|  |P′|  |OS|  |OB|. If more indicators or oscillators are
introduced, the behavior can become drastically expensive. Moreover, the larger is
H the more trustable are the obtained results. A period H of 5 years is reasonably
extended. However, not only we want to be profitable along the whole period H, but we
aim to gain each year composing H.
To overcome all such requirements, we proceed in two phases. First we choose
H = {h1: 2013, h2: 2014, h3: 2015, h4: 2016, h5: 2017}. We consider each year hi,
instead of the entire period H. In this way, the execution of O(BB, RSI) is faster and we
obtain a differentiation about the tested configurations. In particular, we obtain a set
CH :¼ fCh1 ; Ch2 ; Ch3 ; Ch4 ; Ch5 g. Each element cj: = {(p, w)i, (p′, os, ob)i} contained in
a generic Chi is a configuration produced by the optimization for the i-th year. In the
second phase, we look for configurations with ‘good’ performances for the entire
period H. To this respect we select from each Chi , the best elements cj that satisfy two
properties during H:
– P1 (Over Breakeven): cj must be profitable, that is g" − g# > 0;
– P2 (Irrelevant Gains): the number of trades must be greater than some fixed
parameter x to guarantee that the gain of cj is relevant.
On each configuration satisfying P1 and P2 we execute a final simulation by
considering the entire period H, and as evaluation parameters {NP, MDD}.

5 Experimental Results

In this section, we experimentally show how our optimization can enhance the per-
formance of the BB-RSI strategy over extended historical data. Also, we provide the
effectiveness of our results, showing the performance of our optimized strategy on a
real time trade system, currently operating. Tests on historical data are made on an in
intel core i7-5500U @ 2.4 GHz with 4 GB DDR3, Windows 10 Education x64.
260 A. Bigiotti and A. Navarra

Table 1. Best settings achieved for the entire period H.


Period p w p′ os ob
h1: {19–26, 32, 33, 35, 40, 41} {2.0–2.5} {18–20} {25–27} {69–75}
2013
h2: {25, 30, 31, 34, 36–38, 40, {1.8–2.5} {17–20} {25–28} {72–75}
2014 41, 47, 50}
h3: {10, 15, 26–29, 30, 33, 36, {1.3, 1.9– {16–20} {25–28} {70–75}
2015 50} 2.5}
h4: {22, 25, 38–41, 45, 47} {2.0–2.5} {17–20} {27–30} {72–75}
2016
h5: {18, 19, 24, 25, 28, 30, 33, {1.9–2.5} {19, 20} {25–28} {72–75}
2017 35, 48, 49}

Table 2. Restrictions on ranges for the involved variables headings.


Configuration ci : ¼ fðp; wÞ; ðp0; os; obÞg NP $ MDD $ # trades W%
c1 = {(39, 2.2), (17, 27, 73)} 68275 2975 14180 59.89
c2 = {(31, 2.3), (18, 28, 74)} 56950 3575 10753 60.16

The software used is Meta Trader 4 [2]; Algorithm 1 was implemented in Meta
Quotes Language 4 (MQL4, see [1]). We execute O(BB, RSI) on the last five years H,
considering the asset A = EUR/USD (the price of euros in US dollars) and t = 1 min for
the candles formation. The variables involved by the strategy vary in the following
discrete intervals: p in [10, 50], w in [0.3, 2.6], p′ in [5, 20], os in [25, 35], ob in [65, 75].
The interpretation of the data is based on an initial balance of 1000 $, an average
payout p~a of 75%, and an investment of 100 $ for each bet. The optimized configu-
rations obtained by the first step of our approach provide the restricted ranges for the
involved variables shown in Table 1. The outcome is shown in Table 2 along with the
number of trades performed. The best setting is thus c1 where NP is maximized and
MDD is minimized, even though W% is slightly smaller than that achieved in c2. In

Fig. 2. Balance evolution in the period 2 January–15 June 2018 of the BB-RSI strategy under
configuration c1, starting with 1000 $ and bets of 100 $ each.
Optimizing Automated Trading Systems 261

Fig. 2 we show the effectiveness of our approach by reporting the balance evolution of
a real-time trading system currently operating on the basis of c1.

6 Conclusion and Future Work

We have shown how optimization issues are effective for the setup of a trading system for
Binary Options. It might be reasonable to think about other markets and/or other assets
for which multi-criteria optimization is required. Other approaches and methodologies
could be applied to further enhance the behavior of a strategy or to provide completely
new strategies. For instance, we are thinking about applying martingale approaches [3]
that could be effective in Binary Options due to the relation of such a market with
gambling. Other emerging markets require deep investigations. An example is about
crypto-currencies [8], even though the lack of historical data might be critical.

Acknowledgments. Special thanks go to Simone Ciancone for his expertise and useful dis-
cussions. The work has been supported in part by the GNCS-INdAM project 2018 “Anti-Social
Networks”.

References
1. mql4 documentation. https://docs.mql4.com
2. mt4. https://www.metatrader4.com/en
3. Le Gall, J.: Brownian Motion, Martingales, and Stochastic Calculus. Graduate Texts in
Mathematics. Springer, New York (2016)
4. Aldridge, I.: High-Frequency Trading: A practical Guide to Algorithmic Strategies and
Trading System. Wiley Trading Series. Wiley, New York (2013)
5. Bollinger, J.: Bollinger on Bollinger Bands. McGraw-Hill Education, New York (2001)
6. Bonenkamp, U.: Combining Technical and Fundamental Trading Strategies. Gabler Verlag,
Wiesbaden (2010)
7. Bulkowsk, T.: Fundamental Analysis and Position Trading: Evolution of a Trader. Wiley,
New York (2013)
8. Clarkson, M.: Cryptocurrency: Best Strategies for Investing and Profiting from Cryptocur-
rency. CreateSpace Independent Publishing Platform (2018)
9. Coulling, A.: Binary Options Unmasked. Anna Coulling (2015)
10. Guy, D.: Forex Trading Money Management System. Roulette Trader (2016)
11. Haynes, R., Roberts, J.: Automated Trading in Futures Markets Update (2017)
12. Laamb, D.: Automated Trading Strategies by Example. Philip Lim (2017)
13. Perchanok, K., Hrytsyuk, I.: The Encyclopedia of the Indicator RSI (Relative Strength
Index). CreateSpace Independent Publishing Platform (2011)
14. Person, J.: Candlestick and Pivot Point Trading Triggers. Wiley Trading Series. Wiley, New
York (2018)
15. Pring, M.: Study Guide for Technical Analysis Explained. McGraw-Hill, New York (2002)
16. Schwager, J.: A Complete Guide to the Future Markets. Wiley Trading Series. Wiley, New
York (2017)
17. Stevens, L.: Essential Technical Analysis: Tools and Techniques to Spot Market Trends.
Wiley Trading Series. Wiley, New York (2002)

You might also like