0% found this document useful (0 votes)
8 views

Research 4

Indian Stock Exchanges - Buying and selling Stocks

Uploaded by

GANESAN G
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Research 4

Indian Stock Exchanges - Buying and selling Stocks

Uploaded by

GANESAN G
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

Expert Systems With Applications 204 (2022) 117478

Contents lists available at ScienceDirect

Expert Systems With Applications


journal homepage: www.elsevier.com/locate/eswa

Stock market prediction and portfolio composition using a hybrid approach


combined with self-adaptive evolutionary algorithm
Rodrigo Lopes de Almeida, Rui Ferreira Neves ∗
Instituto de Telecomunicac˛ões, Instituto Superior Técnico, Torre Norte, Av. Rovisco Pais, 1, 1049-001, Lisboa, Portugal

ARTICLE INFO ABSTRACT

Keywords: This work presents a new approach to maximize financial market investment returns. It incorporates two
Evolutionary algorithms Evolutionary Algorithms (EAs) combined with fundamental and technical investment strategies. The first EA
Self-adaptive evolutionary algorithms (simple) maintains its evolutionary parameters static during evolution. The second (self-adaptive) introduces
Technical analysis
the variation operators’ parameters’ values in the representation for them to evolve. The EA is responsible for
Fundamental analysis
optimizing the weight that financial ratios from the F-Score have on composing static/dynamic portfolios.
Technical indicators
F-score
Furthermore, it is also responsible for defining the importance that selected technical indicators have on
S&P500 revealing the best timing for market positions placement. Results showed that both cases surpassed the S&P500
returns, performing their best results using a self-adaptive EA combined with a static portfolio and a sliding
window of 2 years of train/test. The technical case study showed better results in ‘‘bear markets’’ since it
predicted some market declines. Its best subtest achieved returns on average 2.2x and in its best 3.5x higher
than the benchmark. Its Sharpe Ratio achieved, on average, 4.9x and in its best 9x higher results than the
benchmark. The fundamental case study displayed best in the ‘‘bull market’’, achieving high market prices.
Its best subtest achieved returns on average 2.4x and in its best 3.2x higher than the benchmark. Its Sharpe
Ratio achieved, on average, 4.4x and in its best 6.5x higher results than the benchmark.

1. Introduction Two main strategies attempt to beat the market: the Fundamental
and the Technical. On the one hand, the fundamental strategy bases
Financial markets have been around for more than four centuries. In itself on financial statements and applies this economic data to build
1602 the first “modern” securities market was founded in the Nether- portfolios (Soros, 2015). On the other hand, the technical strategy uses
lands not long after the establishment of the Dutch East India Company. past data (prices/indicators) and tries to mine patterns like trends that
This creation was the result of the necessity of exchanging commodities
may prompt a superior sign to where the market is moving (Schwager,
between traders. Since the creation of the Amsterdam Stock Exchange
1984).
many have followed its steps, and today a financial market is available
With the expansion and study of the financial markets, numerous
in most nations of the modern world. For a long time, markets have
been a territory of interest not only to traders but also to researchers. models were developed, and much data was generated. Many brokers
The trends of the market, the price unpredictability, and the amount of also started offering more technical information. With the power of
money that generates created such interest that multiple theories and computers, many saw the possibility of processing all this information
studies to comprehend the markets have been developed. in a short time to help with trading decisions. From that point forward,
In the Theory of Efficient Markets (EMT), Fama et al. (1970) state multiple researchers from the most different areas have developed sys-
that market prices reflect all the available information and that the mar- tems and hypotheses that enable the traders to have more power in time
ket reacts rapidly to variations in the world (Malkiel & Fama, 1970). to make a trade. A particular area that has brought much innovation is
This hypothesis additionally affirms that stocks trade at fair value. the Artificial Intelligence (AI) domain that, in models such as Evolution-
With that in mind, it is inconceivable for the investors to purchase ary Computation (EC) and Neural Networks (NN), has demonstrated
undervalued stocks and make a profit out of them (beat the market).
potential in the research for forecasting models (Gorgulho, Neves, &
Even though this hypothesis has substantial valid premises, there is
Horta, 2011; Hsieh, Hsiao, & Yeh, 2012; Lin, Yang, & Song, 2011; Pinto,
also the opposite side of supporters who do not agree with it and have
Neves, & Horta, 2015; Silva, Neves, & Horta, 2015).
proposed numerous strategies to vanquish the market.

∗ Corresponding author.
E-mail addresses: [email protected] (R.L.d. Almeida), [email protected] (R.F. Neves).

https://doi.org/10.1016/j.eswa.2022.117478
Received 26 May 2020; Received in revised form 14 April 2022; Accepted 29 April 2022
Available online 17 May 2022
0957-4174/© 2022 The Authors. Published by Elsevier Ltd. This is an open access article under the CC BY-NC-ND license (http://creativecommons.org/licenses/by-
nc-nd/4.0/).
R.L.d. Almeida and R.F. Neves Expert Systems With Applications 204 (2022) 117478

In this work, a new approach to portfolio composition is proposed, market sentiment. The profit of shareholders is a result of both the
combining Evolutionary Computation with multiple indicators, ratios, dividends paid to them from the companies profits and of any actions
and proposed theories. To solve the problem of which stocks to choose in the share price (capital growth) (Levinson et al., 2014; Strumeyer,
for a portfolio composition, fundamental indicators and ratios are 2017)
suggested in combination with an EA. The time and type of position
also have incredible significance, so the Evolutionary Algorithm helps, 2.2. Market forecasting
with the support of technical indicators, to perceive the best time to
make the position in the markets. Market Forecasting is defined as the process of determining the
The Evolutionary Algorithm relies on creating populations that direction in which the price is likely to move. Forecasting can be
based, on their fitness, evolves the best individuals and removes the approached in two ways: using Technical Analysis or Fundamental
ones who got the worst results. With some evolution time, the popu-
Analysis. While technical analysis concentrates on the examination
lation winds up showing signs of improvement and can advance the
of market activity, fundamental analysis centers around the financial
procedures of portfolio arrangement and market exchanging.
powers of supply and demand that cause the price to vary (Murphy,
There are three main contributions to this paper. The first is the
1999).
implementation of a portfolio composition system combined with F-
Score for ranking companies to take part in static/dynamic portfolios.
2.2.1. Fundamental analysis
The second contribution is the development of EAs that, combined
with a fundamental and technical investment strategy, choose the It is believed that stocks have a real “fundamental” value, different
best weights for portfolio composition variables and technical analysis from their current market price. The fundamental value of a stock
indicators. One of the EAs even has self-adaptive capabilities, meaning should be defined concerning the earning power of the assets or con-
that it is able to incorporate the variation parameter values in the cerning the fundamental value of other stocks. Throughout time, the
candidate solutions in order to adapt its variation operator parameters market price of a stock should tend towards its fundamental value, and
hoping to achieve optimal values for efficient optimization. Finally, when it happens, the analysis of fundamental values provide a useful
the last contribution is the creation of a sliding window scheme to guide to investors.
understand the best combination of years, for training and testing Fundamental Indicators are a crucial part of the fundamental anal-
trading algorithms. ysis. These tools provide the analyst with better methods for un-
This paper is structured as follows: Section 2 addresses, in the derstanding the financial statements and formulate the appropriate
first section, the fundamental knowledge and concepts both in the conclusions.
markets field as in the Artificial Intelligence area. The second part The F-Score is a fundamental scoring system that ranges from 0–9
describes the related work and analyzes what ideas and concepts can be (9 being the best), aiming to classify how strong the financial position
taken to use for further development. Section 3 presents the proposed of a company is. To make this classification, Piotroski, Joos, Monahan,
architecture, its functionalities, and an in-depth analysis is performed and Lee (2002) proposed an aggregate signal (1) that results from the
for most developed modules. Section 4 presents and examines the case addition of specific individual binary signals. These signals are financial
studies developed in this work according to selected validation metrics. ratios inferred from reports such as the financial reports (Piotroski
Section 5 presents the conclusions of this paper and suggestions for et al., 2002).
future work.
𝐹 _𝑆𝐶𝑂𝑅𝐸 = 𝐹 _𝑅𝑂𝐴 + 𝐹 _𝛥𝑅𝑂𝐴 + 𝐹 _𝐶𝐹 𝑂 + 𝐹 _𝐴𝐶𝐶𝑅𝑈 𝐴𝐿
2. Related work + 𝐹 _𝛥𝑀𝐴𝑅𝐺𝐼𝑁
+ 𝐹 _𝛥𝑇 𝑈 𝑅𝑁 + 𝐹 _𝛥𝐿𝐸𝑉 𝐸𝑅 + 𝐹 _𝛥𝐿𝐼𝑄𝑈 𝐼𝐷 + 𝐸𝑄_𝑂𝐹 𝐹 𝐸𝑅 (1)
This section provides, in the first section, fundamental concepts
on Equity Financial Markets, Market Forecasting, as well as the tools The binary values are always given, taking into account the result
used to perform it and Artificial Intelligence with a particular focus of the ratios. The ratios used in F-Score are described below:
on Evolutionary Algorithms. In the second part, the related work is
• Return On Assets (ROA) allows the analyst to understand how
presented in Market Forecasting and Evolutionary Computation.
profitable a company is.
2.1. Financial markets • Cash Flow Operations (CFO) allows the analyst to understand
the easiness that a company has to transform sales into cash.
The concept of the financial market covers multiple types of mar- • Accrual is the records of the revenues and expenses regarding a
ketplaces where several sorts of trading occur. The financial market is company during a specific period.
the name given to a place where buyers and sellers meet to trade assets. • Gross Margin (MARGIN) is a percentage that expresses how
The investors or “floor traders” buy and sell assets in the exchanges to profitable the company’s operations are. It measures how much
make the most profit they can. These decisions of buying and selling revenue from sales the organization holds after all the costs
are based on expectations about future prices, and these, in turn, are associated with providing a service or making a product are
conditional on present buy and sell decisions (Soros, 2015). deducted.
Equities are usually known as shares or stocks that represent partial • Asset Turnover (TURN) compares the sales value of a company
ownership of a company and also work as financial instruments. Shares to its average sales value. It is a clear way to measure the
are formed initially when a corporation is established. efficiency of how the company is managing its assets to create
The capital market is a general term that includes the stock market value.
and other venues for trading financial products and long-term debt. • The change in leverage (LEV) allows the analyst to have over-
The stock market allows banking institutions and investors to exchange sight over the changes in the company debt-related issues.
stocks, either publicly or privately, to match capital savers with capital • The Liquid variable measures the Current Ratio (CR) in compar-
needers and to raise capital (Mishkin, 2007; Strumeyer, 2017). Follow- ison to the previous year’s current ratio. This result is a good way
ing the public listing of a company (Initial Public Offering (IPO)), the for the analyst to examine the capacity that the company has for
shares trade on stock exchanges, and their valuation is influenced by paying debts.
supply and demand, which is determined by the underlying fundamen- • (EQ OFFER) tells the analyst if there is a change in the number
tals of the macroeconomic business factors like the interest rates, and of shares since the previous year

2
R.L.d. Almeida and R.F. Neves Expert Systems With Applications 204 (2022) 117478

Table 1
Related work table.

2.2.2. Technical analysis the next generation. In order to create the new generation, variation
While fundamental analysis uses the information that is available in operators (reproduction/mutation) are applied to the best candidates.
the financial statements to forecast prices, technical analysis is based After breeding, the offspring is evaluated with the fitness function and
on finding patterns in data (as volume, open interest, sentiment mea- subsequently competes with the other solutions for selection.
sures, or others) available from databases (Schwager, 1984). During This type of mechanisms allows the species to evolve in the direction
the technical analysis, the analyst looks at past data and searches of the best individual and also to have some randomness associated that
for patterns like trends or regular cycles that could lead to correct enables new kinds of features to be tested in the environment. This
market predictions. After the pattern extraction, it is possible to apply process repeats itself until the best solution (optimization) is attained
them and choose when to buy and sell stocks accordingly to the or until the stop criteria set previously is reached (Eiben, Smith, et al.,
rules deduced from the data (Mishkin, 2007). Technical analysis em- 2003; Mitchell, 1998).
ploys multiple types of tools such as: Support and Resistance, Trends,
Technical Indicators, and Market Indicators. 2.4. State of the art
Support and Resistance represent moments where the
buyers/sellers prevent the price rate to go below/above a certain In this section, multiple works in the financial market’s prediction
threshold. This type of barrier allows traders to talk about price levels. and Evolutionary Computation area are presented and explained. At
Trends represent a fluctuation in price that makes price follow a the end of the section, a Table 1 is presented, featuring the different
specific direction (trend-line). Technical Indicators are mathematical algorithms and results obtained in the works introduced.
calculations on stock price and volume that enable the trader to antic-
ipate price changes. While Technical Indicators provide a glimpse of 2.4.1. Works on financial markets prediction
how a stock is behaving, Market Indicators presents information on A system showing good results contradicting the S&P500 and buy-
how a specific market is performing (Achelis, 2001). and-hold on the losses by profiting in a down-trending is developed
using genetic algorithms and an Echo State Network (ESN) for technical
2.3. Artificial intelligence analysis parameter enhancing (Lin et al., 2011).
Another work that investigated the power of NN in financial markets
Artificial Intelligence is a broad scientific field of study. To best showed that the average returns from NN are above the overall market
define it, we can divide it into its four major goals: thinking humanly, average (Lam, 2004).
thinking rationally, acting humanly, and acting rationally. The first In order to predict the highest and lowest stock prices of each day,
two are concerned with the thought process and reasoning, whereas an Artificial Neural Network (ANN) using a Multilayer Feed-Forward
the other two address behavior. The first and third measure success Neural Network (MLP) was trained. The results show that the trading
in terms of closeness to human performance, whereas the second and system can double the initial capital of the investor in the tested
fourth, measure towards an ideal performance measure denominated period, revealing to be a system with potential within the dataset
rationality1 (Russell & Norvig, 2016). presented (Martinez, da Hora, Palotti, Meira, & Pappa, 2009).
AI separates into very distinct categories: Symbolic, Deep Structured A new approach is developed to automatically manage a portfolio
Learning, Bayesian Networks, and Evolutionary Algorithms. by using a Genetic Algorithm (GA) conjugated with technical anal-
Evolutionary Algorithms underlying idea is to follow the concept ysis (Gorgulho et al., 2011). The results prove that this method is
of evolution. In these algorithms, a population is generated in a partic- successful, and the combination between the technical indicators and
ular environment with a limited amount of supplies. The competition the GA can be very fruitful.
to get those resources creates a natural selection that, in turn, produces On another study, a Multi-Objective Genetic Algorithm (MOEA) to
an increase in population fitness. create and manage a stock portfolio by implementing a fundamental
Given an optimization problem, multiple candidate solutions are and technical approach is proposed (Silva et al., 2015). The results
generated and evaluated under a specific quality function. This func- show that the increase in the number of fundamental indicators makes
tion’s job (fitness function) is to evaluate the candidates. a positive impact on the precision of the simulation results and also in
After the evaluation, the algorithm ranks the solutions from best the MOEA.
to worst so that the best-ranked individuals get to breed and create A technical strategy optimizer combining the Volatility Index (VIX)
indicator with a MOEA to predict the future tendency of assets price
is developed. This work showed that the system outperforms market
1
Given what it knows, a system is rational if it can reason and does ‘‘the indexes and reduces investment risk. It is also observable that the
right thing’’. returns increase when the risk rises and that the Volatility Index (VIX)

3
R.L.d. Almeida and R.F. Neves Expert Systems With Applications 204 (2022) 117478

Fig. 1. System architecture.

indicator avoids several falls in the stock market by reducing the In another work, a new approach proposes a combination of an Evo-
negative turns Pinto et al. (2015). lutionary Artificial Bee Colony Algorithm (EABC) with Penalty Guided
A hybrid approach is proposed using F-Score (1) and G-Score among Support Vector Machines (PGSVM) in order to generate predictions
with a momentum strategy incorporated with past technical informa- more effectively (Hsieh et al., 2012). In this system, the EABC algorithm
tion (Chen, Lee, & Shih, 2016). The results show that the hybrid system uses a population of bees who are given velocity and flying direction in
outperforms the moment strategy with higher returns. order to optimize the PGSVM. The results show that the EABC-PGSVM
method outperforms other comparable methods saving Central Process
2.4.2. Works on Evolutionary Algorithms Unit (CPU) time and also enhances the hit ratio. Given the efficiency
Genetic algorithms are a subtype of Evolutionary Algorithms used and potential for forecasting classification presented by the algorithm,
in optimization problems based on the theory of evolution and natural the authors propose that the system may be applied in other fields.
selection. With this in mind, Genetic Algorithm (GA) seems a particu-
larly exciting methodology to apply in the most different areas. Genetic
3. Architecture
algorithms are proposed to improve technical analysis by generating a
combination of parameters that identify the optimal reversal points of
The designed system attends two significant problems: The selection
financial trends (Lin et al., 2011). By using GA as the enhancer of the
technical indicators and combining it with Echo State Network (ESN), of good fundamental companies for portfolio composition and the
this work brings a new perspective on how it is possible to use genetic picking of the best time to take positions in the market. The approach
algorithms on stock trading systems. to solving the given problems is based on Artificial Intelligence, more
In a typical GA, it is common to create a “study population’’ to specifically in the Evolutionary Algorithms branch. On the one hand,
measure its performance on doing specific tasks and to comprehend the evolutionary process selects the best companies for the portfolio by
how the evolutionary steps result in creating a better population. With providing the most suitable weights to give the appropriate importance
that as a foundation, random types of individuals called “classifier to each ratio of the F-Score (1). On the other hand, it provides weights
equations’’, composed of an array of weights that symbolize the value for the technical indicators to change their importance and to get better
given to each technical rule, are created to manage a financial portfolio timing decisions according to how the market is behaving.
by optimizing its technical indicators (Gorgulho et al., 2011). The To accomplish the goals of the proposed system, it was necessary
equation also assigns the score that an asset needs to adopt (long, short to design a framework that could handle all the steps required. The
or closing position) in the portfolio. In order to estimate performance, various steps are divided into different modules, and each module has
the Return on Investment (ROI) function evaluates the efficiency of a specific task that needs to achieve so that the system can be fully
different investments during a specific range of time. functional. In Fig. 1 it is possible to see the full system architecture,
Usually, each candidate solution is assigned to a variety of chromo- the various modules that constitute it, and the way data is transmitted
somes to stimulate the creation of unique individuals, providing more through the system.
complete results. This work utilizes three different chromosomes to In order to better understand the architecture, Fig. 1, a system
represent investment models with real constraints similar to the ones flow diagram was created, Fig. 2. The flow chart represents the in-
encountered by portfolio managers (Silva et al., 2015). Each individual teractions between modules and the way the developed system works.
of the population is composed of a sequence of values (genes). The There are two essential points to know before starting the system flow
chromosome divides itself into two parts. The first group is the financial description: The colors of each module presented correspond to the
ratio weights, and the second is the trading parameters. Three types colors of the architecture module to which they belong. Moreover,
of chromosomes are used to have more broad results and to explore the data inputted by the user, as well as the datasets created, are
more on the GA approach. The algorithms used have two objectives: distributed throughout each module that requires them. All modules
the Return and the Variance of the Returns. The system chooses the use the datasets created except the User Layer Module and Evolutionary
weights for each fundamental indicator and determines the values Algorithm Module. Also, all the modules utilize the user preferences
of the technical indicators. In this study, fitness is calculated using except the Data Preparation Module.
accumulated return and variance. Besides that, the algorithm selects The data flow will now be described step by step:
the chromosomes for reproduction and applies the methods of crossover
and mutation to create new elements. 1. The user starts by defining the configuration settings of the
In systems where the goal is optimizing real-world applications, the system variables. These variables range from: The number of
fitness function is the most critical measure of the implementation (Kim generations to run the Evolutionary Algorithm, the percentage
& Shin, 2007). The fitness evaluation process focuses on simulating the of the population to take part in elitism, the type of investment
performance of each trading individual in the evolving population and strategy to use, and even the maximum portfolio size. The user
calculating the corresponding return related to the risk (Pinto et al., can choose many more settings that are described in the User
2015). Module subsection below.

4
R.L.d. Almeida and R.F. Neves Expert Systems With Applications 204 (2022) 117478

Fig. 2. system data flow.

2. After the user has defined the configurations of the system, 12. In the Evolutionary Algorithm (EA) module, the candidate solu-
the data preparation takes place. The Data Preparation Module tions undergo a process of selection to pick the parents of the
downloads the datasets from its sources. offspring, crossover to reproduce the new offspring, and muta-
3. After downloading takes place, the module inspects, cleans, and tion to perform small variations in the offspring. When all these
validates the datasets to guarantee data quality. processes are complete, the new population replaces the old one.
4. Finally, the Data Preparation Module calculates the fundamen- If the self-adaptive parameter is enabled, then the crossover and
tal ratios and the technical indicators to use in the portfolio mutation operators use the evolutionary part of the chromosome
composition and the trading environment. to get the probabilities of each variation operator.
5. Following, the cleaned data is fed to the Evolutionary Algorithm 13. When all the Evolutionary Algorithm steps are complete, the
Module. In this step, the initial population is generated and sent new population is sent to the Portfolio Creator Module (step 6),
to the Portfolio Creator Module. where all the processes will loop until the training ends.
6. In the Portfolio Creator Module, the portfolio is arranged, taking 14. If the just ended simulation was not a test, but it was the
into account the fundamental part of the chromosomes gen- last generation of evolution (training finished), the best fitness
erated to work as weights and the financial datasets used to individual is selected and used as a chromosome to make an out
calculate the F-score (1). After all the calculations have been of sample test, going back to step 6.
made, the companies get ranked, and the best ones serve as a 15. If the just ended simulation was a test, then the results are sent
portfolio. After the portfolio creation, both the chromosomes and to the User Layer Module, printed to the user, and the system
the portfolio get sent to the Trading Simulator Module. finishes.
7. In the Trading Simulator Module, the candidate solutions get Now that the architecture and the system flow have been intro-
evaluated. During the evaluation, the simulator uses the tech- duced, each module belonging to the designed system will be described
nical part of the chromosomes combined with the technical in full detail.
indicators to choose the best positions and timings for each
company to trade. If the investment type is a buy-and-hold, then 3.1. Data preparation
the algorithm buys all the companies on the first day and sells
them all on the last day of trading. The Data Preparation Module handles three main duties: Data
8. At the end of each year, the simulator sells all the remaining Downloading, Data Processing, and Data Manipulation. Data Down-
stocks. If dynamic F-Score is enabled, then a new portfolio is loading retrieves and stores multiple required datasets from various
generated for the upcoming year (step 6). If it is disabled, the sources. Data processing inspects, cleans, and verifies the data down-
simulation maintains the same portfolio for the upcoming year loaded. Data Manipulation calculates financial ratios and technical
and heads to step 7. indicators from the pre-processed data for posterior use.
9. When the trading period finishes, the positions data frame is The financial indicators were calculated for each downloaded com-
sent to the Statistics Module. In this module, the fitness of each pany using the F-Score ratios. The technical indicators were calcu-
candidate is calculated. lated using specific rules appointed to each Technical Indicator (TI)
10. After the calculation finishes, the module calculates the statistics to form a score. The score varies from Very Low Score (−1), Low
of the simulation performance and stores them. Score (−0.5), Neutral (0), High Score (0.5), and Very High Score
11. If the just ended simulation was not a test, nor the last train- (1), where ‘‘Very Low Score’’ is the worst and ‘‘Very High Score’’ is
ing generation, the fitness values are sent to the Evolutionary the best. The indicators were selected, taking into consideration the
Algorithm Module. goals to achieve and their performance in the works presented. The

5
R.L.d. Almeida and R.F. Neves Expert Systems With Applications 204 (2022) 117478

Fig. 3. Relative strength index example.

Table 2 Table 3
RSI scoring rules. EMA scoring rules.
Score Description Score Description
Very Low RSI value is equal or above 70 Very Low Stock Price was above
Low RSI value is between 30 and 70 but its decreasing Exponential Moving Average (EMA) value and now is below
Neutral RSI value did not change since last period Low EMA value is decreasing
High RSI value is between 30 and 70 but its increasing Neutral EMA value did not change since last period
Very High RSI value is equal or below 30 High EMA value is increasing
Very High Stock Price was below EMA value and now is above

five indicators picked were: Relative Strength Index (RSI), Exponential Table 4
Moving Average (EMA), Moving Average Crossover (MAC), Rate of MAC scoring rules.
Change (ROC), the Moving Average Convergence Divergence (MACD) Score Description
and the VIX (Brasileiro, Souza, Fernandes, & Oliveira, 2013; Gorgulho Very Low Faster EMA crosses below Slower EMA
et al., 2011; Pinto et al., 2015). Low Both EMA values decreasing
Neutral Both EMA values did not change since last period
Each of the indicators will now be described in full detail. High Both EMA values increasing
Very High Faster EMA crosses above Slower EMA
(i) Relative Strength Index
Relative Strength Index (RSI) is a momentum indicator that
measures the significance of a price change to evaluate if it
is overbought or oversold. In this Technical Indicators (TI) the as it represents a fast MA to perceive sudden changes in the price
period chosen was 14 days as its the most common value to use value (Achelis, 2001). The formula follows:
in this indicator (Achelis, 2001). The formula follows:
𝐸𝑀𝐴𝑡 (𝑛) = 𝑃 𝑟𝑖𝑐𝑒𝑡 ∗ 𝑘 + 𝐸𝑀𝐴𝑡−1 (𝑛) ∗ (1 − 𝑘) (6)
100
𝑅𝑆𝐼𝑡 (𝑛) = 100 − (2) and
1 + 𝑅𝑆𝑡
2
and 𝑘= (7)
𝑛+1
𝐴𝑣𝑔𝐺𝑎𝑖𝑛𝑡
𝑅𝑆𝑡 = (3) where 𝑡 represents today, 𝑛 depicts the period chosen and
𝐴𝑣𝐿𝑜𝑠𝑠𝑡
𝐸𝑀𝐴1 (𝑛) is a simple average over 𝑛. The scores of the EMA
𝐴𝑣𝑔𝐺𝑎𝑖𝑛𝑡−1 ∗ (𝑛 − 1) + 𝐶𝑢𝑟𝑟𝑒𝑛𝑡𝐺𝑎𝑖𝑛 match the following rules (see Table 3):
𝐴𝑣𝑔𝐺𝑎𝑖𝑛𝑡 = (4)
𝑛 An example of EMA and its score system is shown in Fig. 4:
𝐴𝑣𝑔𝐿𝑜𝑠𝑠𝑡−1 ∗ (𝑛 − 1) + 𝐶𝑢𝑟𝑟𝑒𝑛𝑡𝐿𝑜𝑠𝑠 (iii) Moving Average Crossovers
𝐴𝑣𝑔𝐿𝑜𝑠𝑠𝑡 = (5) The Moving Average Crossover (MAC) is another implemen-
𝑛
tation of moving averages. In this strategy, two exponential
where 𝑡 represents today, 𝑛 depicts the period chosen, and the moving averages were implemented to find market trends. The
initial 𝐴𝑣𝑒𝑟𝑎𝑔𝑒𝐺𝑎𝑖𝑛 and 𝐴𝑣𝑒𝑟𝑎𝑔𝑒𝐿𝑜𝑠𝑠 are simple averages over 𝑛. first is a fast-moving average characterized by having a shorter
The scores of the RSI match the following rules (see Table 2): period (5) and consequently more sensibility to market shifts.
An example of RSI and its score system is shown in Fig. 3: The second EMA is described by having a slower period (20), and
(ii) Exponential Moving Average therefore a slower but more reliable response to market changes.
A moving average is a trend following indicator that depicts the The MAC is known for using the crossovers between the expo-
mean price over a particular time frame. Since the prices are nential moving averages to find patterns in the market (Achelis,
smoother and clearer to read, they are used to discover patterns. 2001).
The exponential moving average is a specific type of Moving The scores of the MAC match the following rules (see Table 4):
Average (MA) that is calculated by applying a percentage of the An example of MAC and its score system is shown in Fig. 5:
current day price to the previous period moving average value. (iv) Rate of Change
Thus, EMA places more weight on more recent values giving Rate of Change (ROC) is a momentum indicator that displays
them more significance. In this TI, the period picked was 12 days the difference between the current price and the price 𝑛 periods

6
R.L.d. Almeida and R.F. Neves Expert Systems With Applications 204 (2022) 117478

Fig. 4. Exponential moving average example.

Fig. 5. Moving average crossovers example.

Fig. 6. Rate of change example.

before. The signal generated creates a curve estimating the was 13 (Achelis, 2001). The formula follows:
percentage that prices have changed over time. Doing so pro- 𝑃 𝑟𝑖𝑐𝑒𝑡 − 𝑃 𝑟𝑖𝑐𝑒𝑡−𝑛
vides the trader with a reliable method to measure how quickly 𝑅𝑂𝐶 = ∗ 100 (8)
𝑃 𝑟𝑖𝑐𝑒𝑡−𝑛
the price is moving. Rapid growth or decline may indicate
overbought or oversold conditions. where 𝑡 represents today and 𝑛 depicts the period chosen. The
The most popular periods for this TI are between 12 and 25 for scores of the ROC match the following rules (see Table 5):
short/intermediate trading. For that reason, the selected period An example of ROC and its score system is shown in Fig. 6:

7
R.L.d. Almeida and R.F. Neves Expert Systems With Applications 204 (2022) 117478

Fig. 7. Moving average convergence divergence example.

(v) Moving Average Convergence Divergence Table 5


ROC scoring rules.
The Moving Average Convergence Divergence (MACD) is a trend
following indicator that outlines the relationship between a Score Description

faster line (MACD) and a slower line (signal). The faster line Very Low ROC value was above 0 and now is below
Low ROC value increasing and Stock Price decreasing
represents a difference between 12 and 26 periods of exponen-
Neutral ROC value did not change since last period
tial moving averages while the slower line denotes a 9-period High ROC value decreasing and Stock Price increasing
EMA. Very High ROC value was below 0 and now is above
A commonly used technique converts the MACD indicator into a
histogram that plots the difference between the two MACD lines.
Table 6
The value of this visualization is to spot the spread between the
MACD scoring rules.
two lines (widening or narrowing). On the one hand, when the
Score Description
histogram is over zero and starts to fall, it denotes a weakening
Very Low MACD Histogram value was above 0 and now is below
in the uptrend. On the other hand, when the histogram is below Low MACD Histogram value decreasing to −∞
zero and starts to move upward, it expresses a loss of momentum Neutral MACD Histogram value did not change since last period
in the downtrend (Achelis, 2001; Murphy, 1999). The formula High MACD Histogram value increasing to +∞
follows: Very High MACD Histogram value was below 0 and now is above

𝑀𝐴𝐶𝐷𝑡 (𝑛𝑠 , 𝑛𝑙 ) = 𝐸𝑀𝐴𝑡 (𝑛𝑠 ) − 𝐸𝑀𝐴𝑡 (𝑛𝑙 ) (9)


Table 7
VIX scoring rules.
𝑆𝑖𝑔𝑛𝑎𝑙𝑡 (𝑛𝑡 ) = 𝐸𝑀𝐴𝑡 (𝑛𝑟 ) (10) Score Description
Very Low Fast SMA is above Slow SMA
𝑀𝐴𝐶𝐷𝐻𝑖𝑠𝑡𝑜𝑔𝑟𝑎𝑚𝑡 (𝑛𝑠 , 𝑛𝑙 ) = 𝑀𝐴𝐶𝐷𝑡 (𝑛𝑠 , 𝑛𝑙 ) − 𝑆𝑖𝑔𝑛𝑎𝑙(𝑛𝑟 ) (11) Low Fast SMA is below but approaching Slow SMA
Neutral Both SMA values did not change since last period
where 𝑡 represents today, 𝑛𝑠 depicts the short period, 𝑛𝑙 illus- High Slow SMA is below but approaching Fast SMA
trates the long period and 𝑛𝑟 represents the signal period. It is Very High Slow SMA is above Fast SMA
also important to notice that the values used for 𝑆𝑖𝑔𝑛𝑎𝑙(𝑛𝑡 ) are
the 𝑀𝐴𝐶𝐷𝑡 (𝑛𝑠 , 𝑛𝑙 ) result. The scores of the MACD match the
following rules (see Table 6):
an improved sentiment. On the other hand, the faster moving
An example of MACD and its score system is shown in Fig. 7: average crossing above the slower moving average represents an
(vi) Volatility Index unimproved market sentiment. The SMA formula follows:
The VIX is a sentiment indicator that tracks the S&P500 volatil-
1∑
𝑛−1
ity. Also known as the “Fear Index”, measures the amount of
𝑆𝑀𝐴𝑡 (𝑛) = 𝑃 𝑟𝑖𝑐𝑒𝑡−𝑖 (12)
optimism or fear in the market through price volatility. 𝑛 𝑖=0
A good example of VIX usefulness is the 2009 market crash.
where 𝑡 represents today and 𝑛 depicts the period chosen. The
Before the crash, VIX values would range between 10 to 30
scores of the VIX match the following rules (see Table 7):
however, when the market crash was imminent, VIX value sky-
rocketed determining that something abnormal was happening. An example of VIX and its score system is shown in Fig. 8:
In this work, the VIX indicator was used combined with two
Simple Moving Average (SMA) to smooth the values and get 3.2. Evolutionary Algorithm
more reliable signals. A faster SMA was used with a period of
50 while a slower SMA was implemented with a period of 200. In this work, Evolutionary Algorithms were selected as the model
The moving averages crossovers denote important shifts in the of AI to implement. This type of algorithms were picked since the
mentality of the investors. On the one hand, the slower moving reviewed papers revealed that these are able to achieve promising
average crossing above the faster-moving average represents results when combined with financial forecasting. Furthermore, the

8
R.L.d. Almeida and R.F. Neves Expert Systems With Applications 204 (2022) 117478

Fig. 8. Volatility index example.

Fig. 9. Fundamental chromosome composed of the F-Score (1) ratios.

Fig. 10. Technical Chromosome composed of the selected technical indicators.


Fig. 11. Self-Adaptive Chromosome composed of the probability of mutation 𝑃𝑚 and
crossover 𝑃𝑐 for the variation operators.

same analysis showed that EA are capable of handling the goals pro-
posed for this work (Gorgulho et al., 2011; Hsieh et al., 2012; Lin cases, values for the parameters are defined prior to the beginning of
et al., 2011; Pinto et al., 2015; Silva et al., 2015). The Evolutionary the algorithm, staying fixed throughout the whole process.
Algorithm Module is the center of this work. This module handles the The traditional method to choose the parameters is based on con-
creation and evolution of the system weights in order to achieve the ventions such as “mutation probability should be low”, “population
best solution possible. In this work, the first EA (simple) maintains size should be 200” and limited experimentation with distinct values.
its evolutionary parameters static during evolution. The second (self- For example, considering three parameters and four values for each of
adaptive) introduces the variation operators’ parameters’ values in the them.
representation for them to evolve. In this subsection, some of the EA Nevertheless, this type of parameter tuning is not feasible. Trying
constraints implemented are described as the parameters used in this all different combinations systematically is extremely time-consuming.
work. Besides, for numerical parameters, the optimal values could lie between
the points we are testing or not even be among the ones selected.
3.2.1. Representation This idea becomes even more discouraging if we are looking for
In this work, the representation was developed in a modular way. a generally good setup that is able to operate well on a range of
There are three types of representation modules: Fundamental, Techni- problems/scenarios (Eiben et al., 2003).
cal, and Self-Adaptive. In this work, the self-adaptive representation is the innovation part
The Fundamental Representation module is composed of nine and allows the EA to incorporate the variation parameter values in the
values depicting the weights of each fundamental F-Score (1) ratio. In candidate solutions. With this novel methodology, the EA evolves and
Fig. 9, a representation of the fundamental chromosome is presented. adapts the variation operator parameters, hoping to achieve optimal
It is important to notice that the colors of the representation modules values for efficient optimization. In Fig. 11, a representation of the
presented below, match the colors of the architecture modules Fig. 1 self-adaptive chromosome is presented.
where their values are utilized. In this work, the representation modules were combined in or-
The Technical Representation module is composed of six weights der to achieve various types of representations. The outcome of the
assigned for each technical indicator score created in the Data Module. combinations led to the creation of four types of representations.
In Fig. 10, a representation of the technical chromosome is presented. The first representation is used for a fundamental (Buy and Hold)
The Self-Adaptive Representation module is composed of two type of investment and is composed only of the fundamental repre-
genes that dictate the probabilities of mutation 𝑃𝑚 and crossover 𝑃𝑐 sentation module. In this type of chromosome, the weights are used
variation operators parameters. This representation module was cre- combined with the fundamental ratios to create a portfolio to trade.
ated considering one of the biggest problems in EA: Parameter tuning. The second type of representation is used for a technical investment
Building an executable EA instance requires stipulating values for strategy and combines the fundamental with the technical representa-
its parameters. These values determine whether it will find an optimal tion module. This type of representation uses its fundamental weights
solution and whether it will do so efficiently. Parameter tuning is a and ratios to create a portfolio but also the technical indicators scores
commonly practiced approach to algorithm design, where, in most and respective weights to make positions in the market.

9
R.L.d. Almeida and R.F. Neves Expert Systems With Applications 204 (2022) 117478

The third and fourth types of representations used in this work are works as follows: For each gene of the chromosome, a probability/value
variations of the first and second presented with the addition of the self- is generated randomly. If the value generated is lower than the muta-
adaptive representation module to add self-adaptive capabilities. These tion probability (𝑃𝑚 ), then a new value is generated for this specific
last types of representations are used for fundamental and technical gene.
investments, respectively. The mutation operator is a tool for random exploration of the space
containing all possible solutions (search space). Random exploration
3.2.2. Fitness function is welcome in the evolutionary process, not only to try solutions that
For the evolution process to occur an evaluation metric to distin- would not be tested but also to avoid early convergence. However, an
guish the best solutions from the worst must exist. evolutionary process containing much random exploration could turn
In this work, the fitness function utilized was the Rate of Return out to be similar to a brute-force algorithm where the optimal solution
(ROR). This metric is used to evaluate the gain/loss of some investment would be found not by evolution but by testing all the candidates. Fur-
over time, expressed as a percentage of the investment initial cost. The thermore, using a high mutation rate could lead to frequent destruction
higher the value of this metric, the best the individual performance is of candidate solutions with high fitness performing genes.
as it can obtain high returns on its investments. The formula follows: For those reasons in this work, the 𝑃𝑚 selected was 20% as it is
𝐺𝑎𝑖𝑛𝐹 𝑟𝑜𝑚𝐼𝑛𝑣𝑒𝑠𝑡𝑚𝑒𝑛𝑡 − 𝐶𝑜𝑠𝑡𝑂𝑓 𝐼𝑛𝑣𝑒𝑠𝑡𝑚𝑒𝑛𝑡 a low but significant value to occur and create small changes in the
𝑅𝑂𝑅 = ∗ 100 (13) individual. In a self-adaptive scenario, the 𝑃𝑚 is determined by the
𝐶𝑜𝑠𝑡𝑂𝑓 𝐼𝑛𝑣𝑒𝑠𝑡𝑚𝑒𝑛𝑡
value in the chromosome.
While other metrics consider the risk, such as the Sharpe Ratio
(which measures the performance of an investment by subtracting the 3.2.5. Replacement
risk-free rate from the mean return), it was decided that the goal was After the variation operators have completed their job it is time
to maximize profits, even if that carries more risk into the investment. for the old population to be replaced with the offspring. In this work,
The decision relies on the fact that there are already some measures the previous generation population is almost entirely replaced with the
to reduce the risk. Measures, such as having a big enough portfolio offspring. A small percentage of the new population is reserved for
(for it to be diverse) and using the above presented fundamental the elite of the old population. Elitism was implemented in order to
representation module to choose the best companies to take part in the maintain the best solutions from previous iterations. The percentage of
portfolio. Nonetheless, the Sharpe Ratio was still used to evaluate the the population that represents the elite is 30%.
performance of the system on a more statistical side.
3.2.6. Initialization
3.2.3. Selection At the beginning of the Evolutionary Algorithm, a specific number
In order to choose individuals to become parents, a selection process of candidate solutions are randomly generated to create a highly di-
needs to occur. In this work, tournament selection was assigned for this verse population. The population does not contain invalid individuals,
job. not even after the administration of some type of operator. In this work,
Although selection processes are very similar due to their stochastic 100 candidate solutions were randomly generated at the beginning of
nature, tournament selection has a specific parameter that enables easy the algorithm. This value was selected since it already represents a good
control of the selection pressure. The parameter is called tournament amount of solutions for the algorithm to explore.
size (𝑘) and represents the number of individuals to be randomly
selected to a pool where only the best individual will get selected. The 3.2.7. Termination condition
larger 𝑘, the more significant the probability of selecting a high-fitness The evolutionary problem presented does not have a known solu-
member is. In this work, the value of (𝑘) was picked as 70% since it tion. Thus, the purpose of the algorithm is to maximize its returns.
makes enough pressure to get the best fitness individuals and at the However, even after achieving the best solution, the algorithm will still
same time, leaves enough ‘‘space’’ for lower fitness solutions that may search eternally for a superior solution, for that reason, a termination
evolve to something interesting. condition was chosen.
The termination condition serves two purposes: the first is to alert
3.2.4. Variation operators the algorithm that it is time to end, and the second is that by creating
After the parents have been selected, variation operators are em- the same conditions for each test, the algorithms/simulations can be
ployed to generate the new offspring. compared between each other.
Although there are multiple types of crossover procedures, the 2 In this work, the termination condition selected was the number of
point crossover was selected. generations. After a certain number of generations, the algorithm stops
The nature of the operators studied (One-Point Crossover, N-Point the evolutionary process to test the best solution found. In this paper,
Crossover, and Uniform Crossover) makes it hard to state which per- the selected value was 20 generations since it gives enough iterations
forms the best. Nevertheless, it is possible to examine their weaknesses for the population to experiment and evolve to better individuals.
and choose the one that fits better the algorithm.
Two main weaknesses make N-Point Crossover standout: the posi- 3.3. Portfolio Creator
tional bias and the distributional bias. The first states that when the n
value is odd (one-point crossover), there is a strong bias against keeping The Portfolio Creator Module is where the portfolio is constructed
together genes placed at opposing sides of the chromosome. The second according to the year to trade, the weights generated in the Evolu-
one, the distributional bias (which uniform crossover suffers from), tionary Algorithm, and the size of the portfolio desired. During the
represents the cases in which a specific number of genes might be more development of this work, various real-world constraints related to
likely to be transmitted than others during recombination (Bäck, Fogel, portfolio creation as well as the trading system were analyzed and
& Michalewicz, 2018; Rana, 1999). studied. Some were adopted (e.g., maximum portfolio size, when to
In this work, the selected probability of crossover (𝑃𝑐 ) was 100% refresh the portfolio, or even the weight of each company on the
to assure there was a chance to create better individuals in each portfolio) while others were not implemented since they were not
generation. In a self-adaptive scenario, the 𝑃𝑐 is determined by the aligned with the end goal of the work.
value in the chromosome. In this work, the portfolio size established was 20 companies since it
Similarly, as in the crossover operator, the mutation operator also is essential to diversify the capital into various investments to minimize
has multiple types of variations. In this work, the mutation selected the risk exposure. Not only is important to diminish risk but also having

10
R.L.d. Almeida and R.F. Neves Expert Systems With Applications 204 (2022) 117478

an over-diversified portfolio may lead to stunt returns, higher taxes, 3.5. Statistics
and possibly higher risk. Furthermore, results show that a portfolio
containing between 12 to 18 stocks will already provide more than 90%
The Statistics Module has two main goals: Calculate the fitness
of the benefits of diversification, assuming it is an equally weighted
values for the candidate solutions using the data frame received from
portfolio, which is the case in this work (Reilly, Brown, & Leeds, 2018).
the Trading Simulator Module and the fitness function (13) but also
The created portfolio for this work is also equally weighted making
calculate statistics for the simulations in order to validate and evalu-
each stock worth 5% apiece and in some of the studied test cases, there
is a renewal in the companies on a yearly basis. The portfolio is always ate the system performance. In this work, metrics such as Maximum
created, taking into account the year before entering the market. This Drawdown (MDD), Risk-Return Ratio (RRR), Sharpe Ratio, Sortino
strategy allows choosing the best companies of the year before, hoping Ratio, and the fitness function ROR were employed to evaluate the
that they will behave as well in the next year. system performance. Besides other metrics such as the number of
In order to create the portfolio, the F-Score (1), along with the transactions, Profitable Transactions (PT), Unprofitable Transactions
fundamental datasets created in the Data Preparation Module, are used (UT), Maximum Profit (MaxP), Minimum Profit (MinP), Average Profit
to score the financial ratios. The formula awards the ratios with binary (AvgP) and Average Return (AvgR) were employed to evaluate the
values according to its rules. After that, each score is multiplied by evolution of trading activity.
its corresponding weight from the chromosome to give the necessary
importance to each ratio.
After the F-Score (1) has been calculated for all the companies, they 4. Results & discussion
get ranked from highest to lowest score. Subsequently, the companies
with the best scores are selected to be part of the portfolio. This paper comprehends two central case studies: The Technical In-
vestment and the Fundamental Investment. Each case study subdivides
3.4. Trading Simulator itself into four specific cases:

1. With dynamic F-score


The Trading Simulator is a close to the real-life trading environment
2. Without dynamic F-score
responsible for training/testing the chromosomes and portfolios cre-
3. With dynamic F-score and self-improvement
ated. This simulator runs through every data point in sequence and for
4. Without dynamic F-score but with self-improvement
each allows the portfolio companies to take a position. Each company
can only have one active position meaning that if the company is On the one hand, the first two subtests examine the influence
already bought, the only positions the system is allowed to execute of adopting a fundamental/technical investment strategy combined
are to maintain the investment or to sell it. Furthermore, the simulator with using a portfolio that changes each year versus a portfolio that
invests the same amount of money into each company. At the end of
stays unchangeable throughout the whole trading period. On the other
each year, all the stocks unsold are sold, and depending on the settings
hand, the last two subtests also test the importance of using a funda-
selected, a new portfolio might be created for the upcoming year. When
mental/technical investment strategy combined with a dynamic/static
the simulation finishes, the results are sent to the Statistics Module
portfolio. However, also study the importance of adding variation
to calculate its return that serves as fitness for the chromosome and
operators probabilities into the chromosome structure. The purpose
portfolio used.
of these experiments is to understand the effect that these capacities
The Trading Simulator is responsible for two main points:
produce on trading returns. In this paper, only the subtest that achieved
the best results for each case study is going to be presented.
3.4.1. Dynamic F-Score
To test the suggested cases, the architecture and parameters pre-
The Dynamic F-Score is the name given to a feature developed
sented in Section 3 were used. The subtests were submitted to a period
to update the portfolio each year. The goal of this innovation relies
of training and testing (out of sample) using a sliding window ap-
on getting the best-performing companies from the year 𝑦 − 1 ready
proach to expose the system to different environments. The developed
to trade in the year 𝑦, hoping that their fundamentals will enable
scheme comprises blocks of one year that together comprehend data
good trading performance. When this feature is enabled, the Trading
Simulator Module “asks” the Portfolio Creator Module to build a new from 2012-01-01 to 2018-12-31. The multiple arrangements of these
portfolio for the upcoming year. blocks compose six types of sliding windows (32, 31, 22, 21, 12 and
11). Each sliding window name represents the number of training
blocks first and the number of testing after. A simple example is
3.4.2. Investment strategies
window 32 that represents three years of training and two years of
There are multiple approaches to the problem of when to take
testing. The reasoning behind the choice of those specific values relies
positions in the market. In this work, two types of strategies were
on the fact that there is a limited amount of data, and windows too
implemented: Buy and Hold and Technical Investment.
big would not allow for training and also testing. To compare the
i. The Buy and Hold strategy utilizes the portfolio created and results from different sliding windows, each composition includes the
buys stocks for each company on the first day of trading and same four years of testing. Fig. 12 represents all the types of windows
sells them all on the last day of trading. created.
ii. The Technical Investment utilizes the portfolio created and In this work, transaction costs were not considered since, in the
takes positions according to a weighted average between the current days, some brokers (e.g., Interactive Brokers) offer very small
technical indicators scores and its chromosomes weights. fees per market position, making it irrelevant to take it as a cost.
To obtain robust results, the trains/tests were repeated ten times
The result is then interpreted in the following way:
each, and the metrics introduced in the Statistics Section 3.5 were
• If the result is > 0.5, then it represents a Buy position. utilized as system validation/evaluation metrics. To understand how
• If the result is < −0.5, then it represents a Sell position. the system performance is related to a “real-life” trading method, the
• Any other result represents a Maintain position. S&P500 index prices were used as a “benchmark”.

11
R.L.d. Almeida and R.F. Neves Expert Systems With Applications 204 (2022) 117478

Fig. 12. Sliding window scheme.

Table 8
Technical investment best subtest results (without dynamic F-Score but with self-improvement).

4.1. Technical investment subtest and the same sliding window comes the best simulation with a
57.34% ROR, MDD of 7.67%, Sharpe Ratio of 2.45, RRR of 7.47, and
In this case study, the EA evolved multiple candidate solutions in a Sortino Ratio of 1.17.
order to achieve the best possible return. The candidates are composed Besides using a new approach for portfolio management, this study
of weights for the portfolio creation (fundamental representation mod- also tests the ability of the EA to self-adapt during the evolutionary
ule) and for the technical investment strategy (technical representation process. In that matter, the self-improved derivations subtests achieved
module). In the last two subcases, the candidate solutions also in- better results on average than the “normal evolution” ones in all return
cluded the variation probabilities in their representations (self-adaptive performance metrics.
representation module) to create a self-adaptive EA. The examination of Fig. 15 leads to the conclusion that all subtests
The first case study is characterized by achieving better results on were able to evolve their populations during the training sessions. On
average in the sliding window, composed of two years of training and the one hand, the simple dynamic EA achieved an average 50% ROR
two years of testing. Furthermore, this case study presents better results while its derivation (EA with self-improvement) achieved on average
on average using a non-dynamic portfolio management strategy. ROR of 45% not being able to surpass the original test. On the other
Through analysis of Figs. 13, 14 and the results Table 8 presented, hand, it is perceivable that the simple non-dynamic EA achieved a
it is possible to conclude that the technical system was able to avoid staggering 156% average ROR surpassed by its derivation test using
multiple losses and present fairly consistent profits. Thanks to the se- a self-improved EA that achieved an average 170% ROR.
lected technical indicators, the system was able to abandon the market
(creating the horizontal lines seen in the multiple figures) in multiple
situations that later proved to be declining moments. However, during 4.2. Fundamental investment
“bull markets”, this system showed some lack of “confidence” to pursue
higher returns since it would take some time to start “climbing” the In this case study, the EA also evolved multiple candidate solu-
market after declining moments. tions in order to achieve the best return possible. The candidates are
The technical case study achieved its best average simulation with- formed of weights for the portfolio creation (fundamental represen-
out using a dynamic portfolio strategy, however, it used a self-improved tation module) that is later used in the Trading Simulator Module
EA. This simulation achieved the best ROR of all average simulations with a Buy-and-Hold investment strategy. In the last two subcases,
with a 35.67% ROR, 11.90% MDD, Sharpe Ratio of 1.33, RRR of 3.62, the candidate solutions also included the variation probabilities in
Sortino Ratio of 0.63, and a sliding window of 22 that coincidentally their representations (self-adaptive representation module) to create a
shows a very similar behavior to the line of the S&P500. From the same self-adaptive EA.

12
R.L.d. Almeida and R.F. Neves Expert Systems With Applications 204 (2022) 117478

Fig. 13. Technical investment best subtest results (without dynamic F-Score but with self-improvement average simulations).

Fig. 14. Technical investment best subtest results (without dynamic F-Score but with self-improvement best simulations).

Table 9
Fundamental investment best subtest results (without dynamic F-Score but with self-improvement).

The second case study is characterized by achieving its best average developed in this work, a simple buy-and-hold investment strategy
results using two training years and one/two testing years. Addition- proved to be highly profitable. On the one hand, not having technical
ally, this case study presents better results on average using a static
indicators may have downsides since it allows the portfolio to drop
portfolio management strategy. Through analysis of Figs. 16, 17 and
multiple times during declining markets. On the other hand, during a
the results Table 9 presented, it is possible to conclude that the funda-
mental investment case study was able to achieve high profits. Thanks “bull market” the portfolio is able to achieve stellar returns since it does
to the weighted F-Score scoring system and the multiple enhancements not have a “bottleneck” to stop its profits.

13
R.L.d. Almeida and R.F. Neves Expert Systems With Applications 204 (2022) 117478

Fig. 15. Average technical training of the Evolutionary Algorithm.

Fig. 16. Fundamental investment best subtest results (without dynamic F-Score but with self-improvement average simulations).

Fig. 17. Fundamental investment best subtest results (without dynamic F-Score but with self-improvement best simulations).

14
R.L.d. Almeida and R.F. Neves Expert Systems With Applications 204 (2022) 117478

Fig. 18. Average fundamental training of the Evolutionary Algorithm.

The fundamental case study achieved its best average simulation fear or optimism in the investors. This fear/optimism then produces a
in the same subtest and sliding window as the technical case study. significant rise or decline in the companies prices, creating unexpected
This simulation produced the best ROR of all average simulations with market momentum’s.
39.49%, a 17.25% MDD, Sharpe Ratio of 1.19, RRR of 2.36, and Sortino Lastly, a relevant point to notice is that although the training
Ratio of 0.68. From the same subtest and sliding window comes the best sometimes would yield high ROR that, would not necessarily mean that
simulation with a 52.64% ROR, MDD of 13.75%, Sharpe Ratio of 1.78, their tests would be that great and vice-versa. Once again, the trading
RRR of 3.82, and Sortino Ratio of 1. market is a very complex system that is connected to the world in
In terms of self-adaptive EA, the self-dynamic subtest presents, on general. Training a system that works flawlessly for several years may
average, nearly equivalent results as the original test. However, the result in a good testing performance in some environments. However,
same does not happen in the static portfolio subtest, where its self- it does not imply that it will be able to dominate and entirely surpass
adaptive derivation shows better results in every single performance the market during testing years.
return average metric.
Through the analysis of Fig. 18, it is noticeable that during training, 5. Conclusions
the algorithm was able to evolve its population. On the one hand,
the simple dynamic EA achieved a 55% average ROR, while its self- The analysis of the results obtained in this work allows conclud-
adaptive derivation produced a nearby average value of 54% ROR as ing that Evolutionary Algorithms, combined with the stock market,
it happened in the test sessions. On the other hand, the non-dynamic represent a powerful tool when it comes to portfolio composition
subtest achieves, on average, a ROR of 53% approximately while its and technical trading. Not only that but also the capability of using
self-adaptive derivation produces a lower value around 50% ROR. multiple data sources, extracting the critical information, transforming
it into usable data to compose portfolios for trading in few seconds
4.3. Results comparison demonstrates significant potential in the developed system.
The presented results are promising and reveal that the technical
In this work, both case studies achieved better returns using a and the fundamental case studies combined with Evolutionary Algo-
self-improved EA and a static portfolio management strategy. rithms can surpass the S&P500 returns which is an extremely difficult
On the one hand, the self-improved EA results do not come as a task. Both case studies achieved their best results using a static portfolio
surprise. Including the variation operators’ parameters in the chromo- management strategy and a self-adaptive EA with returns more than
some allow the algorithm to perform a more specialized evolution since two times higher than the benchmark in both average cases. Besides,
it adapts these values according to the fitness achieved. Consequently, both subtests also achieved these results in the same sliding window
this feature brings a more efficient evolutionary process and, therefore, composed of two years of training and two years of testing.
higher returns during the testing period. On the one hand, the technical case study revealed its value dur-
On the other hand, the static portfolio results come as a negative ing “bear markets” since it is able to diminish accentuated declines.
surprise. During the elaboration of the portfolio management strategies, Nonetheless, during “bull markets”, the technical case study lacks
the dynamic approach emerged as a “logical” solution. Using the best “confidence” to pursue higher returns. On the other hand, the funda-
companies from the year before trading in the following year should mental case study shows many more declines during the “bear market”.
yield good returns. This idea demonstrated not to be always true since Nevertheless, it shows the ability to “climb” the market at a fast pace
the static portfolio strategy overcame the dynamic strategy. The main achieving significant returns during “bull market” momentum’s.
reason for this to happen may relate to market seasonality and the Overall, the proposed goals in this work were achieved, showing
world in general. While during a “bull market”, all companies tend that it is possible to surpass S&P500 using not only a fundamental
to thrive, during a “bear market”, even the best companies decline. approach but also a technical approach if combined with EA.
Not only that, but companies who thrive in specific momentum’s may In this work, the most significant system limitation is related to the
not prosper in others. The reason behind it may not only be specified time each simulation took to complete. Although much was done to
in financial statements but may also be connected to the state of decrease time complexity, there is always room for improvement.
the world. Events such as economic tensions between countries, legal Some future work improvements could be replacing the developed
agreements, wars, and scandals impact companies’ prices by creating EA with a MOEA system using two financial ratios to maximize return

15
R.L.d. Almeida and R.F. Neves Expert Systems With Applications 204 (2022) 117478

and reduce risk. Another improvement would be transferring the devel- Gorgulho, A., Neves, R., & Horta, N. (2011). Applying a GA kernel on optimizing
oped work into a faster version of Python to decrease the time it takes technical analysis rules for stock picking and portfolio composition. Expert Systems
with Applications, 38(11), 14072–14085. http://dx.doi.org/10.1016/j.eswa.2011.04.
to run each simulation. Finally, in this work, the variation operators’
216.
parameters were included in the representation for optimization. In Hsieh, T.-J., Hsiao, H.-F., & Yeh, W.-C. (2012). Mining financial distress trend data
future work, other parameters such as the “percentage of the population using penalty guided support vector machines based on hybrid of particle swarm
that takes part in elitism” could also be included in the representation optimization and artificial bee colony algorithm. Neurocomputing, 82, 196–206.
for optimization. Kim, H.-j., & Shin, K.-s. (2007). A hybrid approach based on neural networks and
genetic algorithms for detecting temporal patterns in stock markets. Applied Soft
Computing, 7(2), 569–576.
CRediT authorship contribution statement Lam, M. (2004). Neural network techniques for financial performance prediction:
Integrating fundamental and technical analysis. Decision Support Systems, 37(4),
Rodrigo Lopes de Almeida: Conceptualization, Formal analysis. 567–581. http://dx.doi.org/10.1016/S0167-9236(03)00088-5.
Levinson, M., et al. (2014). The economist guide to financial markets: Why they exist and
Rui Ferreira Neves: Formal analysis.
how they work. The Economist.
Lin, X., Yang, Z., & Song, Y. (2011). Intelligent stock trading system based on improved
Declaration of competing interest technical analysis and echo state network. Expert Systems with Applications, 38(9),
11347–11354.
The authors declare that they have no known competing finan- Malkiel, B. G., & Fama, E. F. (1970). Efficient capital markets: A review of theory and
empirical work. The Journal of Finance, 25(2), 383–417.
cial interests or personal relationships that could have appeared to Martinez, L. C., da Hora, D. N., Palotti, J. R. d. M., Meira, W., & Pappa, G. L. (2009).
influence the work reported in this paper. From an artificial neural network to a stock market day-trading system: A case
study on the bm&f bovespa. In Neural networks, 2009. IJCNN 2009. International
Acknowledgments joint conference on (pp. 2006–2013). IEEE.
Mishkin, F. S. (2007). The economics of money, banking, and financial markets. Pearson
Education.
This work is funded by FCT/MCTES through national funds and Mitchell, M. (1998). An introduction to genetic algorithms. MIT Press.
when applicable co-funded EU funds under the project UIDB/EEA/ Murphy, J. J. (1999). Technical analysis of the financial markets: A comprehensive guide
50008/2020. to trading methods and applications. Penguin.
Pinto, J. M., Neves, R. F., & Horta, N. (2015). Boosting trading strategies performance
using VIX indicator together with a dual-objective evolutionary computation
References optimizer. Expert Systems with Applications, 42(19), 6699–6716. http://dx.doi.org/
10.1016/j.eswa.2015.04.056.
Piotroski, J. D., Joos, P., Monahan, S., & Lee, C. (2002). Value investing: The use of
Achelis, S. B. (2001). Technical analysis from A to Z. McGraw Hill New York.
historical financial information. University of Chicago.
Bäck, T., Fogel, D. B., & Michalewicz, Z. (2018). Evolutionary computation 1: Basic
Rana, S. (1999). The distributional biases of crossover operators. In Proceedings of the
algorithms and operators. CRC Press.
1st annual conference on genetic and evolutionary computation-Vol. 1 (pp. 549–556).
Brasileiro, R. C., Souza, V. L., Fernandes, B. J., & Oliveira, A. L. (2013). Automatic
Morgan Kaufmann Publishers Inc..
method for stock trading combining technical analysis and the artificial bee
Reilly, F., Brown, K., & Leeds, S. (2018). Investment analysis and portfolio management.
colony algorithm. In Evolutionary computation (CEC), 2013 IEEE congress on (pp.
Cengage Learning, URL: https://books.google.pt/books?id=jdVUEAAAQBAJ.
1810–1817). IEEE.
Russell, S. J., & Norvig, P. (2016). Artificial intelligence: A modern approach. Pearson
Chen, H.-Y., Lee, C.-F., & Shih, W. K. (2016). Technical, fundamental, and combined
Education Limited.
information for separating winners from losers. Pacific-Basin Finance Journal, 39,
Schwager, J. D. (1984). A complete guide to the futures markets: Fundamental analysis,
224–242.
technical analysis, trading, spreads, and options. John Wiley & Sons.
Eiben, A. E., Smith, J. E., et al. (2003). Introduction to evolutionary computing, Vol. 53.
Silva, A., Neves, R., & Horta, N. (2015). A hybrid approach to portfolio composition
Springer.
based on fundamental and technical indicators. Expert Systems with Applications,
42(4), 2036–2048. http://dx.doi.org/10.1016/j.eswa.2014.09.050.
Soros, G. (2015). The alchemy of finance. John Wiley & Sons.
Strumeyer, G. (2017). The capital markets: Evolution of the financial ecosystem. John
Wiley & Sons.

16

You might also like