SciELO - Scientific Electronic Library Online

 
vol.14 número4Rendimiento y volatilidades de los mercados mexicanos bursátil y cambiarioComparación de los costos de los sistemas de beneficio definido y de contribución definida bajo una metodología actuarial índice de autoresíndice de materiabúsqueda de artículos
Home Pagelista alfabética de revistas  

Servicios Personalizados

Revista

Articulo

Indicadores

Links relacionados

  • No hay artículos similaresSimilares en SciELO

Compartir


Revista mexicana de economía y finanzas

versión On-line ISSN 2448-6795versión impresa ISSN 1665-5346

Rev. mex. econ. finanz vol.14 no.4 México oct./dic. 2019  Epub 21-Feb-2020

https://doi.org/10.21919/remef.v14i4.435 

Artículos de investigación

Huelum Trading System: A Low-Frequency Algorithm Proposal

Sistema de trading Huelum: una propuesta de algoritmo de baja frecuencia

Ana Lorena Jiménez Preciado1  *  **
http://orcid.org/0000-0001-9158-0685

Salvador Cruz Aké1 
http://orcid.org/0000-0003-1452-377X

César Gurrola Ríos2 
http://orcid.org/0000-0001-5806-4670

1Instituto Politécnico Nacional, México

2Universidad Juárez del Estado de Durango, México


Abstract

This paper aims to build a set of algorithmic trading strategies to capture the persistence of financial series. HUELUM Trading System is proposed to make algorithmic trading in a low-frequency environment and is tested with the Exchange Traded Fund (ETF) iShares NAFTRAC daily prices. HUELUM Trading System includes one mean and one trend technical analysis indicators which are compared to a buy & hold strategy as a benchmark. The principal contribution of this work is that HUELUM Trading System can adapt to NAFTRAC, capturing its behavior, trends, and persistence or momentum. HUELUM is validated through a rolling walk forward and works with any security as long as it has Open, High Low Close (OHLC) prices. When we are ina market with little liquidity and deepness, HUELUM gives accurate buy and sell signals compared to a buy & hold strategy and reduces potential equity losses.

Keywords: algorithmic trading; low-frequency; technical analysis; HUELUM Trading System

JEL Classification: G10; G12; G14

Resumen

El objetivo del presente trabajo es construir un conjunto de estrategias de trading para capturar la persistencia y memoria de series financieras. Se propone un sistema de trading de baja frecuencia llamado HUELUM, mismo que es probado con el Exchange Traded Fund (EFT) iShares NAFTRAC para precios diarios. La principal contribución de este trabajo es que el sistema de trading HUELUM tiene la capacidad de adaptarse al NAFTRAC, capturando su comportamiento, tendencia y persistencia. El sistema HUELUM es validado a través de un análisis de ventanas móviles, además de que funciona con cualquier activo financiero que registre precios de tipo apertura, máximo, mínimo y cierre (OHLC, por sus siglas en inglés). Cuando nos encontramos en un mercado con poca liquidez y profundidad, HUELUM proporciona señales precisas de compra y venta comparada con una estrategia de buy & hold, asimismo, el sistema de trading propuesto permite la cobertura ante potenciales pérdidas de inversión.

Keywords: entrepreneurship; global innovation index; human talent; search and matching with frictions

JEL Classification: J01; J23; J24; M51; O31

1. Introduction

Algorithmic trading4 is used to whether to find a top or bottom trends for shares, more specifically, investors who rely on algorithmic ttrading use quantitative and technical analysis tools to determine strategies for trade. Algorithmic trading consists of analyzing stock prices through technical charts and mathematical tools that represent open, high, low, and close prices.

Algorithmic trading seeks to detect and predict patterns in security prices; in this regard, many attempts and methodologies have been developed. This field has numerous investigations to apply techniques such as genetic algorithm (Chien-Feng, Hsu, Chi-Chung, Chang, & Chen-An, 2015), (Ying-Hua & Ming-Sheng, 2017), machine learning (Stanković, Marković, & Stojanović, 2015), (Dias-Paivaa, Nogueira-Cardoso, Peixoto-Hanaoka, & Moreira-Duarte, 2019), Bayesian models (Bian-Du & Jingdong, 2016),fuzzy time series (Gradojevic & Gençay, 2013), high frequency (Menkveld, 2013), (Hasbrouck & Saar, 2013), (Hagströmer & Nordén, 2013), technical trading rules (Bajgrowicz & Scaillet, 2012), (Kuang, Schröder, & Wang, 2014) and the development of new tools for technical analysis.

Most of the techniques mentioned apply trading algorithms that in the field of finance represents an environment where computer programs, statistical software and the developing of languages and tools, based on trading rules, are built anytime and anywhere in the world. Algorithmic trading is used for any securities since currencies, commodities, assets, or stocks. There are two types of algo-trading: 1) high-frequency trading where the trader’s advantage is in the speed of the connection and 2) low-frequency trading where the gain is in the trading model. From amateur to institutional investors who want to buy and sell such securities and get a profit (Manahov, Hudson, & Gebka, 2014).

Even though the bases of trading are quite simple -buy low and sell high- the complication is how much to buy or sell and when (Escobar, Moreno, & Múnera, 2013). Since the financial market, as a complex system, involves a high number of interacting participants to maximize profits. However, financial markets are influenced by other factors such as politics, culture, and even macroeconomics news (Lan, Zhang, & Xiong, 2011), (Escobar et al., 2013) and (Scholtus, Van Dijk, & Frijns, 2014).

Although financial markets represent a complex system, this does not mean that it is an entirely random and unpredictable system (Lan et al., 2011). Unlike the researches mentioned, it is considered that focusing on persistence and memory of patterns could lead us to build a solid strategy for trading. The motivation is not only to gain the maximum profit; the essential idea is to provide a tool that allows capturing persistence, memory, and the cyclical behavior of the financial series5. It is anticipated that prices of securities that are considered for the study could not present a random walk process since prices are hardly independent or identically distributed -at least in the financial environment-.

However, when considering a market with semi-strong efficiency where price formation is represented by the expectation of historical returns, coupled with available public information, prices can be "read" with the use of algorithms, allowing us to understand and even anticipate (at least partially) the prices and behavior without claiming that the market is efficient in the sense as is defined by the Efficient Market Theory (EMH) according to (Fama, 1969).

The basis of the algorithm for this study focuses on the use of a low-frequency model. The strategy does not depend on the speed or computing capacity of the hardware or software, in this case, the low-frequency model is formed by information retrieved from fundamentals, macroeconomic news, and financial analysts as well as strategies based on statistical and mathematical models and technical analysis which focuses on price trends and momentum (Harris & Yilmaz, 2009) and (Serban, 2010).

Under the hypothesis of whether securities show repetitive behaviors, algorithmic trading allows capturing its memory and persistence. This investigation aims to build a set of algorithmic trading strategies to capture persistence and memory of financial series. The main objectives are 1) to build an algorithmic trading strategy based on a low-frequency algorithmic trading model for daily frequency assets in a semi-strong environment and 2) to make an evaluation and optimization of the algorithmic trading strategy with a walk forward cross-validation.

HUELUM6trading System is proposed, and it is tested with (ETF) iShares NAFTRAC daily prices (ticker: NAFTRACISHRS.MX) which replicates the behavior of the Índice de Precios y Cotizaciones (IPC) in 99%, and it is the most traded ETF in México. The evaluation of the algorithm focuses on one natural calendar year from January 2nd, 2018 to December 31st, 2018: 252 observations.

Unlike other algorithms that are used to find buy and sell signals and despite of the furor of high frequency algorithms that dominate the market through their famous robot advisors and all the plentiful techniques’ applied to algorithm trading, HUELUM Trading System is built in a low-frequency environment, attending the problem of low deepness and liquidity exhibited by securities with low marketability. Likewise, HUELUM can adapt to any security as long as it has Open, High Low Close (OHLC) prices.

The document is divided as follows: the next section concentrates on the theoretical base of the study, which is the EMH Theory. The third part gives an overview of chart pattern recognition with technical analysis and Dow Theory besides the description of the tools that will be implemented. The fourth section introduces the trading System with the low-frequency model name as HUELUM. In the last part, the low-frequency trading System is optimized and tested with a walk forward cross-validation. Finally, the findings and conclusions of the study are presented.

2. Algorithmic trading on Efficiency Market Theory

Since (Fama, 1969) publication where is formally proposed the Efficient Market Hypothesis (EMH), thousands of articles have been written either to confront or provide evidence that denies/accept this hypothesis. Despite this, it has been nearly 50 years of his study and that there have been achieving in statistical, econometrics and theoretical models and even though the growing quality and quantity of financial data, as (Sewell, 2012) points out, yet and surprisingly, there is no consensus about whether a market is efficient or not.

As (Fama, 1969) defines, we can assume that a market7 is efficient if prices always “fully reflect” all available information meaning that security’s current price is equal to its fundamental value or intrinsic value. To prove efficiency, it is necessary to specify the price formation process. Using (Fama, 1969) notation:

E(p˜j,t+1|Φt)=[1+E(r˜j,t+1|Φt)]pjt (1)

Where E corresponds to the expected value, the price of a particular financial asset at the time t is pjt and for t+1 is p˜j,t+1 ;rj,t+1 represents the percentage return (pj,t+1pjt)/pj,t+1 and finally Φt is a set of information and it is assumed to be fully reflected in the price. Another assumption is that prices and returns are random variables. In the end, E(r˜j,t+1|Φt) displays the value of the equilibrium expected return from the information provided by the set Φt . It does not matter which is the expected value, information given by Φt is totally or fully used for shaping equilibrium expected returns (Fama, 1969).

Following EMH, we can distinguish among three types of market efficiency: weak, semi-strong, and strong. The first one refers to a set of information that only includes history prices; semi-strong efficiency is, in addition to history prices, the readiness of public information (e.g., annual reports, utilities, and even macroeconomics news) and the strong way means the sum of semi-strong plus private information (such as monopolistic access to relevant information about prices).

At this point, it is worth noting to highlight, which are the conditions under a market could be efficient. According to (Fama, 1969), sufficient conditions for market efficiency are:

  1. It is assumed that there are no transactions costs8 when trading securities in the market.

  2. Information is free and available for all market agents.

  3. The expectative and implications of current information are thought-out and evaluated in the same way for all the market’s participants9. Hence the distributions of future security prices are known.

However, the assumptions of the theory mentioned before are restrictive, causing several criticisms and arguments against EMH. It is worth nothing to highlight some of these criticisms to explain why assuming a market in its semi-strong way allows us to approach the concept of animal spirits which includes the psychology of the traders when buying and selling securities.

2.1 Animal spirits in a semi-strong efficient market

There are plenty of publications that worn out about the failure of the EMH, but undoubtedly professor Robert Shiller is widely known for his studies that disagree with EMH theory. Part of their arguments relates to the behavior of human beings when making decisions, in other words, to what Keynes referred to as “animal spirits.”

When EMH was published in 1970, coincides with the domain of the rational expectations theory. Among the models that stood out in the financial area in 70’s -including EMH- were (Merton, 1973) whit an intertemporal general equilibrium model best known and currently widely used as Capital Asset Pricing Model (CAPM), the rational expectations general equilibrium (Lucas, 1978) which is an analysis of the stochastic behavior of equilibrium asset prices in pure exchange economy with identical consumers and one-good as well as the extension of Merton’s model published by (Breeden, 1979) where a beta of stock allows to measure the sensibility of a stock return compared to some index.

However, it was in the eighties when the boom of rational expectations started to crash down and mainly of this, at least in the financial area was because stocks began to show excess volatile behavior compared to what EMH predicted, and fundamentals changes could not explain this but for animal spirits (Shiller, 2003). In this sense, it is hardly assumed that economic agents are rational. As has been shown, in the real world, it is not possible to stand out no transactions cost and fully available information. Likewise, it is very pretentious to assume that all economic agents process the data in the same way, so we cannot expect the distributions of future securities.

Even though the criticism of EMH, if a market with semi-strong efficiency is considered as an assumption where price formation is represented by the expectation of historical returns coupled with available public information, prices can be "read" with theuse of algorithms allowing us to understand and even anticipate (at least partially) to prices behavior without claiming that the market is efficient in the sense as is defined by the EMH.

In algorithmic trading, strategy frequencies are the cornerstone before even the design of the algorithm per se, depending on the frequency of frame with which the financial asset is moving, strategies change. Frequencies for trading are: low, high, and ultrahigh (Lee & Seo, 2017).

  1. Low-frequency trading: is done with inter day transaction regularity.

  2. High-frequency trading: is done with intraday transaction regularity up to the minute.

  3. Ultra-high frequency: is done with intraday transaction regularity up to the second or millisecond.

The discussion about whether a low, high or ultra-high frequency trading is the best choice to take profit in financial markets leads us to those who consider that high-frequency trading manipulates and modifies assets’ prices and market’s liquidity (Menkveld, 2013). For example, (Jacob, Napoletano, Roventini, & Fagiolo, 2016) examine the dynamic between low and high-frequency traders through an agent-based model concluding that both postures lead to flash crashes, the authors even point that high-frequency trading can be potentially harmful to financial markets stability.

Likewise, (Li, Cooper, & Vliet, 2017) point out that high frequency leads volume in financial markets but still is not clear how high frequency affect low-frequency trading. The found out that high-frequency activity improves liquidity and orderexecution quality, as well as likelihoods executions for low-frequency positions, which is a similar result from (Brogaard, et al, 2018) proving the stability of liquidity supply by high-frequency traders.

While is true that the literature of trading focuses on high-frequency and its impact on financial markets and even on low-frequency traders, these studies tend to use liquidy markets or assets, taking samples of NASDAQ or S&P500 index but what happens when there is a problem of low deepness and liquidity exhibited by securities with low marketability. The basis of the algorithm for this study focuses on the use of a low-frequency model. The strategy does not depend on the speed or computing capacity of a hardware or software; in this case, the low-frequency model is formed by:

  1. Information retrieved from fundamentals, macroeconomic news, and financial analysts.

  2. Strategies based on statistical and mathematical models.

  3. Technical analysis which focuses on price trends and momentum.

It should be noted that the low-frequency model, which is proposed in Section 4, it is based on technical analysis, assuming semi-strong efficiency, transactions cost and “animal spirits” that are known as noise traders10 in EMH terms. Next section explains the nature of technicalanalysis and the mean and trend indicators that will be used for the trading System proposal.

3. Technical Analysis Chart Pattern for Securities trading

Recall the concept of noise traders or irrational traders (those who are guided by animal spirits). Empirical evidence has shown that security prices may not be as independent as they presume (Forecasts, 2015). The way that noise traders and informed traders take their decisions influence market behavior and one of the most important approaches that analyze the changes in financial markets through prices (whether an asset is bought or sold) is Dow Theory.

Dow Theory arose from a series of articles published by Charles Dow between 1900 to 1902 in The Wall Street Journal. This methodology focuses on the utilization of long term tendencies in the stock market as a measure of whether an asset goes up or down (Brown, Goetzmann, & Kumar, 1998).

The cornerstone of the Dow Theory is that the stock market can be analyzed based on three kinds of trends: primary trend, secondary trend, and daily fluctuations. First, the prior trend is identified, although its duration and length are unpredictable, the Dow Theory and technical analysis as well make it more likely to anticipate a switch in trend. Secondary trend corrects prior tendencies; if the primary trend is bearish (downtrend), the secondary trend is called rallies. Otherwise, when the prior trendis bullish (uptrend), the secondary trend is named as corrections. Finally, daily fluctuations focus on closing averages, and they are useful for determinate long or short positions for traders. Figure 1 shows an example of a trend Theory by Charles Dow whit NAFTRAC.

Source: Own elaboration in R programming language based on “quantstrat” and “blotter” packages.

Figure 1 Dow Theory for NAFTRAC 2018-05 to 2018-12  

Figure 1 shows a downtrend from June 2018 to the beginning of September 2018 but notices that there are corrections in each month of the period, after that in the middle of October a bearish trend started until December 2018 with rallies each month either. Dow Theory focuses on trend analysis of securities prices; for that reason, the use of graphs is vital to identify the market behavior that an asset follows, this is when technical analysis becomes quite useful, despite the questioning and enigma represented by this tool (Kuang et al., 2014).

Technical analysis focuses on pattern formation trough Japanese candlesticks and a universe of trading rules, which includes the use of indicators, oscillators, and even geometrical figures. Japanese candlesticks represent the open, high, low, and close (OHLC) prices of an asset. It should be noted that technical analysis is a short-term analysis and that the candlestick represents the synthesis of the prices mentioned above. As from the position of the prices, candlesticks can be bullish or bearish; high and low prices represent the tails or shadows of the body of the candle as can be seen in figure 2:

Source: Adaptation of (Mcdonald M. , 2002).

Figure 2 Japanese candlesticks formation  

First green candle of figure 2 refers to a bull figure; this formation occurs when the close price is higher than the open price of the asset, likewise, is related to bulls because the way that they attack is with the horns (upwards). In the other hand, there is a bear figure, and this formation is done when the open price is greater than the close price and is referred to bears because these creatures attack downwards with their claws. Both bullish and bearish candles have shadows or tails; upper/lower shadows represent the distance between open/close prices and high/low prices. For this reason, it is crucial to have OHLC prices for candlesticks formation11.

From the combination of prices, different candles can be formed with both: bulls and bearers. Figure 3 shows a general classification of Japanese candlesticks that arose from the combination of those prices. The first candle (1) of figure 3 presents a biggreen body with small tails; it represents a confirmation signal of a bullish trend. The second candle (2) has the same meaning but for a downtrend. The candles numbered as 3 (short tails and bodies) suggest a hold position where neither buyers and sellers pressure the market. These candles are associated with uncertainty, and they are named as dojis12. Candles numbered 4, and 5 (long tails and small bodies) represent a trend reversal signal, both green candles are called as a hammer and inverted hammer respectively, and red candles are known as hanging man and shooting star. Finally, candles numbered as 6 (long tails and small bodies) indicate domain by buyers or sellers during the trading session. In the end, the open and close prices are relatively close, showing a sign of uncertainty in the market.

Source: Adaptation of (Mcdonald, 2002).

Figure 3 Patterns from Candlestick analysis  

3.1 trading strategy with trend and mean indicators

The main categories for the implementation of trading strategies, at least for this proposal, are trend following and mean reversion. These strategies try to identify asset price uptrend, downtrends, and their momentum, which is the tendency of raising or falling prices to keep doing so. While is true that we can find plenty of technical indicators, for this study it will be described those that are implemented in the low-frequency algorithmic trading model proposed which are Simple Moving Average (SMA) for trend following and Bollinger Bands (BB) for mean reversion indicators.

3.1.1 Trend following indicator: Simple Moving Average (SMA)

Overall, moving averages are one of the most used and straightforward technical indicators but powerful if it is well implemented. A Simple Moving Average (SMA) is a smoothing of a time series, this case, of a security price which calculates the average of closing prices in a certain period (minutes, hours, days, weeks and so on) and is a versatile tool because SMA moves forward in time (Droke, 2001). An SMA is calculated as follow:

SMAn=nClosen (2)

Where n refers to the number of observations considerate from a given period. The selection of the days for the construction of the SMA helps to capture different trend frames; as the SMA increases, the smoother the series became. According to (Droke, 2001), there are many moving averages combinations, but at the end, it is about combining fast and slow moving averages to identify crossovers, this is bull and bear signals.

Table 1 Trend frame from smoothing days for moving averages  

Trend Moving Average
Very short term 5-13 days
Short term 14-25 days
Medium term 26-49 days
Medium-long term 50-100 days
Long term 100-200 days

Source: Own elaboration based on (Droke, 2001).

The way that is found a buy/sell signal is trough out the double crossover of SMA: this is when slow SMA crosses above or below a fast one. Figure 4 shows buy and sell signals trough moving averages crossovers. When the faster SMA, in this case, the 15 short average crosses below the slower SMA, this is, the 30-medium long average (the smoother), it is considered as a sell signal. Otherwise, when the faster SMA crosses above the SMA(30), then it is a buy signal. This is how SMA’s combinations become useful because, trough out its crossover, it is possible to find buy and sell signal in securities prices. However, one of the most certain challenges is to find combinations that help to detect signals in an accurately way; this is going to be possible in the Automated trading System proposed.

Source: Own elaboration in R programming language based on “quantstrat” and “blotter” packages.

Figure 4 NAFTRAC SMA(15) and SMA(30) trend strategy 2018/01 to 2018/07  

3.1.2 Mean reversion indicator: Bollinger Bands (BB)

John Bollinger created Bollinger Bands in 1992, and they are still widely used for technical analysts (Bollinger, 2002). It has the distinction of being based on the volatility of 20 days SMA and is an advisor for possible overbought and oversold areas13 (Bollinger, 1992). Its construction is shown as follows:

Middle Band=SMA20

Uper Band=SMA20+2σ20 (3)

Lower Band=SMA202σ20

Where σ is the standard deviation and represents the volatility of the financial asset, every time that σ increases, Bollinger Bands (BB) will get wider and will confirm the trend of the share but, if the closing price or candlesticks reach or jump across the upper band, then the security is overbought and when the opposite happens, this is, when the closing price or candlesticks crosses the lower band, the security is in an oversold area. Figure 5 represents this behavior.

Source: Own elaboration in R programming language based on “quantstrat” and “blotter” packages.

Figure 5 NAFTRAC Bollinger Bands(20,2) mean reversion strategy 2018/07 to 2018/12  

In figure 5 it is observed from July 2018 to October 2018 that the NAFTRAC is in a neutral or lateral trend, the upper and lower bands are relative close each which means that there is low volatility; when BB is getting wider, these are associated to morevolatility (Bollinger, 2002). Now, when candlesticks touch upper and lower bands, for example, the two candles that are slightly up at the beginning of July 2018, these candles when arising the upper band, they bounce off, in that sense, the ETF is overbought providing a possible selling signal. In the other hand, when the closing prices or the candlestick tend to break lower bands, is consider that the security is found in an oversold area, showing buy signals14 (Bollinger, 2002).

4. HUELUM Trading System

The steps for building and testing HUELUM Trading System are:

  1. Define the trading strategy with technical indicators.

  2. Add strategy signals (crossover or a threshold signal).

  3. Add enter and exit rules in market or limited positions, furthermore, stop loss, and trailing stops rules15 can be upheld.

  4. Optimize strategy parameters using different combinations.

  5. Evaluate the performance of HUELUM Trading System with:

    1. trading statistics metrics such as net trading profit and loss, gross profit/loss, percentage profitable/ unprofitable trades maximum drawdown and equity curve,

    2. trading performance metrics such as annualized return and annualized standard deviation.

  6. Make a cross-validation process with a set training taken from sample data and tested out of the sample, in this case, a Walk Forward Analysis (WFA).

  7. Compare strategy performance with the benchmark (buy and hold strategy).

4.1 The trading strategy, signals, and rules for HUELUM

The indicators used in this analysis are SMA (trend strategy) and BB (mean strategy). The first step is to build a double crossover trading signal; this is when indicators cross above/under between them.

Trend strategy with SMA, double crossover trading signals:

  • Buy signal: previous (SMAfast< SMAslow)current(SMAfast > SMAslow)

  • Sell signal: previous (SMAfast> SMAslow)current(SMAfast< SMAslow)

Mean strategy with BB, double crossover trading signals:

  • Buy signal: previous (Close>Lower Band)current(Close<Lower Band)

  • Sell signal: previous (Close<Lower Band)current(Close>Lower Band)

For the simulations, the following assumptions are considered:

  1. Our initial equity is of $10,000.00 (USD).

  2. Only market orders are allowed.

  3. There is a transaction fee of 0.25% for each trade (buy and sell).

  4. Every time that the buy signal is activated, 100 shares of NAFTRAC are bought.

  5. Every time that the sell signal is activated, all the shares of NAFTRAC are sold.

  6. NAFTRAC shares are in MXN currency. However, the results of the strategy reflect profits and losses in dollars.

  7. HUELUM Trading System focuses on the last natural calendar year: January 2nd, 2018 to December 31st, 2018: 252 observations.

4.2 Optimization of parameters for HUELUM

Parameter optimization relies on finding a set of indicators parameters able to maximize historical risk-adjusted performance. Specifically, what is going to be done is parallel computing of sets combinations to find and chose those that report more net trading profit and loss, maximum drawdown, and profit to maximum drawdown. These combinations are going to be compared with market orders. It the end, traders will be able to choose the strategies that are more convenient to its risk profile.

In the case of the SMA strategy, its optimization will involve the calculation of the historical performance of different combinations of moving average lengths using the historical sample from January 2nd, 2018 to December 31th, 2018. So, the first part of SMA’s strategy optimization is to set different combinations of low and fast SMA.

Table 2 reports combinations of fast SMA combinations from 10 to 20 with steps of five, and slow SMA has combinations from 25 to 35 with the same number of steps. Results of HUELUM optimization shows that portfolio 6 ( SMA20,30 ) is the best combination in accordance with $133.95 net P&L, the second best according to the minimum distance of maximum drawdown and the profit registered. On average, for every trade, profit is $33.49 with SMA20,30 combination.

Table 2 Optimization of parameters for SMA Strategy  

Combinations 1 2 3 4 5 6 7 8 9
Fast SMA 10 15 20 10 15 20 10 15 20
Slow SMA 25 25 25 30 30 30 35 35 35
Portfolio Port_1.1 Port_1.2 Port_1.3 Port_1.4 Port_1.5 Port_1.6 Port_1.7 Port_1.8 Port_1.9
Num Txns 9 9 13 8 10 8 8 8 6
Num Trades 4 4 6 4 5 4 4 4 3
Net trading.PL -$218.54 -$9.58 -$105.97 -$354.57 -$2.41 $133.95 -$224.93 -$76.51 -$222.16
Avg Trade PL -$54.63 -$2.24 -$17.66 -$88.64 -$0.48 $33.49 -$56.23 -$19.13 -$74.05
Max. Drawdown -$328.29 -$199.50 -$283.31 -$423.95 -$201.26 -$200.95 -$316.95 -$296.36 -$364.17
Profit. To Max. Draw -$0.67 -$0.05 -$0.37 -$0.84 -$0.01 $0.67 -$0.71 -$0.26 -$0.61
End Equity -$218.54 -$9.58 -$105.97 -$354.57 -$2.41 $133.95 -$224.93 -$76.51 -$222.16

Source: Own elaboration

Results are validated with figure 6; the most significant way to determine the best optimization parameters is choosing the lines that are at the top of each frame in figure 6.

Source: Own elaboration in R programming language based on “quantstrat” and “blotter” packages.

Figure 6 Strategy optimization of SMA with net trading, maximum drawdown, and profit to maximum Drawdown  

The same dynamic is going to be for parameter optimization for BB strategy; table 3 reports SMA combinations from 5 to 15 with steps of five and two to three standard deviations each. In this case, results of HUELUM optimization shows that the first portfolio ( BB5,2 ) is the best combination in accordance with $638.11 net P&L, but with underperformance according to the minimum distance of maximum drawdown. On average, for every trade, profit is $63.81 with 5 SMA and 2 standard deviation for BB combination.

Table 3 Optimization of parameters for BB strategy  

Combinations 1 2 3 4 5 6
SMA 5 10 15 5 10 15
Standard deviation 2 2 2 3 3 3
Portfolio Port 2.1 Port 2.2 Port 2.3 Port 2.4 Port 2.5 Port 2.6
Num Txns 36 20 13 8 3 5
Num Trades 10 3 1 4 1 1
Net trading.PL $638.11 -$2,092.59 -$3,193.71 $162.60 $45.62 -$880.13
Avg Trade PL $63.81 $79.75 -$48.17 $40.65 -$10.64 -$84.61
Max. Drawdown -$1,645.04 -$3,724.33 -$5,305.55 -$428.29 -$233.71 -$1,451.94
Profit. To Max. Draw $0.39 -$0.56 -$0.60 $0.38 $0.20 -$0.61
End Equity $638.11 -$2,092.59 -$3,193.71 $162.60 $45.62 -$880.13

Source: Own elaboration

Strategy optimization is confirmed in figure 7, recall the best optimization parameters is choosing the lines that are at the top of each frame.

Source: Own elaboration in R programming language based on “quantstrat” and “blotter” packages.

Figure 7 Strategy optimization of BB with net trading, maximum drawdown, and profit to maximum Drawdown  

4.3 Rolling walk forward analysis

The cross-validation process that is going to be used for HUELUM Trading System is a Walk Forward Analysis (WFA) which consists in optimizing indicator parameters with a set training taken from sample data and is tested out of the sample repeating the process of one step forward up to the end of data time series. According to (Pardo, 2008) the main advantage of using WFA is that optimize parameters over time, in that sense, every time that the parameters are tested out of the sample, are not the same. Figure 8 represents the essence of a WFA:

Source: retrieved from (Wiecki, 2012).

Figure 8 Walk Forward Process  

WFA allows to solve overfitting problems and is considered as a more practical method for real-time data since every time that new data is registered, is adapting to market changes. Another advantage is that is possible to know if the last optimal parameters are good enough for implement a trading strategy, if performance is not satisfactory, is likely to change to another technical indicator or to set up different parameters to be optimized. For SMA and BB indicators proposed in this work, the WFA is going to be tested with the best parameters optimization.

According to (Pardo, 2008), the size of the walk-forward window is based on data availability and data frequency. The longer the training periods, the higher the number of walk-forward, and the reliability of the WFA. Besides, a walk-forward window is proportional to the size of the optimization window. In this case, the optimal window is two months (considering slow SMA, which implies a little more than a month) and uses 10 months of training periods to perform a robust WFA. Table 4 shows the components of WFA.

Table 4 Out of sample/testing range strategy  

Training periods 10 months
Testing (out of the sample) 2 months
Parameters Combinations
SMA Trend Strategy
Fast SMA 20
Slow SMA 35
BB Mean Strategy
SMA 5
Standard Deviation 2

Source: own elaboration

For SMA strategy, the first testing out of the sample is from 26/04/2018 to 16/05/2018 where the de net trading is -$181.29, while is true that the net trading is not a positive amount, the optimal in this case is to minimize losses (same situation 09/10/2018 to 15/10/2018). In the other hand, WFA from 22/06/2018 to 29/08/2018 and 11/09/2018 to 27/09/2018 shows a profit of $345.86 and $54.81 respectively: results out of the sample for SMA are in table 5.

Table 5 Strategy Walk Forward Analysis Results for SMA(20,30)  

Out of Sample WFA Trades Net trading PL
26/04/2018 to 16/05/2018 2 -$181.29
22/06/2018 to 29/08/2018 2 $345.86
11/09/2018 to 27/09/2018 2 $54.81
09/10/2018 to 15/10/2018 2 -$85.44

Source: own elaboration

Finally, (SMA20,30) strategy WFA performance versus a buy & hold strategy16 has better results since equity (the initial amount of equty that ins invested) isabove clothe sing price of NAFTRAC and ends up with a profit. In adittion, the drawdown is less than buy & hold, this can be seen in figure 30:

Source: Own elaboration in R programming language based on “quantstrat” and “blotter” packages

Figure 9  SMA20,30 Strategy WFA performance vs. benchmark  

For BB(5,2) strategy, the first test out of the sample is from 24/01/2018 to 24/01/2018 where the de net trading is -$1193. Losses are also reported in 25/04/2018 to 08/06/2018, 03/10/2018 to 06/11/2018 and 09/11/2018 to27/12/2018, and profits are registered five times in the evaluation: results out of the sample for BB(5,2) the strategy is in table 6.

Table 6 Strategy Walk Forward Analysis Results for BB(5,2)  

Out of Sample WFA Trades Net trading PL Out of Sample WFA Trades Net trading PL
24/01/2018 to 24/01/2018 2 -$11.93 02/08/2018 to 08/08/2018 2 $65.80
09/02/2018 to 09/03/2018 4 $82.91 13/08/2018 to 28/08/2018 3 $268.64
16/03/2018 to 05/04/2018 4 $267.71 04/09/2018 to 12/09/2018 2 $11.39
25/04/2018 to 08/06/2018 5 -$182.32 03/10/2018 to 06/11/2018 6 -$288.61
16/07/2018 to 25/07/2018 2 $93.53 09/11/2018 to27/12/2018 5 -$138.65

Source: own elaboration

In the same way as SMA20,30 , strategy with BB(5,2) WFA performance versus a buy & hold strategy has better results since equity is above of the closing price of NAFTRAC and ends up with a profit. It is noteworthy that BB(5,2) behaves more volatile and the drawdown is less than buy & hold, this can be seen in figure 10:

Source: Own elaboration in R programming language based on “quantstrat” and “blotter” packages

Figure 10  BB5,2 Strategy WFA performance vs. benchmark  

Lastly, both strategies display better trading performance metrics compared with the buy and hold strategy. SMA20,30 strategy exhibits a higher annualized return of 1.31% and 1.93% with BB(5,2) strategy compared with a negative return of -16.73% registered by the buy and hold strategy. Annualized standard deviation represents a measure of volatility and risk performance, in this case, the SMA20,30 combination is less risky than the benchmark (buy and hold) but not with BB(5,2) strategy as it is presented in table 7.

Table 7 trading performance metrics  

Performance SMA Strategy BB strategy NAFTRAC Closing Price
Annualized Return 1.31% 1.93% -16.73%
Annualized Std Dev 3.44% 17.40% 16.65%

Source: own elaboration

While NAFTRAC ended up with a negative return in 2018, HUELUM can take advantage of NAFTRAC behavior optimizing the strategies presenting a profit.

5. Conclusions

Algorithmic trading is used to whether to find a top or bottom trends for share prices, more specifically, investors who rely on algorithmic trading use quantitative and technical analysis tools to determine strategies for trade. Algorithmic trading consists of analyzing stock prices through charts and mathematical tools that represent open, high, low, and close prices. In this regard, the objective of this work is to build a set of algorithmic trading strategies to capture persistence and memory of financial series, more specifically, to build an algorithmic trading strategy based on a low-frequency algorithmic trading model for daily frequency assets in a semi-strong environment.

HUELUM Trading System low-frequency model was proposed to make algorithmic trading tested with the ETF NAFTRAC daily prices which replicate the behavior of the Índice de Precios y Cotizaciones (IPC) of Mexican Stock Exchange. In this first version of HUELUM it was tested one mean indicator (Bollinger Bands), and one trend indicator (SMA) and they were compared to a benchmark, in this case, with a buy & hold strategy. Assuming initial equity of $10,000.00 (USD), technical indicators were probed to detect buying and selling signals: both, SMA and BB were tested applying different combinations and validated through a rolling walk forward analysis.

To select the best portfolio with SMA and BB combinations, we searched for parameters able to maximize historical risk-adjusted performance such as net trading, profit and loss, maximum drawdown, and profit to maximum drawdown. In the end, the best combinations were those its end equity exhibited the highest profit. Likewise, it is possible to know the number of trades and transactions of each combination as well as the average profit/loss per trade.

For NAFTRAC, the best technical indicators are SMA20,30 and BB(5,2) combinations, with $133.95 net P&L while BB(5,2) is the best mix in accordance with $638.11 net P&L. Both strategies display better trading performance metrics compared with the buy and hold strategy with a higher annualized return of 1.31% for SMA20,30 and 1.93% return for BB(5,2) . Nonetheless, BB(5,2) exhibits a higher risk due its 17.40% annualized standard deviation related to the 16.65% for buy and hold and 3.44% of SMA20,30 .

In the end, these strategies help to reach out the maximum profit even when NAFTRAC ended up with -16.73% annualized return. The cross-validation process implemented was a WFA which consists in optimizing indicator parameters with a set training (10 months in this case) and two months tested out of the sample repeating the process of one step forward up to the end of NAFTRAC series. WFA allows to solve overfitting problems and shows the net trading profit/loss for each out of sample and trades. WFA provides essential information about the strategy performance for each window tested.

In that sense, HUELUM could be used for a general strategy or could be tested in every time frame chosen from the trader to select the most profitable indicator or a mix of technical indicators which is a notable advantage since is possible to track trades and strategy performance through an equity curve graph whether form general strategy or WFA windows.

The main of this work is that the HUELUM Trading System has the capability to adapt to any asset (as long as it has OHLC prices), to capture its behavior, trends and momentum and even better, HUELUM gives accurate buy and sell signals allowing trading strategies, all of this, in a low-frequency environment. It is worth noting to point out that while it is true that this research only reported market positions, HUELUM has the flexibility to include limited, stop loss and trailing stops positions according to trader’s preference. Recall the possibility to change cost transactions in HUELUM, which allows comparing different fees, another advantage of this trading System.

Although high-frequency algorithms have become the sensation for many analysts and traders, keep in mind that not all the markets have the deepness and liquidity to make that high-frequency algorithm works efficiently, especially securities that are listed in emerging countries such like México. This is when algorithm trading for low frequency like HUELUM, helps to traders, to analyst and anyone who has an investment in financial assets, to make a better an accurate decision compared to a buy &hold strategy, to make more profits and last but not least, to reduce potential equity losses.

Now, this is not the first and last version of HUELUM; this trading System has the flexibility to include other indicators, not necessarily technical ones. For future research, the creation of new tools and indicators will be implemented in HUELUM Trading System.

Referencias

Bajgrowicz, P., & Scaillet, O. (2012). Technical trading revisited: False discoveries, persistence tests, and transaction costs. Journal of Financial Economics, 106(3), 473-491. doi: 10.1016/j.jfineco.2012.06.001 [ Links ]

Bian-Du, H., & Jingdong, Z. (2016). Optimal execution in high-frequency trading with Bayesian learning. Physica A: Statistical Mechanics and its Applications, 461, 767-777. doi: 10.1016/j.physa.2016.06.021 [ Links ]

Black, F. (1986). Noise. The Journal of Finance, 41(3), 528-543. doi: 10.1111/j.1540-6261.1986.tb04513.x [ Links ]

Bollinger, J. (1992). Using Bollinger Bands. Stocks & Commodities, 10(2), 47-51. [ Links ]

Bollinger, J. (2002). Bollinger on Bollinger Bands. New York: McGraw-Hill. [ Links ]

Breeden, D. T. (1979). An Intertemporal Asset Pricing Model With Stochastic Consumption and Investment Opportunities. Journal of Financial Economics , 7(3), 265-296. doi: 10.1142/9789812701022_0003 [ Links ]

Brogaard, J., Carrion, A., Thibaut, M., Ryan, R., Shkilko, A., & Konstantin, S. (2018). High frequency trading and extreme price movements. Journal of Financial Economics , 128(2), 1-13. doi: 10.1016/j.jfineco.2018.02.002 [ Links ]

Brown, S. J., Goetzmann, W. N., & Kumar, A. (1998). The Dow Theory: William Peter Hamilton’s track record reconsidered. Journal of Finance, 53(4), 1311-1333. doi: 10.1111/0022-1082.00054 [ Links ]

Bulkowski, T. N. (2005). Encyclopedia of Chart Patterns. New Jersey: John Wiley & Sons, Inc. [ Links ]

Chien-Feng, H., Hsu, C.-J., Chi-Chung, C., Chang, B. R., & Chen-An, L. (2015). An intelligent model for pairs trading using genetic algorithms. Computational Intelligence and Neuroscience: CIN, 1-10. doi: 10.1155/2015/939606 [ Links ]

Dias-Paivaa, F., Nogueira-Cardoso, R., Peixoto-Hanaoka, G., & Moreira-Duarte, W. (2019). Decision-making for financial trading: A fusion approach of machine learning and portfolio selection. Expert Systems with Applications, 115, 35-655. doi: 10.1016/j.eswa.2018.08.003 [ Links ]

Droke, C. (2001). Gann Simplified (First ed.). New York: Marketplace Books. [ Links ]

Escobar, A., Moreno, J., & Múnera, S. (2013). A technical analysis indicator based on fuzzy logic. Electronic Notes in Theoretical Computer Science, 292, 27-37. doi: 10.1016/j.entcs.2013.02.003 [ Links ]

Fama, E. F. (1969). American Finance Association Efficient Capital Markets: A Review of Theory and Empirical Work. The Journal of Finance , 25(2), 28-30. [ Links ]

Forecasts, D. T. (2015). The Dow Theory Explained. Indiana: Horizon Publishing Company. [ Links ]

Gradojevic, N., & Gençay, R. (2013). Fuzzy logic, trading uncertainty and technical trading. Journal of Banking and Finance, 37(2), 578-586. doi: 10.1016/j.jbankfin.2012.09.012 [ Links ]

Grossman, S. J., & Stiglitz, J. E. (1980). On the Impossibility of Informationally Efficient Markets. American Economic Review, 70(3), 393-408. doi: 10.1177/0003065108330523 [ Links ]

Hagströmer, B., & Nordén, L. (2013). The diversity of high-frequency traders. Journal of Financial Markets, 16(4), 741-770. doi: 10.1016 /j.finmar.2013.05.009 [ Links ]

Harris, R. D., & Yilmaz, F. (2009). A momentum trading strategy based on the low frequency component of the exchange rate. Journal of Banking and Finance , 33(9), 1575-1585. doi: 10.1016 /j.jbankfin.2009.03.003 [ Links ]

Hasbrouck, J., & Saar, G. (2013). Low-latency trading. Journal of Financial Markets , 16(4), 646-679. doi: 10.1016/j.finmar.2013.05.003 [ Links ]

Jacob, S., Napoletano, M., Roventini, A., & Fagiolo, G. (2016). Rock around the clock: An agent-based model of low- and high-frequency trading. Journal of Evolutionary Economics, 26(1), 49-76. doi: 10.1007/s00191-015-0418-4 [ Links ]

Kuang, P., Schröder, M., & Wang, Q. (2014). Illusory profitability of technical analysis in emerging foreign exchange markets. International Journal of Forecasting, 30(2). doi: 10.1016/j.ijforecast.2013.07.015 [ Links ]

Lan, Q., Zhang, D., & Xiong, L. (2011). Reversal Pattern Discovery in Financial Time Series Based on Fuzzy Candlestick Lines. Systems Engineering Procedia,, 2, 182-190. doi: 10.1016/j.sepro.2011.10.021 [ Links ]

Lee, K., & Seo, B. K. (2017). Marked Hawkes process modeling of price dynamics and volatility estimation. Journal of Empirical Finance, 40, 174-200. doi: 10.1016 /j.jempfin.2016.08.004 [ Links ]

Li, K., Cooper, R., & Vliet, B. V. (2017). How Does High-Frequency trading Affect LowFrequency trading? Journal of Behavioral Finance, 1-15. [ Links ]

Lucas, R. E. (1978). Asset Prices in an Exchange Economy. Econometrica, 46(6), 1429-1445. doi: 10.2307/1913837 [ Links ]

Manahov, V., Hudson, R., & Gebka, B. (2014). Does high frequency trading affect technical analysis and market efficiency? And if so, how? Journal of International Financial Markets, Institutions and Money, 28(1), 131-157. doi: 10.1016/j.intfin.2013.11.002 [ Links ]

Mcdonald, M. (2002). Predict market swings with technical analysis. New York: John Wiley and Sons Inc. [ Links ]

Menkveld, A. J. (2013). High frequency trading and the new market makers. Journal of Financial Markets , 16(4), 712-740. doi: 10.1016/j.finmar.2013.06.006 [ Links ]

Merton, R. (1973). An Intertemporal Capital Asset Pricing Model. Econometrica , 41(5), 867-887. [ Links ]

Pardo, R. (2008). The Evaluation and Optimization of trading Strategies. New Jersey: John Wiley & Sons, Inc . [ Links ]

Scholtus, M., Van Dijk, D., & Frijns, B. (2014). Speed, algorithmic trading, and market quality around macroeconomic news announcements. Journal of Banking and Finance , 38(1), 89-105. doi: 10.1016/j.jbankfin.2013.09.016 [ Links ]

Serban, A. F. (2010). Combining mean reversion and momentum trading strategies in foreign exchange markets. Journal of Banking and Finance , 34(11), 2720-2727. doi: 10.1016/j.jbankfin.2010.05.011 [ Links ]

Sewell, M. (2012). The Efficient Market Hypothesis: Empirical Evidence. International Journal of Statistics and Probability, 1(2), 164-178. doi: 10.5539/ijsp.v1n2p16 4 [ Links ]

Shiller, R. J.(2003). From Efficient Markets Theory to Behavioral Finance. Journal of Economic Perspectives, 17(1), 83-104. doi: 10.1002/9781118258415 [ Links ]

Stanković, J., Marković, I., & Stojanović, M. (2015). Investment Strategy Optimization Using Technical Analysis and Predictive Modeling in Emerging Markets. Procedia Economics and Finance, 19(15), 51-62. doi: 10.1016/S2212-5671(15)00007-6 [ Links ]

Tam, F. K. (2015). The power of Japanese candlestick charts. Advanced Filtering Techniques for trading Stocks, Futures, and Forex. Singapore: John Wiley & Sons Singapore Pte. Ltd. [ Links ]

Wiecki, T. (2012, March 2). Parameter Optimization in Algorithmic Finance Part I: Walk forward optimization. Retrieved from http://blog.quantopian.com/parameter-optimization/Links ]

Ying-Hua, C., & Ming-Sheng, L. (2017). Incorporating Markov decision process on genetic algorithms to formulate trading strategies for stock markets. Applied Soft Computing, 52, 1143-1153. doi: 10.1016/j.asoc.2016.09.016 [ Links ]

4Also known as black-box trading, algo-trading or automated trading.

5Even in a downtrend, financial market always offers an opportunity to make a profitable trade.

6HUELUM refers to a cheering expression used by the community of Instituto Politécnico Nacional. Originally, HUELUM expression was used to gather students and invite them to skip classes.

7Where a market it’s made up of firms that make production-investment decision and investors that select among firms’ securities.

8In fact, the main criticisms of EMH focus on the lack of determinate risk preferences and the cost of information, if we take into consideration this argue, is not possible to reach efficiency because economic agents have no longer access to the same information. In this sense, the EMH is untestable and impossible (Sewell, 2012).

9And even (Fama, 1969) refers that if one of these assumptions is broken, a market is no inefficient unless that with the available information, a better assessment is made. Likewise, if information is not costless for all investors this is not enough to consider a market inefficient.

10There’s plenty literature that discuss whether the behavior of noise traders may influence share prices despite of well-informed investors or not. However, it is considerate that noise traders are essentials if it is desired the existence of liquid markets (Black, 1986) as well as they play a main role in trading sessions (Grossman & Stiglitz, 1980) in spite of they try to replicate the behavior of other traders in an irrational way and their techniques.

11Japanese candlesticks are commonly represented with green or white color for bull’s figures and red or black color for bearish candles. However, they can be represented with the colors that the trader considers most convenient.

12At this point, it is worth notingto mention than the use of candles first appeared at the end of 1800 in Japan. The credits are attributed to a rice trader named Munehisa Homma. This Japanese trader had such a good performance that became the financial consultant to the Japanese government and was given the title of Samurai, he achieved more than 100 winning trades in a road and according to (Tam, 2015), their ideas where perfectioned over many years of trading to finally culminate in the system of candlestick charts that are currently being attributed to Charles Dow as the pioneer of technical analysis in the United States.

13An overbought area relates to a constant uptrend of the security’s prices whit a few corrections and an oversold area is when there is a constant downtrend of the security’s prices whit a few rallies.

14BB can be used as support and resistance as well. A support level is where the closing price or the candles tends to find an imaginary barrier in different bouncing price’s levels when the price is dropping. Opposite to the support, a resistance is when the closing price or the candles tends to find an imaginary barrier in different bouncing price’s levels when the price is rising (Bulkowski, 2005).

15A stop loss order is a specified threshold related to initial trade asset price where a market or limit order is activated, and a trailing stop order is a specified threshold related to current asset price where a market or limit order is activated.

16Assuming buying NAFTRAC at the beginning of 2018 and held it to the end of 2018.

Received: March 18, 2018; Accepted: July 29, 2018

*Contacto de correspondencia. Correo: ajimenezp@ipn.mx

**

Segundo Lugar, Categoría Investigación Financiera Empresarial, XXXIV Premio de Investigación Financiera IMEF-EY 2018

Creative Commons License This is an open-access article distributed under the terms of the Creative Commons Attribution License