Genetic Algorithms and Applications For Stock Trading Optimization
Genetic Algorithms and Applications For Stock Trading Optimization
Vivek Kapoor
Devi Ahilya University, Indore, India
Shubhamoy Dey
Indian Institute of Management, Indore, India
Telegram
@librosselectosdetrading
@cursos_trading_rank
@ranking_trading_courses
@Libros_Trading_Algoritmico
Copyright © 2021 by IGI Global. All rights reserved. No part of this publication may be
reproduced, stored or distributed in any form or by any means, electronic or mechanical, including
photocopying, without written permission from the publisher.
Product or company names used in this set are for identification purposes only. Inclusion of the
names of the products or companies does not indicate a claim of ownership by IGI Global of the
trademark or registered trademark.
This book is published in the IGI Global book series Advances in Computational Intelligence and
Robotics (ACIR) (ISSN: 2327-0411; eISSN: 2327-042X)
Coverage
• Pattern Recognition IGI Global is currently accepting
• Automated Reasoning manuscripts for publication within this
• Evolutionary Computing series. To submit a proposal for a volume in
• Machine Learning this series, please contact our Acquisition
• Fuzzy Systems Editors at Acquisitions@igi-global.com or
• Natural Language Processing visit: http://www.igi-global.com/publish/.
• Computational Intelligence
• Algorithmic Learning
• Heuristics
• Adaptive and Complex Systems
The Advances in Computational Intelligence and Robotics (ACIR) Book Series (ISSN 2327-0411) is published by
IGI Global, 701 E. Chocolate Avenue, Hershey, PA 17033-1240, USA, www.igi-global.com. This series is composed of
titles available for purchase individually; each title is edited to be contextually exclusive from any other title within the
series. For pricing and ordering information please visit http://www.igi-global.com/book-series/advances-computational-
intelligence-robotics/73674. Postmaster: Send all address changes to above address. Copyright © 2021 IGI Global. All rights,
including translation in other languages reserved by the publisher. No part of this series may be reproduced or used in any
form or by any means – graphics, electronic, or mechanical, including photocopying, recording, taping, or information and
retrieval systems – without written permission from the publisher, except for non commercial, educational use, including
classroom teaching purposes. The views expressed in this series are those of the authors, but not necessarily of IGI Global.
Titles in this Series
For a list of additional titles in this series, please visit:
http://www.igi-global.com/book-series/advances-computational-intelligence-robotics/73674
Telegram
@librosselectosdetrading
@cursos_trading_rank
@ranking_trading_courses
@Libros_Trading_Algoritmico
Table of Contents
Preface.................................................................................................................viii
Section 1
Genetic Algorithms, Neural Networks, and Chaos Theory
Chapter 1
Introduction to Expert Systems, Fuzzy Logic, Neural Networks, and Chaos
Theory.....................................................................................................................1
Chapter 2
Introduction to Biologically Inspired Algorithms.................................................11
Chapter 3
Introduction to Genetic Algorithms in Search and Optimization.........................32
Chapter 4
Genetic Algorithms (GAs) and Their Mathematical Foundations........................54
Section 2
Genetic Algorithms Theory and its Working
Chapter 5
Genetic Algorithm (GA) Methodology and Its Internal Working........................67
Chapter 6
Understanding Genetic Algorithm (GA) Operators Step by Step.......................100
Chapter 7
Operator Control Parameters and Fine Tuning of Genetic Algorithms (GAs)...115
Chapter 8
Advance GA Operators and Techniques in Search and Optimization................128
Section 3
Genetic Algorithms in Finance
Chapter 9
Genetic Algorithms (GAs) and Stock Trading Systems.....................................154
Chapter 10
Synergistic Market Analysis, Technical Analysis, and Various Indicators.........173
Chapter 11
Using Genetic Algorithms to Develop Investment Strategies............................197
Chapter 12
Developing a Single Indicator or Multiple Indicator Market Timing System....215
Section 4
Genetic Algorithms in Other Areas
Chapter 13
Some Other Applications of Genetic Algorithms (GAs)....................................238
Chapter 14
Introduction to Some Other Nature-Inspired Algorithms...................................245
Index................................................................................................................... 261
Telegram
@librosselectosdetrading
@cursos_trading_rank
@ranking_trading_courses
@Libros_Trading_Algoritmico
viii
Preface
ix
Preface
x
Section 1
Genetic Algorithms,
Neural Networks, and
Chaos Theory
Telegram
@librosselectosdetrading
@cursos_trading_rank
@ranking_trading_courses
@Libros_Trading_Algoritmico
1
Chapter 1
Introduction to Expert
Systems, Fuzzy Logic, Neural
Networks, and Chaos Theory
ABSTRACT
The power of genetic algorithms (GAs) and related expert systems such as
fuzzy logic, neural networks, and chaos theory and other classifier systems
is truly infinite in nature. The above stated procedures are sure to happen in
the near future, and there is no chance for it not to occur. GAs, fuzzy logic,
neural networks, and chaos theory are all biologically-inspired algorithmic
procedures, as they all are linked to the world of biology in some way. Market
represents the ideas of traders. In the present environment, the market is
driven by the ideas generated by the use of these AI-based expert systems
and it is causing huge competition in making profits. This chapter is planned
to be a detailed introduction of various popular expert systems such as GAs,
neural networks, fuzzy logic, and chaos theory and their usages. Researchers
in the past have proved that these computational procedures could have far
reaching effects in the stock trading system.
1.1 INTRODUCTION
DOI: 10.4018/978-1-7998-4105-0.ch001
Copyright © 2021, IGI Global. Copying or distributing in print or electronic forms without written permission of IGI Global is prohibited.
Introduction to Expert Systems, Fuzzy Logic, Neural Networks, and Chaos Theory
type of logic i.e is one is buyer logic other is a seller logic. Both parties
should sensibly or logically justify their actions. In past years when use of
computers were of limited in nature, then theories compete with each other
at the speed of human mind. The maximum speed was what human mind
could generate logic. Today we are living in a different world or in age of
technology transformation.
Chaos theory, Neural Networks, fuzzy logic and GAs are the new soft
computing techniques by which you can beat the market and make profits in
today’s competitive scenario. These above listed techniques generate better
trading strategies with the help of computer generated logic. This helps us
to take decision at a very high speed, beating the human mind i.e with in a
fraction of a mille second.
Lot of people in the traditional stock trading community are not in favour
of this type algorithmic generated logic for trading (Lederman et.al, 1995).
Some says these techniques are not in favour of market and it should be
closely regulated. Traditional stock traders also claim that algorithmic trading
generates chaos or noisiness in the market and gives computer professional a
one-sided upper hand. The issues arising due to these procedures are of great
concern. In next paragraph I am discussing and falsifying these concerns
rose in detail.
Firstly there is not an iota of proof to prove that computerized algorithmic
trading is the reason behind the noisiness or instability in the market. Time
to time there are both bearish and bullish runs in the market. There are n
numbers of factors which contribute noisiness or chaos in the market. Due
to algorithmic trading and introduction of computers, decisions are taken
at a faster pace and trading procedures lasts for a few seconds. In contrast
introduction of computers squeezes the volatility or noisiness. In order to
conclude or falsify the claims ultimately it is the human mind that takes the
final decision.
Secondly stock market is a free space. Nobody stops you to make capital
by using some novel idea i.e with the help of computers. Stock market is
always or in most of the times is in a state of chaos. Here the idea which is
fittest in nature gives you the best results. There is no harm to use an algorithm
in combination with the processing power and hi tech speed of computer to
generate parameters or strategies that cannot be generated alone with the
human mind to make decision in the stock market.
Thirdly we are in an era of technological transformation. Those do not
adopt newer technologies or procedures will be obsolete in the years to
come. It is being observed that older traditional static methods are known to
2
Introduction to Expert Systems, Fuzzy Logic, Neural Networks, and Chaos Theory
3
Introduction to Expert Systems, Fuzzy Logic, Neural Networks, and Chaos Theory
4
Introduction to Expert Systems, Fuzzy Logic, Neural Networks, and Chaos Theory
Researchers has shown that Chaos theory, Neural networks, Fuzzy logic, GAs
(Goldberg, 2002) are newer soft computing techniques that are giving better
results as compared to traditional techniques. Implementing these techniques
is just like entering an explored valley, as whole process can change the
thinking process and view about the world.
Stock market represents the investor view. Market absorbs every new type
of information, external or internal and reacts according to it. Thus in a way
we say market is efficient (Focardi et.al, 1997). It takes a lot more effort to
beat the market. Though we can make money out of the market and beat it.
For this we should be better equipped with the latest information about the
market and newer mathematical models to predict the bearish and bullish
run of the market. Hence stock market is a lucrative space to make money
out of it. It also consists of a undesirable feature of risk and uncertainty in it.
In past a lot of researchers had discussed the concept of market efficiency
with varying claims. Some claims that these newer soft computing methods
are of no values. It is impossible to beat the market as market is inherently
efficient. Some says that any newer mathematical model has an intrinsic
value and it adds value to your investment. This debate just goes on. There
are three forms of market efficiency reported 1. Weak form, 2. Semi strong
form, 3. Strong form. We are going to explain them step by step:
1. Weak form of market efficiency: Here market represents all past prices
and trading volume history.
2. Semi strong form of market efficiency: Here prices in market represent
all publically available information.
3. Strong form of market efficiency: Here prices represent all private and
inside information. Here even inside traders cannot make profit from it.
Our biological based soft computing methods later explained in this book
are here to bet weak form of market efficiency. I am giving certain descriptions
or arguments which tell that biological based computer algorithms can beat
weak form of market efficiency:
5
Introduction to Expert Systems, Fuzzy Logic, Neural Networks, and Chaos Theory
Literature from the financial world has shown that an interest of traders
in nature inspired algorithms is increasing day by day, as they were able to
make profits from it. Thus these above state algorithms replicate the natural
living systems in order to solve the problems that cannot be solve with the help
of human mind alone. Algorithms are the set of instructions or procedures
that instructs computers to find much better solutions as compared with the
solutions obtained from the traditional techniques. Computers had got huge
processing power, while these algorithms are of heuristic (Hit and Trial)
nature. They locate useful pattern in a noisy environment and help us to
make important decisions in the financial markets. Below we are explaining
a brief description of these above stated algorithms:
There was always intuition among researchers to apply chaos theory in stock
market. Past researches have shown that they were not wrong on their part.
Stock market always represents chaos. Chaos theory is self-explanatory in
nature and can be used for prediction (Lederman et.al, 1995). Past researches
has proved that to forecast any system by using traditional techniques is not
easy. Since chaos theory cantered on chaos and is a dynamic process. Chaos
theory science has grown up exponentially and it is only due to the increasing
processing power of computers. Since procedure of calculation in chaos theory
is of repetitive in nature. High processing power of computers together with
6
Introduction to Expert Systems, Fuzzy Logic, Neural Networks, and Chaos Theory
large memory is ideal environment to implement and run chaos theory for
prediction of any system.
Neural network is also one of the nature inspired algorithm and soft computing
technique which replicates the working of neurons in the brain. Development
in the area of neural networks depends upon the understanding of working
of brain. Neural network is a parallel processing, self-adaptive algorithms
used to solve hard problems (Lederman et.al, 1995). In past, in the initial
stages of research, large expectations of exaggerated results had led to a
disappointment. But the research accelerated at a uniform pace and today’s
researchers from all over the world has significant interest in this algorithm.
Neural network is being applied due to its ability to solve complex and NP
hard problems in various fields of industry. Organizations are coming up
with various commercial software’s designed on Neural Network to solve a
particular problem in finance or in investment applications.
We had seen from the previous related literature that GAs is becoming popular
day by day (Goldberg, 2002). It is a form of artificial intelligence technique
that mimics nature. It is based on the Darwin theory of survival of the fittest.
It is a artificial intelligence technique that represents artificial life. Genetic
algorithms in its steps consist of biological evolution (i.e crossover, mutation,
selection etc.). GAs are particularly an optimization technique which is used to
optimized a parameter set of a mathematical model, rules set or virtually any
type of optimization. In stock trading system GAs can be used parameters of
a pre define trading rule or rules it. Here initial set of rules or parameters are
7
Introduction to Expert Systems, Fuzzy Logic, Neural Networks, and Chaos Theory
generated randomly. These set of rules or parameters are mated i.e through a
process of crossover and mutation to form a newer set of rules and parameters.
Now those set of rules or parameters which are better fit (fitness is defined by
fitness function) are selected for next generation of crossover and mutation
to get newer better results. This process is repeated until desires solution is
obtained or solution gets stuck up. GAs can be implemented, individually
to solve a particular problem or can be implemented with other knowledge
based systems such as neural networks, Fuzzy logic etc. GAs is heuristic
based system which replicates the system of survival of the fittest.
To put an end to this discussion in terms of artificial intelligence, there is
a clear distinction between each of these techniques; these techniques have
some slack or light similarities also. These all techniques are explained in
detail in the next chapter.
Our book is divided into four parts. First part discusses about the various
soft computing algorithms. Chaos theory, Neural Networks, Fuzzy logic and
GAs are the examples of it. These all algorithms are described in detail and
comparison between them is also made. Second part explains the external
working of GAs detail. It explains how design changes or operator parameter
changes in GAs will have an impact on the solution quality. Third part explains
how GAs can be applied to optimize trading strategies for stock market. This
whole process is described in detail. Finally the forth part, we will discuss how
GAs are applied for other applications. We will also discuss the prominent
work done by other researchers in the area of GA. In last we will also discuss
some next generation nature inspired algorithms.
First four chapters of this book explain Chaos theory, Neural Networks,
Fuzzy logic and GAs. Since this book is all about GA working. GAs is
explained in detail in the coming chapters as compared to other nature
inspired soft computing techniques. In comparison to GA explanation, other
techniques are explained in a very general way, and not in detail. Major
historical development in other techniques and development in them is also
explained. Research is moving in a very fast pace in all these NI algorithms,
but we had made an attempt to include basic and current state of art work
in all these areas in our book. Frequently asked question related to GAs are
answered in this book. Genetic Algorithms are represented as GAs popularly
in the past literature and in the research community.
8
Introduction to Expert Systems, Fuzzy Logic, Neural Networks, and Chaos Theory
Part two of this book explains the internal mechanics of GAs and its
operators. It also give us some insight about the advance operators of GA.
Chapter 5 and 6 explains GAs in simple executable steps. Some experiments
done about the internal working of GA are explained in this chapter. After
discussing the internal working of GA, we turn our attention towards advance
GAs operators used in search and optimization in chapter 8.
Part three of this book helps us to apply GA to find various attractive stock
trading strategies. Chapter 10 gives insight to various technical indicators
used to forecast and to tell when to invest and when to divest from the
market. This chapter also explains the methodology of the popular technical
indicators often used in the investment literature. Here the explanation is of
very general in nature. Chapter 12 explains how GAs can be applied to find
attractive parameters for various technical indicators to get better rewards. It
help us to find how GAs is employed to find optimal trading rule parameter,
but it is only a starting point.
This book closes with part four portion which speculate about some other
application of GAs and other explanation of newer nature inspired algorithms,
which has come into the picture.
The whole content of this book is process oriented. Rather than result
oriented. The method here shows that how GA can be applied to search
attractive trading strategies parameters of a single indicator based system
or multiple indicator based system also. Because our book is all about GA,
hence explanation of GAs is by far the largest. But the readers or researchers
interested in other nature inspired algorithms will see plenty of literature about
in our book. My best wishes to the readers to move into the exciting world
of GAs and its application in stock trading systems. Those who will be left
behind will bite the dust. This is my perception about this book.
Telegram
@librosselectosdetrading
@cursos_trading_rank
9
@ranking_trading_courses
@Libros_Trading_Algoritmico
Introduction to Expert Systems, Fuzzy Logic, Neural Networks, and Chaos Theory
REFERENCES
Focardi, S., & Jonas, C. (1997). Modeling the Market- New Theories and
Techniques, Frank J. Fabozzi Associates.
Goldberg (2002). Genetic Algorithms in Search, Optimization and Machine
Learning. Pearson Education.
Lederman, J., & Klein, R. A. (1995). Virtual Trading- How any trader with
a PC can use the power of Neural Nets and Expert Systems to boast Trading
Profits. Probus Publishing Company.
Meredith, J., Shafer, S., & Turban, E. (2002). Quantitative. Business Modeling.
South Western Thomson Learning.
Telegram
@librosselectosdetrading
@cursos_trading_rank
@ranking_trading_courses
@Libros_Trading_Algoritmico
10
11
Chapter 2
Introduction to Biologically
Inspired Algorithms
ABSTRACT
In order to find more sophisticated ways to remain in competition in the
stock market, investors and analysts are finding procedures based on nature-
inspired artificial intelligence-based algorithms. It is seen that interest of
researchers has grown in these technologies in the past years. These newer
techniques have changed the investment arena of the stock market. A lot
of thought process, hard work, creativeness, and knowledge about these
algorithms are required to implement them in the stock investment area. In
the past, few people have had the privilege to implement and obtain better
results by using these algorithms. But with the access to affordable computing
systems and experts with the knowledge of these computing systems, we can
take advantage of making profit from the market. This chapter explains the
detail working of these AI techniques such as chaos theory, neural networks,
fuzzy logic, and genetic algorithms in detail.
2.1 INTRODUCTION
DOI: 10.4018/978-1-7998-4105-0.ch002
Copyright © 2021, IGI Global. Copying or distributing in print or electronic forms without written permission of IGI Global is prohibited.
Introduction to Biologically Inspired Algorithms
less time consuming. It took really long time by the trading and investment
community to accept that AI can be applied to stock trading environment.
There were practical reasons for it. First traders found altogether new field
which AI represents and it was difficult for them to understand its nutty gritty.
Second there was no radically software available to get the results. Third
in the initial phase there was absence of hardware and processing power to
implement AI based techniques as they were computationally intensive in
nature (Lederman et.al, 1995).
To start with the years of main frame computers, there were languages
such as BASIC, FORTRAN, Pascal and COBOL to implement. Researchers
used to write code of the logic generated by them in these languages. After the
invention of personal computers, similar programs or codes were run on new
and powerful processing machines. This trend continues and later advance
software tools to implement trading systems come into picture. These tools
were based on various programming languages and have better data handling
and graphic capabilities. These tools help us to write codes to implement and
test mathematical formulas of any technical indicator together with the use of
simple IF…..Then rules. These rules were tested on past historic data to test
their viability. For example with the help of these tools one can write code and
implement rule. (e.g. If present price crosses the n day moving average line in
the upward direction then buy signal is generated, if it crosses in downward
direction then sell signal is generated). This is a knowledge based system on
which AI technique can be applied (Focardi et.al, 1997).
With the increase in the processing power of computers and workstations,
many more complex rules can be implemented and tested. Thus these rules
based systems are replaced by the knowledge based systems, which uses
combination of both rule based and artificial engineering. Here advance
programming languages such as PROLOG and LISP comes into picture
(Meredith et.al, 2002). As various AI based soft computing algorithms such
as GAs, Neural Networks, Fuzzy logic and Chaos theory comes into picture
interests of the trading community increases (Baur, 1994). Researchers in their
results have found that these techniques were profitable and locate profitable
pattern in the noisy stock data just like a able stock trader. Thus as the years
passed by, various innovative commercial software comes into existence
and they grab hearts and minds of the stock traders. Thus in this way a large
number of stock traders began to use these commercially available software’s.
Hence in this way artificial engineering and knowledge based systems gets
a strong foothold in the non-so technical stock trading community. Now a
dys more and more stock traders are using it and making profit through it.
12
Introduction to Biologically Inspired Algorithms
13
Introduction to Biologically Inspired Algorithms
wildest imaginations. Myth is that these algorithms are generally a black box
technique, which does not require much of the system knowledge information.
These algorithms are mystical, as they add a feature of randomness in their
working. They all promise potentially profitable strategies or rules. Here
the process of system development requires a large part of work to be done
on the trader part itself. In the coming section we will take a deeper look at
these technologies through a futuristic window.
Knowledge based systems (also known as expert systems) is a logical rule based
reasoning that mimic if.........else type of logical thinking (Deurgio, 1998).
The rule can be of crisp logic or true false in nature also. In addition to the
financial systems knowledge based systems are being used to develop a game,
play chess, used in medical diagnosis, prove certain mathematical theorems
etc. Though there is a very little work published about the implementation
of knowledge based systems in stock trading area, but some implementation
in finding asset allocation, rating of bonds, mutual fund trading etc can be
found. There are reports that these proven systems are used among private
or individual traders.
There are three components of knowledge based systems which are explained
in detail below: 1. Inference Engine 2. Rule Based 3. Data base.
1. Inference Engine: This is the main core of the system. The inference
engine processes the rules and finds the exact results for the problem.
Inference engine consists of set of rules or facts, which generate results
or achieve a particular goal. Result here is a new conclusion generated
from the previous facts or a new set of rules generated from the previous
rules.
14
Introduction to Biologically Inspired Algorithms
3. Data Base: It consist of past or historic data of the problem that is being
addressed by the knowledge based expert system. Our rule set and
reasoning function will be applied on that particular data to find solution
of the problem. From this he can make an inference that whether he can
apply that rule set for future data or not to generate profit.
Initial rule sets are the basis of knowledge based systems. These rule sets are
constructed by a field expert having a vast amount of knowledge in that field.
Inference engine is constructed by using popular logic based programming
language such as PROLOG, LISP etc. Programmer cast the rule by using
one of the programming languages in which he is comfortable. Services of
one or more than one expert having knowledge of that domain is desirable
to construct knowledge based system and see how well the inference of
knowledge based system performs and right decision can be made from it.
The above rule set formed is not of self evolving in nature as seen in other
techniques. But in order to have these inference engine relevant rules has to
be changed manually from time to time, as market condition changes. Well
defined rules will lead to better and accurate result.
The performance of knowledge based systems depends upon the
consciousness, clear cut mind set, subject knowledge level and experience
15
Introduction to Biologically Inspired Algorithms
of domain experts. We would avoid experts the experts who generate rules
by mere thinking or by instincts. There should be synergy between the rules
formed, proper implementation of it will lead to better and accurate results.
Thus results obtained will match with the results generated by traders, when
he is doing trading by himself. Continuous testing and changes in rule set
will fine tune the system according to the market conditions. That is why
knowledge based system is run on the historic or past data. If it generates
better results according to our expectations then it is used for future use.
Otherwise we should modify the rule set and newer rules should be inserted
and older rules should be deleted to improve its performance.
There are several reasons that knowledge based systems has not gain popularity
as compared to other soft computing based systems. Since formulation of
rule set in knowledge based systems depends upon the expert we had roped
in. Thus there is really lack of experts in the area of stock trading system that
can generate profitable rules. Second knowledge based system is not flexible
in nature i.e changes in them has to done manually from time to time and are
not of self-evolving in nature. Knowledge based systems are brittle in nature
and in their working too. You really need intervention of some expert to
change the rule set and to make it relevant in the changing market condition.
If set of rules formulation depends upon the particular patterns to make
inference, then you should implement a hybrid system which will use another
algorithm to formulate the pattern in the past data. Other drawback is that if
a rule set is formed by the expert with a proven track record generates huge
losses, and then you had to start fresh as a whole. Knowledge based systems
are not of adaptive in nature. You really need human intervention to make
these knowledge based system relevant to the changing market conditions.
Thus rules in the knowledge based system should be updated from time to
time. Otherwise knowledge based system will go in vain and will be obsolete
very soon.
Anyone who deals with the stock market must have seen various types of
vibrations and confusing trends in the market. Thus market represents chaos as
16
Introduction to Biologically Inspired Algorithms
1. Past researches has shown that with the help of Chaos theory forecasting
in turbulent phase of market is possible with a high degree of accuracy.
2. After a period of stability, some degree of turbulence entered in the
market. This is a indication that one should take quick decision during
that period.
3. Chaos theory provide improved analysis behaviour as it takes into
consideration of various other financial relationships.
Fuzzy Logic system is just like a traditional “Crisp Logic”, which is used
to draw rules, inferences that come to some conclusions (Rajasekaran et.al,
2007). Fuzzy Logic is successful and popular because it expresses the
statement with a certain degree of indistinctness. These statements are not
fully in black and white, but they contain grey shades in them. Expression
of Fuzzy Logic statements include the terms “Slightly above”, “very much
below”. These statements cannot be totally true or totally false, but true or
false to a greater or lesser degree. It is often very difficult to represents such
grey shades of reasoning in traditional knowledge based systems as discussed
17
Introduction to Biologically Inspired Algorithms
2.5.1 History
Fuzzy logic is first generated from the theory of fuzzy sets by mathematician
named Lotfi Zadoh. It is somewhat similar to the traditional knowledge based
systems as studied earlier. Here also you have to take services of an expert to
form rules and to implement it with the use of technology. Various components
of Fuzzy logic system is similar to the traditional knowledge based system
such as inference engine, data base and rule set. The only difference between
knowledge based system and Fuzzy logic based system is that here rules
represents certain degree of greyness i.e they are made up of crisp logic and
they contain certain degree of uncertainty in it. Due to this reason system
developers are attracted towards it and are spending more time and energy
in implementing fuzziness in the rule.
Here in order to incorporate fuzziness in our rule “greater than” and “less than”
phrase will be replaced by “slightly high” and “slightly less”. For example in
a traditional based system we consider a rule “If ratio of closing price of stock
and its Moving average os greater than 0.5 value of the technical indicator
than buy”. Here if the ratio comes out to be 0.6 then according to the rule
we should buy. There are various other numbers between 0 and 1 scale for
example 0, 0.1, 0.2, 0.3,………0.7, 0.8, 0.9, 1.0. Here in fuzzy system we
have two new terms such as “slightly high” and “slightly Low”. Hence value
between 0.3 to 0.5 is considered to slightly above while value between 0.5
to 0.7 is considered to be slightly above. Thus in this way a new crisp set or
fuzzy set of slightly above and slightly below values are created. Here we had
to specify the degree of truth which each number is the member. Thus in this
way we had grey shades in our expression. Thus with the values between 0
and 1 we can define membership function. The whole process of assignment
is called fuzzy frication. Thus in this way vagueness in the expression is
defined and represented.
Consider the Figure 1.
Closing price to the moving average Vs Degree of membership X axis
represents ratio of closing price to the moving average and y axis represents
18
Introduction to Biologically Inspired Algorithms
Figure 1.
2.5.3 Advantages
19
Introduction to Biologically Inspired Algorithms
2.5.4 Disadvantages
20
Introduction to Biologically Inspired Algorithms
Neural network mimics the function of human brain. Now we will discuss
the working of human brain. In brain there are various nerve cells known as
neurons. Human brain consists of various types and sizes of neuron which
have various nerves called dendrites hanging or connected to other neurons.
Signals are carried between various neurons through these dendrites. Nerve
signals are of binary in nature. Neurons calculate each of the incoming
signals. If the signal sum crosses the onset value, then the signal is passed
to the other neuron or discarded.
Human brain consists of complex structure of neurons connected to each
other in n number of ways. Due to this human brain act like a multi-processor
and performs various human related tasks in a single period of time or act
like a parallel processing system. We replicate this process of human brain
in our neural network system. Neural network can be implemented in a
hardware where electronic circuit replicate the working of neurons or it can
be implemented by using a programming language in a software mode.
In our neural network terminology neuron is referred as term node. Here
input signals are taken and output signals are generated. Various weights are
assigned to input signals and they are sum up to produce the output. A simple
modus operandi of simple neural network is shown in Figure 2.
Now we discuss the steps that occur in between input and output. i.e in the
nodes. Initially weights are assigned to the input signals in a random fashion.
Neural networks are self-adaptive in nature, so the values of these weights
will alter in successive iterations. There are altogether number of methods
21
Introduction to Biologically Inspired Algorithms
which can be used to adjust weights assigned to the input layers. Generally
weights are multiplied and summation is done.
Neural Network is a layered structure. Neural Network architecture can be
of different sizes. It can have two input variables to a few hundred variables.
It can have from to two to three layers to a dozen of layers. There can be n
combination between input variable and number of layers in neural network.
It depends upon the problem to be solved and computational complexity a
machine can handle. Past researches had found that three to four numbers
of layers are sufficient to solve any given problem. Addition of more layers
does not have much impact on the solution quality, but it increases the time
to generate the results by few seconds depending upon the problem. Number
of input variables, neurons and layers vary upon the problem which we are
solving.
Let us say our neural network model has two layer of nodes as shown in
Figure 3.
Inputs are given to the input layers which are passed to the second layer.
The output of the input layer is passed to the second layer and from it to the
third layer and finally to the output layer. From this user gets output from
22
Introduction to Biologically Inspired Algorithms
the network. The intermediate layers between input and output are known
as hidden layer. These layers neither receive direct inputs and they neither
give direct output to the outer world. They are not directly connected to the
outside world.
As shown in the above figure all the nodes in the neural network are
connected to each other directly or indirectly. The connection can be made
to each other in a variety of fashion. There can be many input signals but
it can have only one output signal. This output signal from a node can be
transmitted or forwarded to the other node in the next layer. This type of
neural network is known as feed forward network. When an output signal
is transmitted backward, then it is known as feedback network. Increase in
number of nodes will lead to the increase in number of possible ways in
which connection can be made.
Hidden layers are not connected to the outside world, but they contain
knowledge value in them, hence they are important. There is no thumb rule
to find the number of hidden layer in the neural network architecture and in
what ways they can be connected to each other. These layers remove noisiness
or error from the information or data as it moves from layer to layer in the
hidden network.
Now we will discuss what happens in the node. The learning takes place at
the node. The weights of the node are adjusted, and due to the self-adaptive
nature of neural network, thus desired output is generated. One of the methods
for weight correction is known as back propagation. In this difference in
value between actual output and required output is measured or calculated.
Thus using these values weight of the output layer is adjusted. This entire
process is repeated n number of times. There are two types of learning process
supervised and unsupervised. In unsupervised learning the weights of the
system adjust by themselves i.e system teaches to itself. In case of supervised
learning process weights are steadily adjusted to produce required output.
Thus adjustments of weights are done repeatedly in many training cycles.
Due to this error between actual data and desired data is minimized. When
error is squeezed up to an acceptable level then training cycle is said to be
complete. The final weights in this case are used to find output for next set
of input data.
Advantages of using Neural Network are that they can integrate large amount
of information to get the desired output. Neural Network architecture is such
that it learns from past experience and is self-adaptive. It does not depend upon
the expertize to be given by the expert traders in case of knowledge based
systems and Fuzzy Logic. Neural Network when properly used has got ability
23
Introduction to Biologically Inspired Algorithms
to pinpoint profitable patterns that exists in the market data. Making profitable
strategies from neural network is not an easy task. Neural Network is a trial
and error activity which requires a high degree of sophistication. It requires
hard work and dedication. As we had studied Efficient market Hypothesis
(EMH) earlier which states that one cannot beat the market. It is not totally
true but partially true. There are numerous tiny profitable patterns hidden in
the noisiness of the stock data which would be exploited and capitalized to
make profit. This all requires a lot of hard work and proper implementation
of Neural Network. Past researches have shown that to beat EMH partially
is not impossible with the help of Neural Network.
2.7.1 History
24
Introduction to Biologically Inspired Algorithms
1990’s. During this period a lot of commercial and user friendly software’s
based on GA comes into existence. For example Evolver, LOGIVOLVE etc.
Various other software’s that used combination of GA and Neural network to
generate profitable strategies which is known by the term “neurogentics” are
also in the market. Here we use GA to optimize weights of neural networks
in back propagation method.
Santa Fe institute developed a computer-generated stock market. Here
traders were actually a computer programs which do trading of some virtual
stocks that were distributed between them. In this project GA is discussed
in detail. Some articles also discussed that how GA can be used to evolve
new trading rules in stock market. Initially rules were generated using LISP
rules and GA was used to optimize these rule sets. Past researches give us
an indication that interests of stock traders in GA is increasing day by day.
GA’s are general purpose algorithms till not graphical user interface of GA
comes into existence. Various computer programming languages provides
flexibility by which they could implement GA to solve a particular problem.
In fact neural network is the past and GA’s are the present. Here later in our
book we will discuss how GA’s can be used to optimize a trading system either
in the form of a rule set or parameter set of a rule. In the coming section we
will see how GA could be used to optimize a stock trading system briefly.
Detail description will be done in the latter half of this book.
25
Introduction to Biologically Inspired Algorithms
26
Introduction to Biologically Inspired Algorithms
27
Introduction to Biologically Inspired Algorithms
Parent A : A1.A2.A3.A4
Parent B : B1.B 2.B 3.B 4
Crossover Process
Offspring A : 17.22.11.3
→ Tobe replaced
Offspring B : 27.20.53.7
After mutation of the two member integer in the offspring A and B, will
be replaced by some other integer.
Offspring A : 17.29.11.3
→ Tobe replaced
Offspring B : 27.20.53.2
The basic theory about crossover is that if the moving averages of parents
are good and profit generating if used. Then by the process of recombination
it will generate better offspring which will generate higher profits. There
is also a possibility that it may not work. But good feature of two systems
recombined in a simpler way will generate a better system or parameter sets.
Hence cross over is useful. The particular position we take from each parent
is determined randomly and it varies each time mating is done or crossover
process occurs.
Basic engineering of mutation is that it introduces diversity in the population,
thus preventing chromosomes from being stagnant. Due to mutation newer
patterns or integers will appear in the population which leads to search newer
28
Introduction to Biologically Inspired Algorithms
spaces and better solutions will be reported. There may be many patterns
which when recombined with the existing patterns or integers will give a great
solution. Hence introduction of these patterns in the chromosomes of the
population is done by the process of mutation. Thus random recombination of
the existing chromosomes (Crossover) and introduction of random fragments
in the chromosomes (Mutation) encapsulated by the selection operator navigate
altogether a random procedure in the right direction.
There are many other advance genetic operators which we will discuss
later in this book, which can be used in combination with crossover, mutation
and selection operator to generate optimal solution. There is no fixed schema
which tells us that all these operators can be used in such a fixed pattern. The
different combination of the use of these operators in GA varies from problem
to problem. Past researches has shown that standard use of together crossover
29
Introduction to Biologically Inspired Algorithms
2.8 CONCLUSION
REFERENCES
30
Introduction to Biologically Inspired Algorithms
Meredith, J., Shafer, S., & Turban, E. (2002). Quantative Business Modeling.
South Western Thomson Learning.
Rajasekaran & Vijaylakshmi Pai (2007). Neural Networks, Fuzzy Logic,
and Genetic algorithms, Synthesis and Applications. Prentice-Hall of India
Private Limited.
31
32
Chapter 3
Introduction to Genetic
Algorithms in Search
and Optimization
ABSTRACT
This chapter is all about introducing genetic algorithms in the search process,
which are based on the theory of natural selection, genetics, and survival
of fittest. By detailed understanding of the algorithm, one would be able to
apply it in your respective field for optimization. At the end of this chapter,
the reader will have acquired basic theory and working of these algorithms.
Since genetic algorithms are used in diverse fields, the tone and language
of this chapter is kept simple and casual for better understanding. Genetic
algorithms in this chapter are applied through a hand calculation example.
Genetic algorithms are basically mathematical calculations based on Darwin’s
theory of survival of fittest. This chapter gives a detailed understanding of
the theory and working of genetic algorithms based on hand calculation
examples. Comparison of genetic algorithms with other search procedures
is also done.
DOI: 10.4018/978-1-7998-4105-0.ch003
Copyright © 2021, IGI Global. Copying or distributing in print or electronic forms without written permission of IGI Global is prohibited.
Introduction to Genetic Algorithms in Search and Optimization
each other and some random string patterns are also introduced in it to form
new strings. This is a innovative search procedure which searches various
vantage points parallel through this recombination and randomization process.
These vantage or superior solutions cannot be finding alone with the help of
human mind. Here the solution of the problem is represented or mapped into
bit of strings or by alpha numeric characters etc. After every generation new
set of superior solutions are created by recombination of various other fittest
old solutions. While recombination and introduction of bit strings is a fully
random process. But due to the introduction of selection operator, it is not
a simple random walk. These two procedures in genetic algorithms search
various points in the solution space parallely and found new search points
with a superior performance which cannot be found manually.
Initially genetic algorithms and its procedure are founded by John Holland
(1975) and his students at university of Michigan. This algorithm mimics
natural adaptive process mathematically and is implemented with the help of a
computer program. This has leads to the advancement in artificial intelligence
based search procedures.
Researchers have found genetic algorithms to be effective, robust in all
environments. Genetic Algorithms provides a delicate balance between its
productiveness and effectiveness (to produce desired effect) which is essential
to remain in competition in various adverse environments. Robustness i.e to
produce desired results should be an inherent property for artificial intelligence
systems. Property of robustness in a artificial intelligence system reduces
the cost of design. If a particular system is adaptive in nature then result
given by it will be for longer duration. Hence the algorithm designers should
take a note that this system can only excel if it contain properties such as
robustness, competence and springiness. These all features along with the
feature of addictiveness and to find new solutions are found in nature. Genetic
Algorithm mimics these entire features from the nature which is rare in other
soft computing technique found so far. Thus the popular notion is that no
one can beat the nature as nature is robust, self-adaptive and self-repairing.
Past researches in genetic algorithms has shown that it provides robust
and fascinating results when applied to complex problems. Past published
research has shown that GA is effectively used to solve problem in the field
of business, economics, engineering and scientific applications. Reason for
the popularity of genetic algorithms is that the steps involved to implement
genetic algorithms are simple and it do parallel search in various points at a
33
Introduction to Genetic Algorithms in Search and Optimization
when compared with the neighbourhood points in the search space. Figure
1 shows a complete picture of local and global optima.
In these procedures if we get trapped in the lower optima then we will
miss the global solution or the peak. Hence there are no features in calculus
34
Introduction to Genetic Algorithms in Search and Optimization
based system to get out of these local peaks and find the global peak. Further
improvement of result can only be done by starting fresh or by a random
restart. These two functions above in the figure are one peak or two peak
35
Introduction to Genetic Algorithms in Search and Optimization
not very encouraging and efficient. Genetic Algorithms is not fully random
search procedure but a randomize search technique. Genetic Algorithms use
random tool to search various points in parallel at a given point of time in
a highly noisy and multidimensional search space. Use of random function
as a guide in search space seems to be very strange, but real world problems
consists of many such cases. Simulated annealing is one such type of random
search technique which helps us to find minima or maxima points in a search
space. One thing is clear that random search procedure uses random function
to exploit the parameter search space and is not totally a directionless search
technique.
As we had done an exhaustive search on comparison of these traditional
techniques, we found then that they are not robust in nature. This does not
mean that these traditional techniques must be discarded. These techniques
can be used in many simpler applications, while complex application may
need many hybrid applications.
If we compare all the three schemes we discussed earlier i.e specialized,
enumerative and robust scheme for various problems. We found that past
researches have shown that robust schemes perform well for complex
problems. Enumerative schemes perform well for simpler or particular set of
problems. Even the hybrid system created by joining two or more optimization
techniques gives good result as compared to enumerative or random walk
technique. Later part of this book will show that how genetic algorithms are
robust when applied in any way and fill the gap created by these schemes.
36
Introduction to Genetic Algorithms in Search and Optimization
them from quality of solutions that had found not by the procedure or by
their internal process.
For example consider a case of stock trader (Bauer, 1994). How do we find
that the decision taken by him is good or bad? It depends upon the amount of
profit he has earned or not. If all the traders in the community are earning profit
then he will be judged by the ranking he achieves in the trading community
or by the amount of profit he has earned. What was his overall efficiency? In
real world, optimization is just like to obtain better results from the previous
ones or relative better solutions than find until so far. Thus importance of
optimization is that, we do a little bit of improvement in satisfying level of
performance. Higher degree of optimization means attaining perfection in
a whole. In next section we will see how Genetic Algorithms is better with
other traditional techniques. We will also study that how GA will help us to
achieve higher degree of optimization i.e perfection.
1. In GA parameter set or rule set are coded or mapped into binary strings
or alpha numeric characters. Thus GA optimized these coded or mapped
strings not the actual parameters or rule set.
2. In GA we have a well-defined fitness function. The quality of string is
judged by the fitness score of that string not by other supplementary
knowledge of the system.
3. In a given search space the GA procedure search parallel in various
number of points, not a single point.
4. GA use probabilistic or is a random walk algorithm. It does not find
fixed or distinct rules.
37
Introduction to Genetic Algorithms in Search and Optimization
01011
11001
00101
11000
38
Introduction to Genetic Algorithms in Search and Optimization
39
Introduction to Genetic Algorithms in Search and Optimization
attractive solutions for various problems whose best solutions are not known
so far or NP hard problems.
The search procedure in GA is based on Darwin theory of survival of
fittest. The population is worked by various operators until superior solutions
rule the population. The GA procedure consists of various steps which can
be combined and implemented in various permutations and combinations.
The main purpose of this chapter is to give you a broad over view of GA and
its manual implementation.
Study of genetics is all about past physical features of our fore fathers. In
genetic science we do research about the working of genes and how their
features are transmitted from one generation to other.
All the living being is made up of cells which contain in them the past
inherited features. These cells are in form of a grouping and these structures
are known as chromosomes. Thus the hereditary information is coded within
genes and chromosomes and infinite number of combination can come up from
this information. This genetic system of each organism is called a genotype.
Probability of our survival, development and our working efficiency is
determined by this genotype. This genotype is the coded structure while the
decoded structure is known as phenotype. Thus genes are the coded structure.
Two persons may have almost same genes, while some minor changes in
genotype will make substantial changes in phenotype. Human beings generally
consist of 46 pair of chromosomes out of which 23 come from mother side
and 23 comes from father side. In biology each chromosomes member moves
in a pair and exchange their genes. This process is known as crossover. Thus
in a pair of 23 genes only one gene either from father side or mother side is
dominant in each parameter, which is transmitted to the future generation.
Thus crossover does not produce new genes, but new pair of genes or genetic
material. Thus there can be nearly 19 trillion different combinations of male
and female genes. Thus all individuals in this world are unique.
Thus there is copying of genetic material from one generation to other.
In the process of copying certain amount of alterations or imperfections are
added to it, which is known as mutation. Possibility of mutation is very less,
but it generally adds much needed genetic diversity in the population of genes.
Short term effect due to mutation is very less, but in a long run it leads to
noteworthy changes in maintaining genetic population diversity.
40
Introduction to Genetic Algorithms in Search and Optimization
41
Introduction to Genetic Algorithms in Search and Optimization
Step 1: First initial population size has to be decided. For example we had set
population size to five. We will use random function to generate bits of
5 bit strings of the solution. We will flip the coin to see if bit generated
is 0 or 1. For example if our five individual strings are: 10000, 00110,
00001, 10001, 11000. After converting these binary strings into decimal
equivalent we get 16, 6, 1, 17 and 24. Every time we run this part of
program in computer we will get different binary strings as these strings
are produced using random number generator. The problem which we
had taken is very simple one. Real world problems are of complex in
nature. Here five bit representation of string will have at most 25 potential
solutions. But in real world complex problems will have trillions of
42
Introduction to Genetic Algorithms in Search and Optimization
GA’s are designed in such a way that fitness values of individuals or average
Fitness Score
Expected Actual Count
Sr. No. Binary String Decimal Equivalent f1/∑f1
Count f1/ for Selection
f9Avg.)
1 10000 16 0.25 1.25 1
2 00110 6 0.0937 0.4687 1
3 00001 1 0.0156 0.0781 0
4 10001 17 0.2656 1.3281 1
5 11000 24 0.375 1.875 2
SUM 64
Average 12.8
Max. 24
In our above example fifth string has highest fitness and fitness score is
1.875. While 2nd string has lowest fitness score of 0.0781. This calculation
43
Introduction to Genetic Algorithms in Search and Optimization
of fitness score is actually sampling sequence, which will be done for all
individuals of population in every generation. Thus next generation individuals
will again be judged by their fitness score and sampling sequence will be
applied to them as well.
Step 4: Here next generation individuals are generated from present population
pool by using various operators. There are a variety of traditional and
advance level operators, which we will study later in this book. Two
of the most powerful operators inspired by biology are crossover and
mutation. In case of crossover operator selection process will choose two
random strings from the parent pool depending upon their fitness score.
In our case suppose 2nd and 5th string i.e 00110 and 11000 are chosen.
After this we will randomly choose a point in between the string to cut
it into two parts. Now the two strings look like 00—110 and 11—000.
Now weather crossover will be performed or not will be defined by the
probability decided by us. If we decide probability of crossover to be
0.75 then we will generate a random number between 1 and 100, if its
value comes between 1 and 75 then we will perform crossover and we
will exchange the head and tails of the two strings selected. Here head
of first string will be combined with the tail of second string and vice
versa. Our strings now become 00000 and 11110 which corresponds
to the value 0 and 2 + 4 + 8 + 16 i.e 30. Thus it is to be seen crossover
resulted in to creating fit individual near to the optimal solution.
44
Introduction to Genetic Algorithms in Search and Optimization
i.e 0.01% i.e only 10 bit in 1000 bit. Mutation helps us to add much needed
genetic diversity to our population. It takes the search procedure into slightly
different direction. Researchers have found that high mutation rates take the
search procedure just like a random walk.
Thus it is seen that by using these two operators we transform the population
towards higher fitness values generations after generations. If a particular bit
pattern is needed or is optimal, then with the help of selection operators, the
individuals having that bit pattern are selected repeatedly for crossover and
mutation to produce individuals for next generations. Since selection of a
individual depends upon the fitness score of the individual. Hence crossover
gives some guarantee that a particular bit pattern will be passed on to the
population of next generation. Thus with the help of selection operator we
are also taking consideration of the fitness score of individuals of previous
generations.
Step 5: After completing this whole procedure return to the step 2 and repeat
step 2 to step 4 procedure until population converges or optimal values
are generated. Since selection procedure is taking place based upon the
fitness score of individual string. Due to it good string drives out bad
string and bad string drives out ugly string and so on. Thus bad string
is replaced by good string and good string is replaced by best string as
generations passes by. Crossover also stuff the optimal string pattern
into various individuals strings thus driving out bad string pattern. This
process is repeated again and again till optimal string is obtained or
homogeneity in the population is reached. If all string in the population
is of same pattern, then crossover will not be useful. Then only mutation
can add much needed genetic diversity to the population. If all strings in
the population are homogeneous and optimal then mutation will act as a
spoiler. Here application of mutation operator will destroy the situation
and will not improve it. Mathematical model to represent crossover and
mutation operators are explained in the next chapter.
45
Introduction to Genetic Algorithms in Search and Optimization
Fitness Score
Binary String Actual
Decimal Expected % of
String No. Randomly f1/∑f1 Count for
Equivalent Count f1/ Total
Generated Selection
f9Avg.)
1 10000 16 0.25 1.25 1 25
2 00110 6 0.0937 0.4687 1 9.3
3 00001 1 0.0156 0.0781 0 1.5
4 10001 17 0,2656 1.3281 1 26.5
5 11000 24 0.375 1.875 2 37.5
Sum 64
Average 12.8
Maximum 24
46
Introduction to Genetic Algorithms in Search and Optimization
for mating and to pass their genes into next generation. Here roulette wheel
selection technique as shown in fig. below is the most popular.
After the selection of strings with roulette wheel selection technique, we
perform crossover and mutation operations on them. In crossover strings are
selected randomly and mated by using randomly selected sites within the
string. Seeing the above given table two strings 10000 and 00110 are selected
for crossover, the crossover site is 1, which will yield two new strings 10110
and 00000. The results of the other string that are crossed are seen in Table 3.
The last operator mutation is done bit by bit basis with a very low frequency.
If probability of mutation is 0.01, with 25 bit we expect 25 × 0.01 / 100 =
2,5 bits will undergo mutation in every generation. Our by hand simulation
procedure shows that an 2 bit mutation occurs i.e changes from 0 to 1 had
taken place.
47
Introduction to Genetic Algorithms in Search and Optimization
Crossover
Mating Pool (Crossover Site F(x)
New Population
Site Shown) (Randomly Value
Selected)
1 l 0000 (16) 1 10110 22
0 l 0110 (6) 1 00000 0
Mutation
00001 (1) 17
10001
100 l 01 (17) 3 10000 16
Mutation
110 l 00 (24) 3 29
11101
SUM 84
AVERAGE 16.8
MAXIMUM 29
48
Introduction to Genetic Algorithms in Search and Optimization
It has been clearly seen in the previous section that mystery about the operations
in GA is cleared by study of building blocks. The theory about building
blocks and its mathematical concepts are clearly explained in next chapter.
Since GA is a combination of natural biology system and computer science
terms. Until now we have seen the working of strings in GA. We talked about
crossover, string position and mutation in GA. In this section we will see how
these terms are replica of terms used in biology. Here term “String” used in
genetic algorithm is a replica of term “Chromosome” in biological system.
In case of nature chromosome gives the genetic system of the organism. The
genetic system is called “Genotype”. Similarly in genetic algorithm analogous
to this term “genotype” we called it by the term “Structure”.
In biological system organism formed by combination of chromosome
or genetic system is called phenotype. While in case of GA decoded string
is known as parameter set, or solution alternative. Coding procedures of the
string in genetic algorithms is generally numeric in nature. In natural system
we say chromosomes consist of genes, which takes some values called alleles.
Thus gene position is identified by gene function and it is given by locus.
While in case of GA chromosomes are represented as strings. String consists
of values. These values depend upon the binary bit positions in the string.
The comparison between natural and genetic algorithm is given in Table 4.
49
Introduction to Genetic Algorithms in Search and Optimization
50
Introduction to Genetic Algorithms in Search and Optimization
3.7 CONCLUSION
51
Introduction to Genetic Algorithms in Search and Optimization
make the algorithm more robust and effective. Past researches have shown
that GA proves its worth when applied to complex problems.
In this chapter we have tried to explain the working of various GA operators
such as selection, crossover and mutation etc. GA works on strings as they
are coded to represent parameters set or some rule. Selection, crossover and
mutation are applied in a series to create new population which represents
newer solutions. The above mention operators are of simple in working,
which works in values, random number generation, copying of string, string
exchange at a random point etc. Despite having less complexity in it, results
obtained by applying these operators are operators are superior to the results
obtained from conventional search techniques. We had done simulation of GA
by hand for one generation and seen its power. Following are the differences
that GA have with other conventional optimization techniques:
52
Introduction to Genetic Algorithms in Search and Optimization
REFERENCES
53
54
Chapter 4
Genetic Algorithms (GAs)
and Their Mathematical
Foundations
ABSTRACT
In this chapter, the authors back GA procedures using old mathematical facts.
More rigorous working of mathematical facts about GAs are raised in this
chapter. In fact, there are a large number of similarities in the population of
strings. The authors see how GA exploits these similarities to generate good
solutions. So, in this whole procedure they show which schema or pattern
will grow and which pattern will die or be lost as generation passes by due
to the effect of selection, crossover, and mutation operator. The study of this
building block hypothesis, leads to better understanding of GA. It will also
help us to reach optimal solutions in much less time.
DOI: 10.4018/978-1-7998-4105-0.ch004
Copyright © 2021, IGI Global. Copying or distributing in print or electronic forms without written permission of IGI Global is prohibited.
Genetic Algorithms (GAs) and Their Mathematical Foundations
To this date there are only few books (Goldberg 1989) are available and few
conference proceeding or conferences related only to GA are available to
the researchers.
Maximize F(Xi);
55
Genetic Algorithms (GAs) and Their Mathematical Foundations
by using the above equation 4.1. Thus the function values are calculated by
substituting the values of X1 and X2 in the objective function F(X) equation.
Fitness Function: Above example is a maximization problem, since GA
based on theory of survival of the fittest. If there is a minimization problem
then it is to be transformed into a maximization problem by some means or
a suitable equation. For maximization problem fitness function is considered
as same objective function i.e F (X) [Fitness Function]= f (x) [Objective
Function].
For minimization problem fitness function should be transformed into
maximization value. Thus fitness function formula is
This equation does not alter the location of the string. Here by this equation
we convert minimization problem into maximization delinquent. Here fitness
function of the string is known as string fitness.
After defining the coding procedure, fitness function GA procedure starts
with the generation of population of random individual strings. Fitness
function of each string is calculated. After this selection, crossover, mutation
operators are applied to generate new population of individual strings. This
process continues until termination conditions are met with. There are n
termination criteria. For example optimal or desired solution is obtained or
string population is exhausted or no genetic diversity is left in the population
or total i.e maximum number of generations is performed in the GA.
4.2.1 GA Operators
Selection is the first operator which comes into the picture (Deb, 2002). Main
objective of this operator is to select strings with higher fitness function for
mating. It is also known as reproduction operator. There are number of other
selection operators in GA. Basic feature of this operator is that they select
strings with above fitness function from the population multiple times. Thus
string with higher fitness function has higher probability to be selected for
mating purpose as compare with string with lower fitness function. Thus the
probability of ith string to be selected in GA population is
n
Pi = Fi / ∑ Fi
i =0
56
Genetic Algorithms (GAs) and Their Mathematical Foundations
n = Population Size.
F (Avg.) = ∑
n
Fi / n
n −1
00 000 00 111
11 111 11 000
Two strings chosen for crossover are known as parent strings, while the
resulting strings obtained are known as child strings. Crossover is based on
basic assumption that parent string with desirable pattern or higher fitness
function score will produce child string with much better fitness score. Since
if the crossing site is generated randomly, it may happen that if crossing site
falls in between the pattern. Then there is a possibility that children string
produce may not have high fitness value. This case is not of too much worry
because selection operator will discard the child string which has less fitness
function in the coming generations. Thus good child string will have higher
probability to survive in the coming generations and child strings with less
fitness score will have lower chances to be selected for mating and pass their
pattern in next generation child strings. Thus overall effect of crossover in
combination with selection operator is beneficial. Thus it preserves string
with better pattern or schema over generation after generations.
57
Genetic Algorithms (GAs) and Their Mathematical Foundations
58
Genetic Algorithms (GAs) and Their Mathematical Foundations
procedures. Here we have seen that string started with value 1 on right side
has always above fitness score. Hence in our function F (x) = x solution is
coded into a five bit binary string. First we see various similarity templates
in the string, second we correlate these similarities templates with fitness
score of the string. Thus if our study about the above two feature is complete
then it will guide us for optimization for particular function precisely with
lesser number of function evaluations. This study of template is known as
similarity template or schemata.
Thus from the previous section we are clear that we are interested in strings
or their fitness score alone, but we are interested in the particular templates or
schemata along with their fitness function. We see that if there is similarity
between the schemata present in the various strings and their fitness score.
A schema or schemata is generally a similarity pattern which is the subset
of string as a whole. In a binary string there are two bit patterns 0 or 1. We
introduces a third position * i.e don’t care symbol. With this extension we have
three possibilities (0, 1, *). Schemata are a pattern matching procedure. Here
in every position 1 binary will have to match with 1, 0 with 0, * with *. No
No consideration of strings with length 5 bits. Thus if schema *0010 matches
two strings (10010, 00010). Here one more schema *000* matches with the
4 strings (00000, 10001, 10000, 00001). Thus schema 0*011 matches with
any string with 0 in the 1st and 3rd position and 1 in fourth and fifth position
respectively. Thus idea of schema helps us to find similarity among various
strings in the population.
Thus with these position (1, 0, *) in a string of length 5 bit we have 35 i.e
243 different similarity templates. If we can have K number of alphabets or
elements in the position, then for a string of length l we will have (K + 1)l
schemata. Thus by adding * I.e don’t care symbol we are making things more
difficult. Consider (0, 1), then we had only 25 alternative strings. In case of (0,
1, *) we have 35 (243) strings or schemata. Considering these strings fitness
score and their similarities in the population. Then we had a lot of information
that we can exploit to make genetic algorithm search more effective.
Consider a single string of length5 bits: 00000. This string is a member
of of 25 schemata because in every bit position you should have value 1 or *
(don’t care symbol. If a string consists of 2l schema then for a population of
n, number of schema will vary between 2l and n × 2l. Thus by getting more
information about similarity templates, we will be able to make genetic
algorithm search more effective.
If there are between 2l and n × 2l schema in a population, than important
question is that how many schemas are processed in an useful or proper
59
Genetic Algorithms (GAs) and Their Mathematical Foundations
manner by the use of selection, crossover and mutation operator in GA. Thus
the question is how the use of these operators will result in growth and decay
of these schemas generation after generations.
Now we will discuss the effect of working of various operators such as
selection, crossover and mutation on growth and decay of these schemas.
The effect of selection operator is that it leads to the growth of schema.
Since modus operandi of the selection operator is to select string with higher
score multiple times. Selection operator does not produce new strings at all.
Considering crossover operator it may or may not cut the schema. It depends
upon the crossover point which is generated randomly. Consider two schema
0***0 and ***11. There is a possibility that first schema is likely to be decayed
as compared to the second schema. Now coming to the mutation operator it
rarely disrupts any schema, as it is used sparingly. Thus from the above study
we make a conclusion that highly fit and short length schema will propagate
generation after generation with a greater frequency. Thus exponential growth
of this schema with these properties is known as building blocks. In our
next section we will examine how many useful schemas are transferred into
next generations? Answered to this question is n3 for n number of function
evaluations. This type of parallelism we exploit in genetic algorithms.
60
Genetic Algorithms (GAs) and Their Mathematical Foundations
61
Genetic Algorithms (GAs) and Their Mathematical Foundations
operator copies or select string according to their fitness. Hence the probability
of string to be get selected is Pi = fi/∑fi. After selecting n string we have
m(H, t+1) i.e one generation has passed by. Thus schema H in the population
for generation t+1 is given by formula m(H, t+1) = m(H, t) * n * f(H)/
∑fi. Where f(H) is the average fitness of strings containing schema in it in
generation t. If average fitness of whole population is f* = ∑fi/n then m(H,
t+1) = m(h, t)* f(H)/f’
This can be explained in a way such that schema present in the string which
have higher fitness score i.e above average fitness score in the population
will grow. So schema present in the strings which has lower fitness score as
compare with the average fitness of the population will decay. This happens
with every schema parallel present in the population. Thus selection operator
will select multiple copies of schema whose string has better fitness score
and schema in the string having lower fitness score are selected in decreasing
number. Thus above average schema’s increases or grow, while below average
schema’s decreases or decay. Thus mathematical form of growth and decay
of schema has been represented by this simple equation:
Where c is a constant.
Thus the effect of selection operator is clear; it increases and decreases
the trials of above average and below average schema. Thus many parallel
schema works in a population of n strings.
Selection operator does not promote or add new string. This is done by
the use of crossover operator. Here old strings are copied without making
any changes in them. Crossover on the other hand is randomized exchange
of strings. It creates newer strings by disrupting the strings at a random
generated point. It may or may not disrupt the schema or similarity template.
For example consider a string of length l = 8.
A = 10110110
H1 = *0*****0
H2 = ******10
Two schemas H1 and H2 are represented in string A. Now we will see the
effect of crossover on these schemas.
62
Genetic Algorithms (GAs) and Their Mathematical Foundations
A = 10110110
H1 = *0** ***0
H2 = **** **10
Ps ≥ (1-Pc) δ(H)/(l – 1)
Thus schema which has fitness score above population average and short
defining length grows. While schemas with lower fitness score as compare
to population average and long defining length are going decay.
Last operator used is mutation. If mutation probability is Pm. Mutation is
random alteration of bits. Thus probability of schema to survive is (1 - Pm).
Thus lower order schema will have larger chances to survive as compared
with higher order schema. Thus probability of surviving mutation is (1 – Pm
* O(H)). Thus the expression representing the combined effect of selection,
crossover and mutation operators are:
Thus summary is that short, low order and above average schema are
likely to increase exponentially in the trials to come. Thus it is known as
schemata theorem or fundamental theorem of Genetic Algorithm. Calculation
representing this theorem is not complex. Thus highly fit schema, combined
with short low order schema are selected, recombined and re experimented to
63
Genetic Algorithms (GAs) and Their Mathematical Foundations
form more fit strings or with a higher fitness function. With the above study
we have reduced the complexity of our problem. Thus instead of trying every
possible combination we were able to build string from these best fractional
clarification. Thus this schemata theorem can be used for generalization of
results for various functions. But for other deceptive function where best
points is surrounded by the worst or finding an optimal solution is to find is
just like finding a needle in haystack, this schemata theorem fails. As building
blocks are of misleading in nature. Thus to find near optimal solution will
take large amount of time.
4.5 CONCLUSION
64
Genetic Algorithms (GAs) and Their Mathematical Foundations
REFERENCES
65
Section 2
Genetic Algorithms
Theory and its Working
67
Chapter 5
Genetic Algorithm (GA)
Methodology and Its
Internal Working
ABSTRACT
Many practitioners are shy with implementing GAs. Due to this, a lot of
researchers avoid using GAs as problem-solving techniques. It is desirable that
an implementer of GA must be familiar in working with high-level computer
languages. Implementation of GA involves complex coding and intricate
computations which are of a repetitive nature. GAs if not implemented with
caution will result in vague or bad solutions. This chapter overcomes the
obstacles by implementing and defining various data structures required
for implementing a simple GA. They will write various functions of GA code
in C ++ programming language. In this chapter, initial string population
generation, selection, crossover, and mutation operator used to optimize a
simple function (one variable function) coded as unsigned binary integer is
implemented using C ++ programming language. Mapping of fitness issue
is also discussed in application of GAs.
DOI: 10.4018/978-1-7998-4105-0.ch005
Copyright © 2021, IGI Global. Copying or distributing in print or electronic forms without written permission of IGI Global is prohibited.
Genetic Algorithm (GA) Methodology and Its Internal Working
we will deeply look into the fact that how variations in GA’s operators can
be made to get best possible solution of a hard problem. Other advanced and
sophisticated operators will also be discussed there.
In past it is seen that working of GA can be easily understood by applying
it to a problem with large search space (Goldberg, 2002). Here we will
understand about working of GA by applying it to a simple problem with a
large search space.
A Genetic Algorithm Solution: Here the above topic refers to the
implementation of a GA, not the solution given by GA. As there are number
of variations about GA that can be implemented, solution quality obtained
by GA for a given problem is discussed in later chapters of this book. The
following steps will discuss about the fundamental characteristics of GA.
68
Genetic Algorithm (GA) Methodology and Its Internal Working
69
Genetic Algorithm (GA) Methodology and Its Internal Working
70
Genetic Algorithm (GA) Methodology and Its Internal Working
It is widely seen from past work that greedy selection process results in an
premature convergence of population. So in this way many optimal solutions
and other vantage points which could be searched could be left behind or lost
in the previous successive generations. Main drawback of greedy selection
technique is that it decreases the genetic diversity in the population very
quickly. Hence the chances to find an optimal or close to optimal solution
are reduced. So result is that solution quality is decreased and many potential
string combinations will be sacrificed in such a way. Thus GA will not have
sufficient diversity left in its population of strings to explore the vast search
space. This is popularly known as premature or advance convergence problem.
1st step: Two above average strings are randomly chosen from the population
with the help of selection operator.
2nd Step: Crossover probability is already assigned in the beginning of
GA. If it is assigned 75% then random number is generated between 0 and
100, and if its value comes in between 0 and 75, then crossover is performed
otherwise not.
3rd Step: If answer to perform crossover is yes then if string is 10 bit long
then a random number is generated between 0 and maximum length of the
string i.e between 0 and 10 if maximum string length is 10. If random value
generated comes to be 7, then this point will be the crossover point of the
two strings.
4th Step: Here we cut each string at the crossover point. First string generated
will have bit position 1 to 6 from 1st parent string and bit position 7 to 10
from the 2nd parent string. While 2nd child string will have bit position 1 to 6
from 2nd parent string and bit position 7 to 10 from first parent string. In result
there is a exchange of two tail pieces of the parent string. Actual working of
crossover is shown below:
71
Genetic Algorithm (GA) Methodology and Its Internal Working
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0
→
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1
Past researches have shown that higher crossover probability rate is very
effective to find optimal solution. But there is no actual value for crossover
probability which will be uniform for all the problems, which are going to
be solved by using GA’s. Again I repeat that crossover is a real powerful tool
which results in effective and efficient searching of the search space. It is
difficult to picture the actual working of crossover. But I think this example
will work for your convenience. It is seen that crossover gains much of the
strength through selection operator. Due to the selection operator all the
odds are in favour for strings having above average fitness. For example
for a particular problem, the pattern 11011 in bit position 5 to 10 leads to a
better solution and pattern 0101 from bit position 1 to 4 also leads to a better
solution. If a string X has pattern 11011 in its bit position 5 to 10 and string
Y has a bit pattern 0101 from position 1 to 4. If selection operator selects
these two strings and crossover takes place then there is a larger possibility
to have bit pattern 1101100101 through 1 to 10 (Bit numbers are taken from
left to right). Thus child string will have fitness more than its two parent
string as it has inherited better character tics of the two.
0 0 0 1 1 0 1 0 1 0
↓
0 0 0 1 1 1 1 0 1 0
72
Genetic Algorithm (GA) Methodology and Its Internal Working
73
Genetic Algorithm (GA) Methodology and Its Internal Working
all steps in GA are similar but fitness function calculation varies from
problem to problem.
3. GA finds both optimal solution and near to optimal solution. For stock
market problem where best solution is not known, the solution obtained
by GA is easily acceptable. Here GA finds many vantage solutions and
converges on to a practically good solution.
4. GA is well designed for various function optimization. Here one parameter
or multiple parameter of function can be optimized to obtain a better
value.
0011 0101 1010 0100 0011 1111 0011 01value = 0.70289 Parent1 =0
Parent2 = 0 Cross Site0
0110 1001 0011 1011 1011 1110 0110 11value = 0.851432 Parent1 =0
Parent2 = 0 Cross Site0
1010 0000 1101 1111 1101 1000 0010 01value = 0.564208 Parent1 =0
Parent2 = 0 Cross Site0
1111 1100 0001 1010 0011 1000 0011 10value = 0.43923 Parent1 =0
Parent2 = 0 Cross Site0
0011 0100 0010 1100 1000 0111 1111 01value = 0.74812 Parent1 =0
Parent2 = 0 Cross Site0
1100 1000 1110 1010 0100 0100 1100 10value = 0.298971 Parent1 =0
Parent2 = 0 Cross Site0
74
Genetic Algorithm (GA) Methodology and Its Internal Working
1011 1001 0011 0110 0011 1000 0010 01value = 0.564235 Parent1 = 0
Parent2 = 0 Cross Site0
1101 1011 1010 0100 1110 1011 1001 10value = 0.403757Parent1 = 0Parent2
= 0Cross Site0
1101 0011 0010 1010 0100 1010 0100 11value = 0.786275Parent1 = 0Parent2
= 0Cross Site0
1011 1101 0100 0001 0000 1101 1001 00value = 0.151398Parent1 = 0Parent2
= 0Cross Site0
1110 0011 1100 1100 0010 1100 1011 00value = 0.206311Parent1 = 0Parent2
= 0Cross Site0
0111 1000 0010 0110 1111 1111 1011 10value = 0.468713Parent1 = 0Parent2
= 0Cross Site0
0011 0111 0010 0100 0011 1101 0111 11value = 0.980233Parent1 = 0Parent2
= 0Cross Site0
0100 1010 0101 1101 0001 1110 0110 10value = 0.351119Parent1 = 0Parent2
= 0Cross Site0
1111 1110 1101 1100 0010 1111 0110 00value = 0.108657Parent1 = 0Parent2
= 0Cross Site0
0000 1111 0011 1111 0110 0110 0101 00value = 0.162536Parent1 = 0Parent2
= 0Cross Site0
1101 1100 0101 1000 0100 1111 0111 11value = 0.983527Parent1 = 0Parent2
= 0Cross Site0
0110 1011 0001 1110 0111 1101 0001 00value = 0.136625Parent1 = 0Parent2
= 0Cross Site0
0010 0110 0011 0011 0101 0000 1111 11value = 0.985034Parent1 = 0Parent2
= 0Cross Site0
1000 1010 0111 1111 0110 0101 0001 11value = 0.885192Parent1 = 0Parent2
= 0Cross Site0
0110 0000 1000 1011 1010 1000 0110 11value = 0.845082Parent1 = 0Parent2
= 0Cross Site0
1011 1100 1101 0100 1110 1011 0100 00value = 0.044383Parent1 = 0Parent2
= 0Cross Site0
0010 0010 0110 0111 1011 0100 1011 01value = 0.705926Parent1 = 0Parent2
= 0Cross Site0
1011 0101 0100 0110 1100 0100 0101 10value = 0.40841Parent1 = 0Parent2
= 0Cross Site0
0000 1001 1000 0110 0111 0011 1011 11value = 0.965721Parent1 = 0Parent2
= 0Cross Site0
75
Genetic Algorithm (GA) Methodology and Its Internal Working
1000 0001 1000 0111 0001 1110 0000 00value = 0.007378Parent1 = 0Parent2
= 0Cross Site0
1111 0110 0111 1010 0010 0001 0000 00value = 0.008079Parent1 = 0Parent2
= 0Cross Site0
0100 0000 1101 0000 1000 0010 0001 11value = 0.87897Parent1 = 0Parent2
= 0Cross Site0
1111 0010 1100 1100 1100 0011 0000 10value = 0.261914Parent1 = 0Parent2
= 0Cross Site0
0110 0110 0001 0100 1000 1000 0110 01value = 0.594797Parent1 = 0Parent2
= 0Cross Site0
1111 0100 1001 1110 1010 0100 0000 11value = 0.752287Parent1 = 0Parent2
= 0Cross Site0
0000 0001 1111 0011 1110 0000 0111 11value = 0.969227Parent1 = 0Parent2
= 0Cross Site0
0111 0110 0111 0010 0001 1011 1101 00value = 0.185077Parent1 = 0Parent2
= 0Cross Site0
1010 0011 1000 1110 0110 1011 1001 01value = 0.653714Parent1 = 0Parent2
= 0Cross Site0
0001 1111 0010 1010 0011 0010 0011 10value = 0.442159Parent1 = 0Parent2
= 0Cross Site0
1100 1001 1000 0101 1010 0100 1101 00value = 0.174172Parent1 = 0Parent2
= 0Cross Site0
1010 1011 0001 0100 0000 1011 1011 11value = 0.96583Parent1 = 0Parent2
= 0Cross Site0
0100 1010 1100 1110 0000 0101 0110 11value = 0.853543Parent1 = 0Parent2
= 0Cross Site0
0011 1000 1110 1111 0100 0011 1111 10value = 0.496275Parent1 = 0Parent2
= 0Cross Site0
1010 0011 1010 1111 0101 0000 0100 01value = 0.531919Parent1 = 0Parent2
= 0Cross Site0
1100 1110 1100 1100 0010 1100 1111 00value = 0.237561Parent1 = 0Parent2
= 0Cross Site0
0100 0110 1110 1001 1110 1000 0101 11value = 0.90769Parent1 = 0Parent2
= 0Cross Site0
1000 1111 1011 0111 1011 0101 1001 00value = 0.151241Parent1 = 0Parent2
= 0Cross Site0
0001 0110 0100 0010 0011 1100 1111 00value = 0.238053Parent1 = 0Parent2
= 0Cross Site0
76
Genetic Algorithm (GA) Methodology and Its Internal Working
0101 1110 1010 0000 1011 0000 0011 11value = 0.938295Parent1 = 0Parent2
= 0Cross Site0
0001 1010 0000 0110 1000 0010 1010 00value = 0.082115Parent1 = 0Parent2
= 0Cross Site0
average fitness 0.518099 min. value 0.007378 max. value 0.987394
generation = 0
struct population
{
int a[30];
float value;
int p1;
int p2;
int crosss;
} oldp[50],newp[50]; → Maximum Population Size
Here maximum population size is kept to 50 and strength length is 30. These
two parameters could be change from problem to problem. But in our problem
upper bound of string length and population size is 30 and 50. Various other
declarations are also made in the structure of population. Here population is
an array of individuals i.e oldp[50] and newp[50]. Here individual’s values is a
array of binary values of 0’s and 1’s. These individuals are called chromosomes
and their fitness values are placed in variable named as value. The data type
given to value is float. This fitness value is the decoded value of the string.
This string is itself an array of numbers with data type declared as int. The
values of array will be 0 or 1. Here in our simple genetic algorithm after the
random generation of population of strings, basic operators as discussed
above are, such as crossover, mutation are applied to the entire population
of the strings, not to a single string itself. This is shown below:
oldp[50] newp[50]
1. 1.
2. 2.
3. 3.
4. 4.
5.Reproduction, Crossover and Mutation 5.
77
Genetic Algorithm (GA) Methodology and Its Internal Working
. .
. .
. .
. .
47. 47.
48. 48.
49. 49.
50. 50.
Generation 1
78
Genetic Algorithm (GA) Methodology and Its Internal Working
In this section we will get the explanation about the implementation of these
three popular GA operators. We had discussed about the theory and working
of these operators in detail in the previous section of this book. So to start
with the coding that is same in all these three operators are random number
generation.
79
Genetic Algorithm (GA) Methodology and Its Internal Working
int selection()
{int i; float r1,r, partsum, rando;
partsum = 0; i = 0;
r = random(100);
r1 = (float)r/100;
rando = r1*sumfitness;
while(partsum< = rando && i<50)
{
partsum = partsum+oldp[i].value;i = i+1;
}
return(i-1);}
The code shown above is a straight forward way to implement selection operator.
This operator can be implemented in a more efficient way also. Apart from
roulette wheel selection technique there are other selection techniques also
which can be used. We are going to discuss these techniques in detail in the
coming chapters. This roulette wheel selection implementation code gives
us a simplest and effective way to select a parent string for next generation.
After the selection operator comes the crossover operator. Implemented
code of crossover operator is given below. Here first two parents’ parent 1
and parent 2 are selected by the use of selection operator. Detail procedure of
working of crossover operator is discussed in the previous section of the book.
By application of this crossover operator two offspring or child strings child 1
and child 2 are generated. The probability of crossover operator and mutation
operator is set in the beginning of the main program. Our implementation of
crossover operator is similar to the working of crossover operator discussed
in the previous chapters.
80
Genetic Algorithm (GA) Methodology and Its Internal Working
81
Genetic Algorithm (GA) Methodology and Its Internal Working
Initially we generate a random number between 0 and 100. If its value comes to
be less than the value of the crossover number we had decided in the beginning
of the program, then crossover will take place otherwise mutation will be
performed. If crossover takes place then we will generate a random number
between 0 and maximum string length says 30 in case of our example. This
random number generated will give us the crossover site. Finally exchange
of strings will take place in crossover. Exchange of strings will take place
between parent 1 and child 1, parent 2 and child 2, so on. After the successful
completion of crossover operator mutation operator will be implemented.
Mutation process is shown in the code. Here we use two nested for loop.
First loop represents the maximum population in use and second loop represents
string length size. Since mutation probability is kept very low i.e of the order
of 1% or 0.01. Which means roughly every 10 bits will be mutated in a total
of 1000 bits checked? Here every bit is selected and condition is checked
using if else statement. If it comes true then the bit value changes from 0 to
1 and vice versa. Thus in our example random number is generated for 50
* 30 i.e 1500 times. This consumes a lot of time and computation resource.
There can be another way, if we already select the bit positions and number
of bits which are to be mutated. This type of sophisticated implementation
of mutation operator is avoided in order to keep things simple.
Together with the use of selection, crossover and mutation operator we
will create a new population newp[50], from old population oldp[50]. After
the creation of new population its strings are copied into old population by
a simple code using for loop.
for(i = 0;i<50;i++)
oldp[i] = newp[i];
Thus again on this oldp[50] selection, crossover and mutation are applied
and next generation population i.e newp[50] is generated which is again
copied into old population oldp[50] and so on, until termination criteria
is met with or maximum number of generations are over. So we discussed
and implemented these three main genetic algorithm operators. They are
mystifying in nature. We have understood their theory and implemented their
coding in C++ language.
82
Genetic Algorithm (GA) Methodology and Its Internal Working
We have seen that we pick two strings i.e mate 1 and mate 2 for crossover
by using selection() function. We apply crossover and mutation operator in
the generation() function. After this we decode the string into their actual
parameter values and calculate the objective function. So after the successful
implementation of selection, crossover and mutation operators, we will
now turn our attention towards problem specific functions. The routines of
selection, crossover and mutation are almost same for every problem. For
every problem there will be different set of parameters. Thus in orders to
calculate objective function of a particular string, first we have to decode the
string to find parameter or set of parameters that string represent. After the
value of parameter or parameter set is obtained, we then proceed to calculate
objective function value associated with the parameter or parameter set, which
indirectly represents the string. Depending upon the problem we will have
different decoding procedures and objective function calculations. To start
with a particular decoding procedure and objective function calculation of
the example we have implemented in this book. In our example our binary
string is decoded starting from a lower order bit position 0 from left to right
by summation of current power of two when bit position is 1 i.e Pow(2,i). This
accumulated value is used to find the objective function of thart particular
string. The objective function calculation in our simple genetic algorithm is
simple calculation of converting binary string into decimal equivalent. Here
our objective function is:
F(x) = (x / Coefficient)
83
Genetic Algorithm (GA) Methodology and Its Internal Working
return value1;}
Objective Function Implementation
In our previous sections we had got glimpse about the various data structures
used in the GA implementation. In previous section we had implemented
selection, crossover, mutation operator function decoded as strings, find
objective function or fitness function of the string. Now we have to go for main
program and call these functions one by one to get GA program implemented
as a whole. Our main program starts by asking genetic crossover and mutation
probabilities from the GA user. Initial population will have parent 1 and
parent 2 zero as their value. Since initial population is generated randomly.
Code for initial population generated function is given below:
Main Program
Here coin is flipped and equal weight age is given for assignment of 0 or 1 to
the population string as it is of binary in nature. In our code implemented we
generate a random number from 0 to 100. Here random number is generated
for every bit. If the value of random number is below 51 then 0 is assigned
to that particular bit position otherwise 1 is assigned. This procedure is
repeated for every bit position. For this nested For loop is used. 1st For loop
represented maximum population size and second For loop represented
maximum string length.
84
Genetic Algorithm (GA) Methodology and Its Internal Working
85
Genetic Algorithm (GA) Methodology and Its Internal Working
{ for(int j = 0;j<30;j++)
cout<<oldp[i].a[j];
//cout<<endl;
oldp[i].value = objfun(oldp[i].a);
cout<<”value = ”<<oldp[i].value;
cout<<”Parent1 = ”<<oldp[i].p1;
cout<<”Parent2 = ”<<oldp[i].p2;
cout<<”Cross Site”<<oldp[i].crosss;
cout<<endl;
} }
Thus listing of the population strings and their objective function values
can also be done in various other tabular and graphic form of writing the code
in writereport(); function depending upon the problem. This is the simplest
form of report we had printed on the screen. This writereport(); function help
us to make comparison of results of various generations. This helps us to see
the robustness of GA results for a variety of operators used. Thus helps in
finding the best individual. To come to an end we had written codes of all
the operators and statistical function to check the GA results. Now we will
enclose all these function declared and call them in our main function step
by step. Below is the code of the main(); function program, in which all the
functions are called in a sequential manner.
void main()
{ clrscr();
cout<<”Enter mutation probability”<<endl;
cin>>m;
cout<<m<<endl;
//s = m*50*8;
cout<<”Enter crossover probability in percentage”<<endl;
cin>>cross;
for(i = 0;i<50;i++)
{ oldp[i].p1 = 0;
oldp[i].p2 = 0;
oldp[i].crosss = 0;}
initialize();//Generate Initial Population
writereport();//Print Whole Population & their objective
function values & parents p1 & p2, cross over site
getch();
statistics();//Calculate & print max., min. & avg. objective
function values of a generation
for(int z = 0;z<50;z++)
{
generation();//Crossover & Mutation
for(i = 0;i<50;i++)
86
Genetic Algorithm (GA) Methodology and Its Internal Working
oldp[i] = newp[i];
//writereport();
calcobjfun();//Calculate Objective Function
statistics();//Calculate & print max., min. & avg. objective
function values of a generation
cout<<” “<<z<<endl;
getch();
}
getch();
}
Main Program of Simple Genetic Algorithm
As seen in our previous chapters we have walked slowly and steadily with
heavy steps and cover a difficult surface of Genetic Algorithm GA code inch
by inch. Now we get a better feel about the GA. We came to know about pros
and cons, ins and outs of the Genetic programming ways. We can bell the
cat known as GA by implementing it in a variety of ways. There are a large
number of codes available over internet i.e in a public view in which GA has
been implemented in a variety of ways. There are many codes for a variety of
other problems where their parameters are to be optimized. Here until now we
have covered implementation of basic operators such as crossover, mutation
and selection in code implementation. There are a number of various others
advance and sophisticated operators in GA, which helps us to find many peaks
in our problem. These advance operators or features will be discussed in the
later chapters of the book. At this point I will not be tempted by these fancy
features or operators of GA. Now in next section we are going to discuss the
results obtained by running our simple Genetic Algorithm program or code
we had implemented.
We already explained the test problem which we had over took. Here the
string length is 30 bit s and it decipher into a integer. The fitness function is
a normal function, F(x) = x/c. Where the value of ‘c’ is used to normalize the
value of F(x). Initially in our earlier chapters we have chosen different fitness
function i.e F(x) = x2. There we had solved the problem by using simple
GA applied by hand. There the string length was short i.e l = 5. Thus the
search space for it was 25 = 32 points. Practically it could be solved quickly
by using any traditional search methods or just by random walk or by brute
87
Genetic Algorithm (GA) Methodology and Its Internal Working
force technique. But at the starting point our aim was to get an insight about
the working of GA. Working with clarity, so we had chosen a limited search
space. As we had settled with it, we go for a much difficult and heavier
problem with a huge search space. We increased the string from l = 5 to l =
30. Thus the search space is increased from 32 to 230 i.e 1.07 * 1010 points.
Hence with more than 1 billion points brute force attack is not a viable and
quick option. Thus with the increase of search space we had made problem
more tougher and appropriate to be solve with the help of GA.
With a large search space in GA we start with the generation of random
population of strings. It is believed that a random population initially generated
will not have strings that represent good solutions. To start with the running
of simple Genetic Algorithm (SGA) code, we are going to decide at what GA
operators settings we are going to run the program. Previous researchers has
shown that high crossover probability (range 0.75 to 0.95) in combination
with low mutation probability (0.01) and moderate population size (50) gives
us the desired results. With this we run our SGA program with crossover
probability 0.90, mutation probably value 0.01 and population size of 50 for
a 50 number of generations. We run our SGA program for 50 generations.
Performance graph is shown in Figure 1.
88
Genetic Algorithm (GA) Methodology and Its Internal Working
As our results shows that our population begins with a initial average fitness
value 1611.13, maximum fitness value is 3452.42. We expect 30 * (1- (Max
fitness value)0.1) number of strings with fitness value greater than maximum
fitness value. By seeing our population we are not so lucky at the beginning.
Though average fitness value of population is not too large. We should not feel
depressed. As we run GA for few generations our average fitness function and
maximum fitness function of strings improves. Our performance increases
exponentially as compared to the initial results obtained, which is shown in
the graph. So as the generations passes by there is a continuous improvement
in average and maximum fitness function of the population. After the run
for few generations our results get converge to a particular higher point.
In final point difference between average fitness function and maximum
fitness function narrows down. Though we do not get the best point, but we
are close to the best point in the search space. In some problem population
converges prematurely without reaching the top point in the solution. So to
avoid such a situation, many variations in design parameters of operators in
GA is to be done to achieve better solution. We will discuss this situation in
detail in the coming chapters of the book. Avoiding premature convergence
will lead us to find many vantage points in the search space. This increases
the efficiency of GA and their ability to find better solutions in a variety of
NP hard problems.
It was seen that other traditional search techniques converges to a local
optima quickly. As there is no means to bring them out of local space. This
results in sacrificing the algorithm ability to find a global optima solution. To
overcome such situation GA is used. Hence in a hybrid system we use both
GA in combination with traditional technique. If in a problem there are many
local peaks, start with GA to find these local peaks, as GA ability to fond
various vantage points parallel. On these many vantage points are obtained,
a traditional technique is applied on these local optima points to get global
optima or improve in the result. In this way by applying this hybrid optima
technique both efficiency and efficacy is increased. So problem of premature
89
Genetic Algorithm (GA) Methodology and Its Internal Working
1010 0010 0001 0100 0000 value = 2462.170654 Parent1 = 42 Parent2 = 19 Cross Site5 1100 1010 0010 0110 1100 value = 1574.2854 Parent1 = 15 Parent2 = 20 Cross Site15
1000 0001 1111 1001 1000 value = 1497.41394 Parent1 = 9 Parent2 = 49 Cross Site10 1000 0110 0010 0100 0000 value = 2115.104736 Parent1 = 15 Parent2 = 44 Cross Site8
0101 0100 1101 1110 0101 value = 55.159428 Parent1 = 9 Parent2 = 49 Cross Site10 0001 1001 0000 0010 1100 value = 1005.999146 Parent1 = 15 Parent2 = 44 Cross Site8
0011 0111 1111 1101 1000 value = 2782.719238 Parent1 = 16 Parent2 = 14 Cross Site9 1010 0010 0001 0100 0000 value = 2462.170654 Parent1 = 3 Parent2 = 18 Cross Site17
0110 0111 0110 0001 0001 value = 46.426941 Parent1 = 16 Parent2 = 14 Cross Site9 1011 1111 1100 1110 0000 value = 3434.122559 Parent1 = 3 Parent2 = 18 Cross Site17
1100 0010 0001 0100 0000 value = 2489.162354 Parent1 = 4 Parent2 = 42 Cross Site3 1001 1101 0001 0100 0000 value = 1294.497192 Parent1 = 24 Parent2 = 17 Cross Site5
0110 1010 0010 0101 0000 value = 2130.183838 Parent1 = 4 Parent2 = 42 Cross Site3 0000 1000 0000 0001 0000 value = 3176.683105 Parent1 = 24 Parent2 = 17 Cross Site5
1100 1010 0001 0100 0000 value = 2280.616699 Parent1 = 34 Parent2 = 42 Cross Site5 0001 1000 0010 0100 0000 value = 3142.484863 Parent1 = 44 Parent2 = 10 Cross Site17
0110 0010 0001 0100 0000 value = 2448.775146 Parent1 = 34 Parent2 = 42 Cross Site5 1100 1010 0001 0100 0000 value = 2280.616699 Parent1 = 44 Parent2 = 10 Cross Site17
1100 0111 0111 1101 1100 value = 344.773956 Parent1 = 24 Parent2 = 15 Cross Site4 1001 1000 0000 0000 1110 value = 1503.666504 Parent1 = 24 Parent2 = 13 Cross Site14
0110 1011 1101 0100 1110 value = 1292.128296 Parent1 = 24 Parent2 = 15 Cross Site4 0110 1011 1101 0101 0000 value = 2725.78125 Parent1 = 24 Parent2 = 13 Cross Site14
1011 0111 0001 1010 0100 value = 662.473633 Parent1 = 0 Parent2 = 46 Cross Site3 1000 0110 0000 0010 1000 value = 1867.874756 Parent1 = 15 Parent2 = 10 Cross Site17
1000 0110 0000 0010 1100 value = 1461.108154 Parent1 = 0 Parent2 = 46 Cross Site3 1100 1010 0001 0100 0100 value = 1828.391724 Parent1 = 15 Parent2 = 10 Cross Site17
0000 1100 1101 0100 1110 value = 264.669495 Parent1 = 25 Parent2 = 13 Cross Site8 1011 1111 1010 0101 0000 value = 339.499756 Parent1 = 18 Parent2 = 33 Cross Site8
0000 1101 0001 0100 0000 value = 1360.903687 Parent1 = 25 Parent2 = 13 Cross Site8 1011 1111 1100 1110 0000 value = 3434.122559 Parent1 = 18 Parent2 = 33 Cross Site8
1011 1111 1100 1110 0000 value = 3434.122559 Parent1 = 2 Parent2 = 45 Cross Site1 0110 0010 0010 0101 0000 value = 2330.462646 Parent1 = 27 Parent2 = 20 Cross Site3
1001 0000 0011 1101 0110 value = 1752.050171 Parent1 = 2 Parent2 = 45 Cross Site1 1101 1111 1100 1110 0000 value = 3397.762695 Parent1 = 27 Parent2 = 20 Cross Site3
1100 1010 0010 0101 0000 value = 2166.496094 Parent1 = 4 Parent2 = 4 Cross Site2 1010 0010 0000 0101 0000 value = 2347.312012 Parent1 = 26 Parent2 = 20 Cross Site11
1100 1010 0110 0101 0000 value = 379.255554 Parent1 = 4 Parent2 = 4 Cross Site2 1100 1010 0011 0100 0000 value = 2276.889404 Parent1 = 26 Parent2 = 20 Cross Site11
0011 0111 1010 0100 1110 value = 5.950563 Parent1 = 16 Parent2 = 13 Cross Site13 0000 0100 0010 1101 1110 value = 1295.282593 Parent1 = 40 Parent2 = 40 Cross Site10
0000 1101 1101 0001 0001 value = 743.005981 Parent1 = 16 Parent2 = 13 Cross Site13 0000 0100 0011 1101 1100 value = 2106.509766 Parent1 = 40 Parent2 = 40 Cross Site10
1001 1000 0000 0001 0000 value = 3026.196289 Parent1 = 47 Parent2 = 19 Cross Site14 1000 0001 1111 1001 1000 value = 1497.41394 Parent1 = 4 Parent2 = 38 Cross Site18
1010 0110 0010 0110 1100 value = 1396.44104 Parent1 = 47 Parent2 = 19 Cross Site14 0001 1011 0011 1010 0100 value = 757.921631 Parent1 = 4 Parent2 = 38 Cross Site18
1010 0010 0001 0100 0000 value = 2462.170654 Parent1 = 45 Parent2 = 42 Cross Site3 0110 0111 1100 1110 0000 value = 3035.79541 Parent1 = 2 Parent2 = 48 Cross Site3
0111 1111 1100 1110 0000 value = 3452.429199 Parent1 = 45 Parent2 = 42 Cross Site3 0000 0110 0010 0101 0000 value = 2013.141357 Parent1 = 2 Parent2 = 48 Cross Site3
0001 1000 0101 0110 0010 value = 82.998642 Parent1 = 1 Parent2 = 6 Cross Site9 1000 0110 0000 0010 1101 value = 335.019623 Parent1 = 15 Parent2 = 4 Cross Site19
1000 0010 1010 0101 1000 value = 462.834534 Parent1 = 1 Parent2 = 6 Cross Site9 1000 0001 1111 1001 1000 value = 1497.41394 Parent1 = 15 Parent2 = 4 Cross Site19
1001 1001 0000 0101 0000 value = 1456.256226 Parent1 = 47 Parent2 = 19 Cross Site11 1000 1110 0010 0101 0000 value = 1827.748169 Parent1 = 1 Parent2 = 41 Cross Site0
1010 0110 0010 0010 1100 value = 1419.860474 Parent1 = 47 Parent2 = 19 Cross Site11 1100 1100 0001 0100 0000 value = 2714.975586 Parent1 = 1 Parent2 = 41 Cross Site0
1010 0110 1100 1111 0000 value = 1383.536255 Parent1 = 19 Parent2 = 45 Cross Site8 0001 1000 0010 0100 0100 value = 2607.161621 Parent1 = 44 Parent2 = 15 Cross Site17
1011 1111 0010 0101 0000 value = 822.751526 Parent1 = 19 Parent2 = 45 Cross Site8 1000 0110 0001 0010 1000 value = 1861.133789 Parent1 = 44 Parent2 = 15 Cross Site17
1100 0010 1101 0100 0000 value = 1268.063354 Parent1 = 6 Parent2 = 25 Cross Site12 0001 1000 0000 0010 0100 value = 2579.331055 Parent1 = 47 Parent2 = 44 Cross Site18
0000 1100 0001 0110 0010 value = 1756.69812 Parent1 = 6 Parent2 = 25 Cross Site12 0001 1000 0010 0100 0000 value = 3142.484863 Parent1 = 47 Parent2 = 44 Cross Site18
0110 0010 0001 0100 1100 value = 1763.261719 Parent1 = 42 Parent2 = 31 Cross Site15 0110 0010 0001 1111 0000 value = 2251.985107 Parent1 = 36 Parent2 = 27 Cross Site12
1001 0111 0011 0010 0000 value = 972.525513 Parent1 = 42 Parent2 = 31 Cross Site15 0111 1111 1100 1100 1100 value = 2691.199463 Parent1 = 36 Parent2 = 27 Cross Site12
0001 1011 0011 1010 0100 value = 757.921631 Parent1 = 10 Parent2 = 46 Cross Site6 1000 0010 0001 0100 0000 value = 2516.42334 Parent1 = 15 Parent2 = 26 Cross Site3
1001 0000 0000 0010 0100 value = 2815.0625 Parent1 = 10 Parent2 = 46 Cross Site6 1010 0110 0000 0010 1100 value = 1422.801636 Parent1 = 15 Parent2 = 26 Cross Site3
0000 0100 0011 11011 110 value = 1289.677856 Parent1 = 37 Parent2 = 41 Cross Site5 1011 0111 1111 0101 1000 value = 2815.221191 Parent1 = 48 Parent2 = 6 Cross Site1
1000 1110 0010 0101 0000 value = 1827.748169 Parent1 = 37 Parent2 = 41 Cross Site5 0000 0111 1100 1110 0000 value = 2938.804688 Parent1 = 48 Parent2 = 6 Cross Site1
0000 1011 1101 1110 0101 value = 718.334961 Parent1 = 30 Parent2 = 9 Cross Site2 0100 0010 0001 0100 1000 value = 2259.015381 Parent1 = 2 Parent2 = 8 Cross Site1
1001 1000 0010 1000 0100 value = 2607.902832 Parent1 = 30 Parent2 = 9 Cross Site2 1110 0110 0010 0101 0000 value = 1934.777954 Parent1 = 2 Parent2 = 8 Cross Site1
0001 1000 0010 0100 0000 value = 3142.484863 Parent1 = 30 Parent2 = 5 Cross Site12 1011 0111 0000 0001 0000 value = 920.499084 Parent1 = 14 Parent2 = 24 Cross Site9
1010 0110 0001 1000 0100 value = 1648.934448 Parent1 = 30 Parent2 = 5 Cross Site12 1001 1000 0001 1010 0100 value = 2540.563965 Parent1 = 14 Parent2 = 24 Cross Site9
0001 1000 0000 0000 0100 value = 2643.164063 Parent1 = 10 Parent2 = 10 Cross Site7 0001 1000 0010 1000 0100 value = 2623.132324 Parent1 = 47 Parent2 = 43 Cross Site4
0001 1000 0000 0010 0100 value = 2579.331055 Parent1 = 10 Parent2 = 10 Cross Site7 1001 1000 0000 0010 0100 value = 2564.229736 Parent1 = 47 Parent2 = 43 Cross Site4
0000 0111 1100 1110 0000 value = 2938.804688 Parent1 = 38 Parent2 = 45 Cross Site5 1001 1000 0000 0001 0000 value = 3026.196289 Parent1 = 24 Parent2 = 43 Cross Site18
1011 1010 1101 0110 0010 value = 764.585754 Parent1 = 38 Parent2 = 45 Cross Site5 1001 1000 0010 1000 0100 value = 2607.902832 Parent1 = 24 Parent2 = 43 Cross Site18
average fitness 1611.138428 min. value 5.950563 max. value 3452.429199 generation = 1 average fitness 2110.324463 min. value 335.019623 max. value 3434.122559 generation = 2
90
Genetic Algorithm (GA) Methodology and Its Internal Working
5.5 CODING
Until now we had used binary string coding for mapping the parameter or
parameters value to the finite length string in case of our simple optimization
problem. Here we had concatenated 0’s and 1’s i.e initially ith value will
have 0 value in case of flip of a coin we had head and 1 value if we got a tail
value. A binary string then represent a unsigned integer i.e a string ai, ai-1,
......a3, a2, a1 will be decoded using formula X = ∑ai*2i-1 . Though this types
of binary encodings gives us a lot of flexibility and power for many types
of twists and turns and a large number of options to represents a solution.
Past researchers has actively used these type of binary encoding almost in
every type of problem representation in the field of science, engineering and
technology spectrum. In this section of the book we will see number of other
coding designs for problems in different areas. In the end we look for binary
string that represents not a single parameter but n numbers of parameters.
It is seen that coding in GA search requires a lot of mind’s eye and thought
process. Coding of the solution should be such that every permutation and
combination of various positions should be addressed. A programmer is
blessed to chose from various choices of coding available. If our coding
system is not efficient then it will not affect our solution quality as GA’s
are robust in their working. Our coding system should be such that short
and high showing schemata should be applicable to the basic problem and
it should select the unimportant alphabet that represents the solution of the
problem. In our earlier example, we had laid stress on binary coding. We
can also try many non binary encoding mechanisms. Comparison between
the two is given in Table 2.
For example we had mapped 6 bit with the combination of alphabets and
numbers (Table 3).
91
Genetic Algorithm (GA) Methodology and Its Internal Working
Table 2. Comparison between the two decimal value and Non binary value.
Since l = 5,
00 000 = Umin
11 111 = Umax
92
Genetic Algorithm (GA) Methodology and Its Internal Working
Here each of the five bits represents one parameter so in total of 50 bit.
Code in C++ language is given below:
5.6 CONCLUSION
93
Genetic Algorithm (GA) Methodology and Its Internal Working
REFERENCES
94
Genetic Algorithm (GA) Methodology and Its Internal Working
95
Genetic Algorithm (GA) Methodology and Its Internal Working
for(i = 0;i<50;i++)
{ oldp[i].p1 = 0;
oldp[i].p2 = 0;
oldp[i].crosss = 0;}
initialize();//Generate Initial Population
writereport();//Print Whole Population & their objective
function values & parents p1 & p2, cross over site
getch();
statistics();//Calculate & print max., min. & avg. objective
function values of a generation
for(int z = 0;z<50;z++)
{
generation();//Crossover & Mutation
for(i = 0;i<50;i++)
oldp[i] = newp[i];
//writereport();
calcobjfun();//Calculate Objective Function
statistics();//Calculate & print max., min. & avg. objective
function values of a generation
cout<<” “<<z<<endl;
getch();
}
getch();
}
void initialize()//Generate Initial Population
{ int x,i,j;
time_t t;
srand((unsigned) time(&t));
for(i = 0;i<50;i++)
{ for(j = 0;j<30;j++)
{ x = rand() % 100;
if (x < 51)
oldp[i].a[j] = 0;
else
oldp[i].a[j] = 1;}}
}
void writereport() //Print Whole Population & their objective
function values & parents p1 & p2, cross over site
{ cout<<”Initial population generated is”<<endl;
for(int i = 0;i<50;i++)
{ for(int j = 0;j<30;j++)
cout<<oldp[i].a[j];
//cout<<endl;
oldp[i].value = objfun(oldp[i].a);
cout<<”value = ”<<oldp[i].value;
cout<<”Parent1 = ”<<oldp[i].p1;
cout<<”Parent2 = ”<<oldp[i].p2;
96
Genetic Algorithm (GA) Methodology and Its Internal Working
cout<<”Cross Site”<<oldp[i].crosss;
cout<<endl;
} }
float objfun(int a[]) //Calculate Objective Function
{long int value = 0; int i; float value1;
for(i = 0;i<30;i++)
{ if (a[i] = = 1)
value = value + pow(2,i);}
value1 = (float) value/1073741823;
return value1;}
void statistics() //Calculate & print max., min. & avg.
objective function values of a generation
{
sumfitness = 0;
float avgfitness;
int i;
for(i = 0;i<50;i++)
sumfitness = oldp[i].value + sumfitness;
avgfitness = sumfitness/50;
cout<< ” “<< avgfitness;
float min;
min = oldp[0].value;
for(i = 0;i<50;i++)
{ if(oldp[i].value< min)
min = oldp[i].value;
}
// cout<<”min. value”<< min;
float max;
max = oldp[0].value;
for(i = 0;i<50;i++)
{ if(oldp[i].value>max)
max = oldp[i].value;
}
cout<<” “<<max;
}
void generation()//Crossover & Mutation
{ //static int f = 0;
int g;
g = random(101);
if(g<cross) //Crossover
{
for(i = 0;i<50;i = i+2)
{
int crss = random(30);
// cout<<”crossover site is”<<crss;
// cout<<endl;
int p = selection();
int q = selection();
97
Genetic Algorithm (GA) Methodology and Its Internal Working
newp[i].p1 = p;
newp[i].p2 = q;
newp[i].crosss = crss;
newp[i+1].p1 = p;
newp[i+1].p2 = q;
newp[i+1].crosss = crss;
for(j = 0;j<crss;j++)
newp[i].a[j] = oldp[p].a[j];
for(j = crss;j<30;j++)
newp[i].a[j] = oldp[q].a[j];
for(j = 0;j<crss;j++)
newp[i+1].a[j] = oldp[q].a[j];
for(j = crss;j<30;j++)
newp[i+1].a[j] = oldp[p].a[j]; }
for(i = 0;i<50;i++) //Mutation
{
for(j = 0;j<30;j++)
{ int g1;
g1 = random(1000);
if(g1<m)
{ if(newp[i].a[j] = = 0)
newp[i].a[j] = 1;
else
newp[i].a[j] = 0;}
}
} }
else
{ for(i = 0;i<50;i++)
newp[i] = oldp[i];
for(i = 0;i<50;i++)
{
for(j = 0;j<30;j++)
{ int g1;
g1 = random(1000);
if(g1<m)
{ if(newp[i].a[j] = = 0)
newp[i].a[j] = 1;
else
newp[i].a[j] = 0;}
}
}
} }
void calcobjfun()
{ for(i = 0;i<50;i++)
oldp[i].value = objfun(oldp[i].a) ;
}
int selection()
{int i; float r1,r, partsum, rando;
98
Genetic Algorithm (GA) Methodology and Its Internal Working
partsum = 0; i = 0;
r = random(100);
r1 = (float)r/100;
rando = r1*sumfitness;
while(partsum< = rando && i<50)
{
partsum = partsum+oldp[i].value;i = i+1;
}
return(i-1);}
99
100
Chapter 6
Understanding Genetic
Algorithm (GA) Operators
Step by Step
ABSTRACT
In today’s world of soft computing, GAs are a hot topic. Researchers developed
this fascinating application to face or to counter many difficult problems which
cannot be solved through traditional approaches. We have seen that in the
published work of GAs, an author does not reveal the working of the GA as a
whole. In this chapter, the authors tried to untwist the GA methodology. This
knowledge will be helpful in applying GAs for various applications (i.e., in
the fields of science and technology and business). In the case of business-
related problems, the use of GAs will have viable value. This chapter is a
guide to using GAs vs. other soft computing techniques. Later in the chapter,
the authors explain the working and comparison of GAs by using question
and answer format.
6.1 INTRODUCTION
DOI: 10.4018/978-1-7998-4105-0.ch006
Copyright © 2021, IGI Global. Copying or distributing in print or electronic forms without written permission of IGI Global is prohibited.
Understanding Genetic Algorithm (GA) Operators Step by Step
101
Understanding Genetic Algorithm (GA) Operators Step by Step
Past researchers have shown that these adaptive models have given
promising results. One of the examples of these adaptive statistical tools used
for optimization of various models if Genetic Algorithms (GA’s). Now a day’s
use of GA has conquered in almost all the system analysis and relevance. GA
is one of the most popular types of adaptive optimization technique which is
used to optimize parameter set of a mathematical function or a rule set also.
To my knowledge of past researches, these new approaches has achieved only
5% of their budding and a lot more work is to be done to fine tune them. To
my study these soft computing based techniques such as Neural Networks
(NN), Fuzzy logic, Genetic Algorithms (Gas) has only just arrived. These
techniques require a large processing power to get accurate results and perform
experiment on a large amount of data. With the availability of cheaper and
higher processing power computers experimenting on a large amount of data
and finding accurate results with the use of these soft computing techniques
has become easier. GA’s working or processing are always parallel in nature.
Here each iteration is independent to each other. Thus here n number of multi
processors and computers can be used to run these iterations parallel, which
results in saving of time.
Past theories or assumptions about market tell us those stock market posses
a property of randomness in its working. Based on this assumption Efficient
Market Hypothesis (EMH) states that market absorbs all the information in
it. Investors and traders try to optimize their profits.
Optimization is widely used in stock trading model. It is a basic building
block in it. Classical optimization procedures are used for several decades.
They occur with a problem of local optima. In case of multiple optima
function they may get stuck to local optima assuming it to be a global optima.
But advancement in optimization procedures leads to the development of
more advanced soft computing procedures such as Genetic Algorithms and
Simulated Annealing. GA’s are self adaptive procedures, which generates a
fixed number of solution generations after generation. GA’s are first invented
by John Holland of University of Michigan in 1960’s. Now a day’s GA’s are
becoming popular optimization procedures in all fields.
It is seen that combination of classical and neo soft computing based
optimization procedure has come into the picture. These are known as hybrid
procedures. Here GA working is used to obtained global scenery. And then
we turn to classical technique to fine tune it. Hybrid procedures are future
optimization procedures. These advances in optimization procedures were
notice by market forces. Several readymade commercial software’s packages
had come into existence for example Evolver is most popular amongst them.
102
Understanding Genetic Algorithm (GA) Operators Step by Step
Selection
Crossover
Mutation
103
Understanding Genetic Algorithm (GA) Operators Step by Step
104
Understanding Genetic Algorithm (GA) Operators Step by Step
105
Understanding Genetic Algorithm (GA) Operators Step by Step
Q- 1 Genetic Algorithms (GA’s) are used for which type of optimization types?
106
Understanding Genetic Algorithm (GA) Operators Step by Step
Ans: At first sight, GA tries to find best or optimal string. Since string
represents the solution itself. In a twist it finds the best possible solution
found until now. If our string represents a set of parameters, then our GA
will try to find the parameter set which gives us best solution. In other way
our solution is represented by fitness function in GA>
After the procedure of string representation is finalized, we will start
thinking about performance calculation or fitness function formula. We had
to give a thought that what we want to optimize. If fitness function formula
is not crafted carefully then we might end up in faulty result. This will not be
the fault of computer or GA but it will be of ours. We just are sure to properly
derive the fitness function formula.
107
Understanding Genetic Algorithm (GA) Operators Step by Step
Ans: Chaos theory only let you know that if the system is in chaotic or in
stable state. But after that what?. System degree of stability is the only result
that this theory gives. There are many equations or formulas with the help of
which you could forecast. But what if system is chaotic? You cannot go in a
reverse direction. You cannot make mathematical formula from a noisy data
patterns. It is virtually impossible. If this could be possible then in both cases
when the system is chaotic and stable, we will be able to forecast the data.
By going in reverse direction is not practically possible in chaotic system.
108
Understanding Genetic Algorithm (GA) Operators Step by Step
Ans: In past researchers who had applied chaos theory to the past market
data has found that stock market data trend or patterns repeat after every five
years. Thus for more accurate results, a training system has to developed
by taking data from the recent past. This could be helpful for applying GA.
whereas chaos theory helps to find the regions among the whole data, where
market is noisy as it will not be for best trader to predict it.
Ans: In case of Neural Network from input to output they are linked via a
certain network of nodes which are loosely connected to each other. Working
in a neural network is just like enlighten occult practice ie mysterious and
black box in nature. It gives good results but what is the modus operandi, it
is not known.
Other drawback is that a lot of experimentation is to done for more accurate
results. Experimentation can be done in a number of of types as there are
n ways by which we can apply neural network to forecast data i.e possible
parameters that can be varied is node connection, total number of hidden layers
etc. Hence neural network can be applied in infinite number of ways. Since
neural network working is of iterative in nature, so they are time consuming
109
Understanding Genetic Algorithm (GA) Operators Step by Step
and require a lot of processing power and memory when applied on a stock
market data to get more accurate results.
Ans: Quick answer is a little bit. Almost all steps of GA procedures are of
similar in nature and are same for all problems. In GA steps like selection,
crossover and mutation are applied in a repetitive manner on the strings. Only
system information that is needed is the fitness function calculation of the
string. So the process that changes from problem to problem is the fitness
function formula and data interrogation. Various function codes of GA such as
selection, crossover and mutation and all other minor function such as initial
population generation etc. does not changes from one system optimization
to other. Exception is that if we use some advance GA operators, as we are
going to discuss them in later chapters of the book. Otherwise coding does
not have to change. We can use any high level computer language such as
Pascal, FORTRAN, C, C++, Java or Mat lab to write a GA code. If you are
not good in knowledge of programming languages or programming itself,
then there are many free GA code made available by GA practitioners, which
makes your task easier.
Where as in case of other soft computing techniques such a s neural
networks, many open source and paid software’s are available, which are
good for users who are not good in writing codes. Though there are infinite
number of combinations or variations among GA operators and n number of
110
Understanding Genetic Algorithm (GA) Operators Step by Step
Ans: GA works with a great speed. Within a short period of time they
are able to search large spaces heuristically. Thus they are perfect for large
search space complex problems. GA is also useful for small search space
problems i.e small string size, but where fitness function calculation is
complex and time consuming. In case of small search space one of the other
search procedures is to us e brute force technique or enumerative search. But
if time is a constraint the GA will be the best technique to use it. Thus crux
of our discussion is that GA is not only good to be use for large search space
and complex problems, but also good for small search space and complex
fitness function problems also where time is a constant.
Q- 15 How will you find or test quality of solution find out by GA?
111
Understanding Genetic Algorithm (GA) Operators Step by Step
Ans: It may happen. First reason for it is that GA solution may converge
after few generations. This happens if selection technique is of greedy in
nature and number of generations and population size are not adequate.
Other reason may be faulty string representation and not so perfect fitness
function formula. Hence to implement a GA we right a computer code. As
computer program is a set of instructions. Poorer or faulty instructions will
not give us not so good results. Last but not the least is bad luck. As GA are
heuristic based techniques, so if we start with some poorer solution randomly
selected. It may happen that after certain successive generation’s solution
quality remain poorer and may not recover. A lot number of different trials
may give better results.
Ans: Speed is a relative term in our search procedure. Our earlier program
was coded in C++. As processing power of computers are increasing for
several years. Time require to do excessive data access and their calculation
is decreasing day by day. With better data analytics approaches, programming
approaches and newer problem representations and fitness function calculation,
112
Understanding Genetic Algorithm (GA) Operators Step by Step
Ans: As father and inventor of GA John Holland has provided a solid base
of the theoretical proof of GA. Searching many search spaces parallel at a
given point of time makes GA a very effective and efficient search technique.
Mathematical representation of GA is very complex and tedious. A lot of
theoretical mathematical representation work has to be done in GA.
6.5 CONCLUSION
The main aim of this chapter is to give a brief reference about Genetic
algorithms (GAs). Frequently asked questions are answered satisfactorily. In
113
Understanding Genetic Algorithm (GA) Operators Step by Step
question and answer format reader will quickly absorb the working of Genetic
algorithms (GAs) and its comparison with other soft computing techniques.
REFERENCES
114
115
Chapter 7
Operator Control Parameters
and Fine Tuning of Genetic
Algorithms (GAs)
ABSTRACT
Genetic algorithms (GAs) are heuristic, blind (i.e., black box-based) search
techniques. The internal working of GAs is complex and is opaque for the
general practitioner. GAs are a set of interconnected procedures that consist
of complex interconnected activity among parameters. When a naive GA
practitioner tries to implement GA code, the first question that comes into the
mind is what are the value of GA control parameters (i.e., various operators
such as crossover probability, mutation probability, population size, number
of generations, etc. will be set to run a GA code)? This chapter clears all
the complexities about the internal interconnected working of GA control
parameters. GA can have many variations in its implementation (i.e., mutation
alone-based GA, crossover alone-based GA, GA with combination of mutation
and crossover, etc.). In this chapter, the authors discuss how variation in GA
control parameter settings affects the solution quality.
7.1 INTRODUCTION
DOI: 10.4018/978-1-7998-4105-0.ch007
Copyright © 2021, IGI Global. Copying or distributing in print or electronic forms without written permission of IGI Global is prohibited.
Operator Control Parameters and Fine Tuning of Genetic Algorithms (GAs)
116
Operator Control Parameters and Fine Tuning of Genetic Algorithms (GAs)
117
Operator Control Parameters and Fine Tuning of Genetic Algorithms (GAs)
118
Operator Control Parameters and Fine Tuning of Genetic Algorithms (GAs)
119
Operator Control Parameters and Fine Tuning of Genetic Algorithms (GAs)
In the working of GA, there are two main working operators’ i.e crossover
and mutation. There are a large number of past studies which explain the
role of these operators. Still there is no one study which gives us a correct
answer, that any one of these operator is powerful than other. Both of these
120
Operator Control Parameters and Fine Tuning of Genetic Algorithms (GAs)
operators are powerful when compared. Both of these operators have different
roles to play in GA working.
It is that mutation alone with some adjusted rate along with selection
operator has given better results. It is a very important operator and it gives
better results in an less time, when used with some adjusted rates. There are
two camps in GA practitioners; one say mutation has an edge over crossover,
other say vice versa.
A lot of theoretical and empirical studies have been done to examine the
effect of these operators on solution quality. Most of the researchers consider
crossover as a frontline operator with primary importance and mutation as a
background operator. They believe that use of mutation alone is not sufficient.
These all studies are deceptive in nature and results obtained by one researcher
contradicts or dispute the result obtained by another researcher. Until this date
there is no fixed analysis that validates the belief of crossover and mutation
camp. To my sense one cannot say that any of the two operators is more
powerful than other. Both operators have different functions to perform when
applied in combination or isolation. There is no doubt that both operators
are integral part of GA. Here we validate the claims of both these camps.
There are two roles of a GA operator, one is disruption or disordering or
disturbance, and other is construction or building block. Both the operators
consist of both of these properties but with a varying intensity. It is seen that
disruptive property is more in mutation as compare with crossover operator.
While ability to preserve a building block is more in crossover operator as
compare to mutation operator. It is seen that crossover is a working of two
individuals while mutation is working of one individual. Mutation of a single
bit does not affect the mutation of another bit. Results of crossover produce
two offspring, while results of mutation produces only one offspring.
John Holland (1975) in his book “Adaptation in Natural and Artificial
Systems” gives us a detail working of behaviour of these constructive
and disruptive rates of these operators. For both crossover and mutation
the disruptive rates depends upon their probabilities. In case of crossover
another parameter i.e number of crossover points will decide its disruptive
rates. Higher probability of crossover and larger number of crossover points
will lead to higher disruption rate. Thus in no way crossover has a lower
disruption rate than mutation. The difference is the way by which we apply
crossover operator. Mutation is an operator that selects a bit depending upon
the mutation probability and then flips or change that bit from 0 to 1 or vice
versa. This proves that though disruption rate of mutation is higher in any
121
Operator Control Parameters and Fine Tuning of Genetic Algorithms (GAs)
case, but higher rates of disruption in crossover can be achieved with its
proper implementation as described above if needed.
Disruption is a process when the building block in the binary strings is broken
down. Thus disruption somewhat leads to exploration towards newer search
spaces. It is seen that crossover with many points or uniformity is more
disruptive or explorative than crossover with single or two point crossover.
Now comparing this power of disruption or exploration with mutation.
In mutation a bit is changed if it is selected. If mutation rate is 0 then no
disruption or exploration will takes place, but if mutation rate is 1 then
disruption is at its peak. Better and higher level building blocks will be lost
due to high rate of mutation. Thus in both of these operators same rate of
exploration or disruption can be obtained provided mutation and crossover
rates are adjusted properly.
Suppose two hyper planes have bit position in common. Then in crossover
there is a guarantee that positions are similar in two hyper planes will preserve
and these building blocks will cross to next generation for sure. While in case
of mutation it is not sure that higher level building blocks is not disrupted.
Thus by studying the behaviour of GA working of GA is anticipated. From
the above theory it is clear that mutation has got higher disruptive rate as
compare with crossover. In some cases crossover has limitations for disruption
or exploration as an operator, no matter what the crossover rate or crossover
points are there. Crossover conserves alleles at the cost of mutation. While
mutation does helps in protecting the building blocks. Until now crossover is
considered to be a disruptive operator. In contrast crossover is constructive
in nature. Here higher order building blocks are made from lower order
building blocks. When disruption level is more in the population, higher level
of construction can only be obtained through the use of crossover operator.
This leads to the convergence of population. Hence mutation at this stage can
add much needed genetic diversity. In comparison with mutation, crossover
has higher construction rate and survival. Thus in this way crossover is one
up to mutation operator. In mutation we can obtain higher construction
level, but rate of survival or passing of important alleles to next generation
is compromised. This is not the case with crossover.
In case of construction mutation cannot perform to a degree to which
crossover is a go getter. In case of disruption no matter by what settings
122
Operator Control Parameters and Fine Tuning of Genetic Algorithms (GAs)
123
Operator Control Parameters and Fine Tuning of Genetic Algorithms (GAs)
operator leads to the loss of much needed genetic diversity in order to effectively
run GA simulations for further few left over generations. Generally high
mutation rate is a random walk. It helps to regain desired building blocks
which have lost in initial generations. In general frequency of mutation is kept
very low i.e 10 mutation bits per 1000 bits in total i.e Pm in this case is 0.01.
It is also known that rate of mutation depends upon various other factors i.e
encoding mechanism, type of optimization problem, greediness of selection
operator in use, population diversity or its size etc. It is not the working of
mutation operator that improves the fitness, because results in a random walk.
It is the selection operator that improves the fitness function as it selects the
individuals with higher fitness values and discards less fit members, which
increases the average fitness function of the population, thus improving
the overall fitness function of the population. In this way generation after
generation there is a continuous improvement in the maximum and average
fitness of the population.
A popular view about mutation is that it is a background operator, disruptive
in nature and must be used infrequently or cautiously. It tends to destroy binary
pattern in the string and generate random noise in the population. Thus in
order to avoid danger to eliminate highly fit schema, which is present in the
population, mutation is used with caution. So possibility of the schema to get
survives increases. In contrast if crossover point accidently fell in between
the highly fit schema, mutation is used to retrieve the building block which
has been lost. Thus the role of mutation can be constructive or destructive
depending upon the rate to which it is applied.
If in a particular problem tie to calculate fitness function is more, than
number of iteration in a GA to be run should be kept low i.e compromise
in the population size has to be made. So to add genetic diversity in the
population higher mutation rate has to be applied. Otherwise GA will run
with a slow improvement rate. It is also seen foe normal problem if mutation
rate is kept high, then GA run resembles like a random walk and preventing
GA population to converge. In case of tripartite GA as discussed in previous
chapters low mutation rate is sufficient. If convergence in GA population is
not reached after subsequent generations is not reached, than there is no need
for higher rate of mutation.
Hence to conclude mutation may develop a new building block, but may
disrupt many other higher level building blocks or high level schemata already
present in the population. Mutation also includes diversity as well as new
information in the population.
124
Operator Control Parameters and Fine Tuning of Genetic Algorithms (GAs)
125
Operator Control Parameters and Fine Tuning of Genetic Algorithms (GAs)
7.8 CONCLUSION
We should select and tune GA operators in such a manner, that they do not
affect, GA success rate. Though GA working is robust in nature, as GA with
only one operator in isolation will give better result than traditional numerical
based method. In order to fully exploit the GA working, proper use of selection,
crossover, mutation operators with above threshold population size is needed.
In the end of this chapter a large amount of important information is obtained
by studying the working of these operators and how to fine tune them. Our
questions about the importance of GA control parameters and their best
settings are altogether given by reading this chapter.
126
Operator Control Parameters and Fine Tuning of Genetic Algorithms (GAs)
REFERENCES
127
128
Chapter 8
Advance GA Operators
and Techniques in Search
and Optimization
ABSTRACT
Genetic algorithms (GAs) are the latest technique to solve problems. A huge
amount of research work is available but still there are a lot of newer avenues
which have to be explored. In this chapter, the authors discuss variations in
the GA operators that can be done and various other background operators
that can be use to improve the efficiency and efficacy of GAs. It is not just like
a mathematical or statistical technique. In this chapter, the authors discuss
various procedural variations, twists and turns, and special meaning they
could give to the GA operators in order to improve the solution quality.
These newer operators and variations might be useful for researchers in the
implementation of GAs to find better solutions.
8.1 INTRODUCTION
Use of science and technology is to make human life simple. Basic science and
technology extract the laws of the nature. The invention of electronic machine
called computer is the most feasible development in the past. With the help
of large processing power provided by computer, our power of prediction
and decision making capability has increased many fold. We have to make
decision in every sphere of human activity weather in engineering field or
DOI: 10.4018/978-1-7998-4105-0.ch008
Copyright © 2021, IGI Global. Copying or distributing in print or electronic forms without written permission of IGI Global is prohibited.
Advance GA Operators and Techniques in Search and Optimization
technical field. This affects the end product or the desired result we need.
In any problem there consists of large number of solutions. Some solutions
have large pay off values as compare to other. The engineer should be able to
pin point the solution with a larger pay off according to its feasibility. Then
he should search feasible solutions to get the optimal value. Searching the
solution area is of two types, Deterministic and Stochastic. Deterministic
search technique uses steepest gradient method while stochastic method
uses randomization as a process to reach towards the optimal value. Various
other non traditional methods have also come into picture and has become
popular now a days. These methods or algorithm are: simulated annealing,
particle swarm optimization, ant colony algorithm, Genetic programming,
Genetic algorithms etc. We are going to discuss all these algorithms in the
last part of this book. GA is based on the Darwin theory of natural selection
and survival of fittest (Goldberg, 2002).
In past computer scientists develop some evolution strategies in which
evolution is used to optimized the design parameter fir the given engineering
problems. In evolutionary population approach, population of solution for
the given problem is generate and by applying various operators which were
inspired from the nature to generate newer population of solutions with
higher fitness and acceptability. Evolutionary optimization is a popular and
active research area now days. Concept of evolutionary programming was
first developed by I. Recenberg, a German scientist in 1960’s. He published
his work named “Evolution Strategies”. GA’s are soft computing based
search and optimization procedures based on the concept of natural genetics
and selection. GA’s are invented and developed by John Holland and his
colleagues and students of University of Michigan USA in 1960’s and 1970’s.
GA’s is a general purpose optimization search procedure and is not design to
solve specific problem. They can be applied in any field of engineering and
technology. Holland in his work published as a book “Adaptation in natural and
artificial systems” in 1975 explains the theoretical working of GA. After that
a lot of work is done by (David E Goldberg, 1989), (Kalyanmoy Deb, 2002)
were published in the public domain. In GA we move from one population of
chromosomes (i.e array of strings of 0’s and 1’s) to another newer population
by applying genetic naturally inspired popular operators such as selection,
crossover, and mutation. A selection operator selects chromosomes having
fitness value more that the average fitness value of the population. Crossover
exchanges part of string in two chromosomes with each other. Mutation when
129
Advance GA Operators and Techniques in Search and Optimization
and where applied changes the binary value of the chromosome i.e from 0
to 1 and from 1 to 0. These procedure developed by Holland were a major
breakthrough in the field of search and optimization. Popularly it came to
be known as Genetic Algorithms. Theoretical foundation of GA is based on
the concept of Schemas and building block hypothesis as explained in the
previous chapters. Based on this theory GA procedure are explained as below:
With the invention of GA, computation evolution has been put on a firm
footing empirically. Until now theoretical foundation was in picture. With
the wide spread research in GA’s, boundaries between GA and evolutionary
computing now over lap each other. GA is now represented as evolutionary
computation in a majority way (Hupt et.al, 2004).
GA is generally guided in many directions by the use of these three
operators: selection, crossover and mutation. In our passion to keep working
of GA simple, we are introducing several variations in these operators as well
as many other interesting operators. This will help us to improve efficiency
of GA and we will be able to prove GA as a robust search and optimization
technique. These advance and low level operators will be helpful in improving
GA’s working. Some of these operators may be problem specific dependent
(Rajesekaran et.al, 2007).
130
Advance GA Operators and Techniques in Search and Optimization
8.2.1 Encoding
Chromosome A: 1100010101
Chromosome B: 0011011011
Here solution to the problem is represented by the use of 0’s and 1’s. The
total length of string gives the accuracy. More the string length more is the
accuracy, less is the length less is the accuracy. Representation of 3 bit binary
string is given as below:
For example:
101 = 1 * 20 + 21 * 0 + 22 * 1 = 5
131
Advance GA Operators and Techniques in Search and Optimization
XiL≤Xi≤XiU
If three bit strings are used then (000, 000) and (111, 111) are the lower
and upper limit. (X1L, X2L) and (X1U, X2U) representation. The formula for
decoding value of binary string is given below:
K =n (i −1)
(x + a )
n
=∑ 2k SK
k =0
Skis the binary string value. So S1 S2 S3.....Sn-1, Kis the bit position.
If we know the lower limit and upper limit of the string i.eXiL, XiU
equivalent value of a string is given below:
132
Advance GA Operators and Techniques in Search and Optimization
A three bit octal string represents number to a range from 0 to 511. Thus
(000, 000) and (777, 777) are the lower limit (X1L, X2L) and upper limit
respectively. The decoded value of the string formula is:
K= n-1
∑ 8KSK
K=0
K= n-1
∑ 8KSK
K=0
133
Advance GA Operators and Techniques in Search and Optimization
Chromosome A: 5 7 6 2 9 7 1
Chromosome B: 2 9 3 7 6 8 5
The integer number can represent the order of city or distances between
the city in case of travelling salesman problem.
134
Advance GA Operators and Techniques in Search and Optimization
8.2.2 Reproduction
n
Pi = Fi / ∑ Fj
j =1
135
Advance GA Operators and Techniques in Search and Optimization
n
∑ Fj = Total fitness of the population.
j =1
136
Advance GA Operators and Techniques in Search and Optimization
will be given rank n (as total population size is n) and worst string
or chromosome will be given rank 1. Thus a new roulette wheel is
constructed with rank or assignment functions as their slots. This type
of selection procedure added much need noise in the next generation
population and thus decrease rate of convergence.
4. Tournament Selection: Tournament means a match between two or
more than two members. Winner member will be selected for mating.
In tournament selection two members are selected randomly from the
pool of the population. Fitness of these two populations is compared.
String having better fitness is selected and copied into the mating pool.
It means that its allele will be part of next generation. This whole
process is repeated until mating pool is filled up by desired number of
strings. In this way newer mating pool will have higher average fitness
function than from the previous one. As winner string is selected. Due
to this selection pressure quality of strings will improve generation after
generation. This will automatically leads to optimal solution in the end.
5. Steady State Selection: This selection process is different from the
previous ones. Here in every generation few chromosomes or individuals
having higher fitness function are selected from the population. They
are going to replace some bad or worst chromosomes and a new set of
individuals for mating pool is created.
6. Elitism Selection: In this type of selection procedure better fitness
chromosomes are copied to form a new population. This increases overall
efficiency of GA and best solution is not rejected. Elitism technique
selects better fit individuals for mating pool. Better fit individual will
be selected larger number of times, while lesser fit individual will be
selected lesser number of times. Some of the worst fitness string will
be rejected and eventually die off. The factor or parameter which will
decide which individual will be selected or rejected is F/ḟ where F is the
fitness of the string and ḟ is the average fitness of the population from
where strings are selected.
137
Advance GA Operators and Techniques in Search and Optimization
areas of search space. Selective pressure means the rate of level by which
better performing string is captured. In other words it defines the greediness
of the selection procedure.
Both of these parameters are inversely proportional to each other. Higher
rate of selective pressure will lead to the loosening of population diversity.
And this results in convergence of population quickly or prematurely. Thus
in this way we stuck up in a local optima as diversity in the population is
lost at an early stage. Selective pressure is decreased in order to reduce the
convergence rate. Thus GA will take some more generation to find a global
optimal solution. Thus in a selection operator proper balance between selection
pressure and population balance must be made. Thus higher rate of selection
pressure or greediness in the selection procedure will lead to the stagnation
and quick convergence of the population towards the local maxima. The
selection operator should be able to add noisiness in the mating pool. Thus
choice of selection operator should have balance between exploitation and
exploration. Exploitation leads to quick convergence, lesser fit solution. While
exploration leads to not so quick convergence, but higher quality of search.
In simple GA crossover and mutation are the two main operators. We will
discuss variation in these two operators first and then we will discuss various
other low level operators also.
8.2.3 Crossover
After selection operator fills the mating pool with better fit individuals,
Crossover operator is applied. Crossover operator is a critical operator. It is
of disruptive in nature. Better strings patterns will be broken. If crossover
frequency is more and crossover points are more than search is just like a
random walk or noisy in nature. It will leads us to nowhere. It will stuck us to
the narrow regions of the search space. Crossover is a recombination operator.
A crossover site is generated randomly and string values are swapped. There
are many variations in crossover process in GA. They are discussed in the
coming section:
1. Single Point Crossover: It is the most simplest and basic form of crossover
operator. Here a point is chosen randomly between the starting and
maximum length of the string. Binary bits after that points in both of
the strings are exchange as shown below:
138
Advance GA Operators and Techniques in Search and Optimization
Chromosome 1 :
11110 11001
(Parent )
Chromosome 2 :
11000 00001
(Parent )
Chromosome 1 :
11110 00001
(Offspring )
Chromosome 2 :
11000 11001
(Offspring )
Chromosome 1 :
11 110110 01
(Parent )
Chromosome 2 :
11 000000 01
(Parent )
Chromosome 1 :
11 000000 01
(Offspring )
Chromosome 2 :
11 110110 01
(Offspring )
139
Advance GA Operators and Techniques in Search and Optimization
Chromosome 1 :
00 000 0000 00000
(Parent )
Chromosome 2 :
11 111 1111 11111
(Parent )
Chromosome 1 :
00 000 0000 00000
(Offspring )
Chromosome 2 :
11 111 1111 11111
(Offspring )
Chromosome 1 :
000000000000
(Parent )
Chromosome 2 :
111111111111
(Parent )
Chromosome 1 : ↓ ↓ ↓ ↓ ↓
100100100101
(Offspring )
Chromosome 2 : ↓ ↓ ↓ ↓ ↓
011011011010
(Offspring)
140
Advance GA Operators and Techniques in Search and Optimization
8.2.4 Mutation
1000
1100
1010
0100
Now in all those strings right most strings have a value 0, if global optima
requires value 1 in that position. Crossover cannot add this diversity in that
position. It can only be added by the use of mutation operator. Though
secondary, it is the important operator in the GA search. Mutation operator
can be applied bit by bit or string by string. In string case whole binary string
values are reversed, if mutation operator is applied.
Bit by Bit mutation operator
↓ ↓
0001001
After Mutation
1001000
141
Advance GA Operators and Techniques in Search and Optimization
0001001
After Mutation
1110110
Mutation operator rate is generally kept low i.e0.01, that means 1 bit per
100 bits or 10 bits per 1000 bits. Apart from these basic operators, there are
a lot more number of various not so important low level operators. When
used strategically these operators gives us better results and add much needed
power to GA. Some of them are listed below:
1. Inversion.
2. Dominance, Diploidy.
3. Deletion.
4. Intra chromosome duplication.
5. Translocation.
6. Segregation.
7. Speciation.
8. Migration.
9. Sharing.
10. Mating.
11. Bit wise operator.
In more detail:
142
Advance GA Operators and Techniques in Search and Optimization
4. Segregation: Here bits are selected and rearranged to produce new string.
↑ → ↓
10 0 000 01
↑ ← ↓
10010000 New string
143
Advance GA Operators and Techniques in Search and Optimization
01 001001001 01 Parent 1
BeforeCrossover
01 111011011 01 Parent 2
01 111011011 01 Parent 1
After Crossover
01 001001001 01 Parent 2
01 000100100 01 Parent 1
After Inversion
01 110110110 01 Parent 2
~ 1000110110
0111001001
144
Advance GA Operators and Techniques in Search and Optimization
c. Shift operators: There are two types of shift left shift («) and right
shift (»). Operator here is applied on to the string. Apart from string
it requires number of positions the binary bits has to be replaced.
This number is given as unsigned integer.
Shift left («): It is shown below
A = 111000111
A « 3 = 000111000
A = 1110000111
A » 3 = 0001110000
Here the bits are shifted in the right direction by the position given
in the number. Thus the left most vacant position is filed by zeroes.
d. Masking: Here given bit pattern is changed to another bit pattern
by using logical bit wise operator. Here two operands are used. One
operand is original bit pattern, while second operand is the mask
i.e a selected bit pattern that does the transformation.
These all bit wise operator can be used in GA to produce new
population or children of next generation. Here in GA, operators are
applied number of times in order to keep population size constant.
7. Dominance and Diploidy: These two operators are the most important
operators, but they are being discussed at last. In biology books, chapter
on genetics start with the work done by Mandel on peas plants, with
mention of dominance (Goldberg, 2002). We in our book are explaining
dominance and diploidy in last because we want to systematically explain
the role of selection, systematic recombination and other operators
first. In nature organisms are diploid and polyploidy in their genetic
structure. This lead us to make assumption, that we cannot applied them
in artificial genetic search i.e in Genetic Algorithms. The coming part
145
Advance GA Operators and Techniques in Search and Optimization
Until now in our GA search we had considered simple genotype i.e haploid
or single stranded chromosome. But it is well known that the working of
nature is not simple. Natural organisms consists of more complex chromosome
structures ie. polyploid or homogeneous chromosomes. Here we are going
to understand only diploid chromosome structure i.e chromosome in pair. In
this type genotype structure consists of one or more pairs of chromosomes,
which consists the information about the same function. Now the question
arises that if this redundancy or repetition is important or not. Why kept
number of pairs of chromosomes that decode the same function, but with a
different answer or values. Now from this pair of chromosome which portion
we will pay more attention and select it. Let us understand this complexity
by an example given below.
Let there be a two chromosome structure
P q R s t u
P Q r S T u
Here each letter weather upper case or lower case represent a alleles, but
with different nature or character tics. Each allele represent different feature
of organism. For example q allele represents a fair skin and Q allele represents
dark skin. So a person cannot be fair and dark skin feature simultaneously.
Nature has to choose from any of the one value. This allele value q and Q
have different feature and offspring can have either q or Q feature. This will
be decided by the genetic operators called dominance. In final string one
allele takes over dominantly over the other. It is expressed in the final string.
The rule is that if capital letters are dominant over lower case or small case
letters then:
P q R s t u
→ P Q R S T u
P Q r S T u
IT means
146
Advance GA Operators and Techniques in Search and Optimization
Now the abstract view is clear. The question arises what is the use to carry
double information, and then we cut information to half and use it. By seeing
it in vogues it seems to be an unnecessary and time consuming step. In real
nature no process is wasteful. There should be rationale behind this step i.e
repetition of previous chromosomes and applying dominance operator on it.
In nature there is a requirement of such type of arrangement, as it protects
genes of older generations against the rapid changes in the environment i.e
from hot climate to cold and then to a bearable temperature, from darkness
to light. Hence there are many rapid changes in the environment. Thus
the organism which has diploid or polyploidy structure, will have greater
chances to survive in the this extreme change in the environment. This due
to the reason that previous generation genes are not lost and preserved in
their diploid and poly diploid structures. Thus multiple combinations exist
and only one combination is expressed. Thus old genes are not forever if
not selected. In this way they come into picture when required by the use of
dominance operator, which is used occasionally or sparingly.
In case of Genetic Algorithms i.e our artificial search, some building
blocks in chromosomes are lost due to faulty or randomized selection operator.
Diploidy and dominance operator help us to carry these chromosomes as they
were useful previously and allow them to come into existence in the future
generations or in some hostile environment, when they are needed the most.
It is seen that these two operators must be applied rarely with a low degree.
Thus it empowers GA larger number of other solutions, resulting in an increase
of efficiency and efficacy. In this way GA allows many alternative solutions
to pass from one generation to other, and prevent them from being lost, as
compared with simpler implementation of GA presented earlier. We have
seen that applying dominance is not an independent act. Rather there must
be certain rule to apply it at a particular location. Researcher had suggested
certain schemes which are explained below:
147
Advance GA Operators and Techniques in Search and Optimization
Uptil now we had applied GA for uni modal function i.e function with only
one peak. It is seen from the results of researchers that GA was very effective
in finding a single global optimum and converging its population around it.
In other domain where there are multiple optima’s GA may find best peak
and converge population around it. It is unable to find other rules or lesser
peaks. Traditional GA are difficult to work for multi modal function.
It is seen for problems with equal multiple peaks traditional GA will
converge towards a single peak. Thus GA to find best rule, GA will converge
towards a single rule. Thus to allow or force GA to search for multiple peaks
and avoid converging its population to a single peak, various population
diversity schemes are suggested. Thus application of these schemes helps GA
148
Advance GA Operators and Techniques in Search and Optimization
to fetch multiple optima for a multi modal domain instead of single optimal.
This helps us to obtained both number and quality of optima.
To start with a multi modal domain, each peak or optimal point is called
as niche. Every niche consists of number of rules for the system to find best
rules of set of parameters. As there are number of niche with varying peak,
number of individuals in these peak should be directly proportional to niche
peak fitness as compare to other niche peak fitness values. Thus GA should
populate niche in proportion to fitness relative to other peaks. One problem
that occurs in implementing these population diversity schemes is that we
do not know the multiple peak of the location of the system. Due to this it
is difficult to populate each niche. Thus in order to identify various niche
location and proportional population values various mechanisms are devised
and discussed in next section.
149
Advance GA Operators and Techniques in Search and Optimization
Until now we are discussing objective function with single criteria. This
criterion is translated into fitness function. After this we apply various GA
operators to find the best or close to best solution founded until now for
a given problem. But in some problem multiple criterion are present at a
given time. Hence they all cannot be represented in a single function. These
types of problems are known as multiple objective optimization problems.
Many researchers in past has applied traditional process of optimization and
search to find best possible solutions find until so far. As stated that there
are multiple objective function in multi objective problem. Thus to represent
multi objective in one equation is:
F = X1 f1 + X2 f2 + ...........Xnfn
X1, X2, X3... are the weights and f1, f2, f3... are multiple objective function.
Here the solution is finding various optimal solutions of various single
objective function using different weight vectors. These various solutions are
called Pareto Optimal solutions. In latest GA is used to solve multi objective
problem.
Until now we all are very well versed with the working of GA. GA works with
the coded string of variables, not with the variables itself. GA need function
values for different variables. GA works with a population of chromosomes
or solution not with a single solution. This makes GA very effective search
methods as search parallel through various points. In GA multiple optima
solutions are found in a single run. This is not the case with the traditional
optimization and search methods. However there are various issues related
to GA while implementing them. They are:
150
Advance GA Operators and Techniques in Search and Optimization
• Easy to absorb.
• Support multi objective optimization.
• Favorable for noisy environment.
• After every iteration solution quality improves.
• Parallel search.
• Exploitative and explorative in nature.
• Best suited as a alternative for hybrid application.
• Popular among researchers and lot of research has been done until so
far.
GA are used when search space is very large, as brute force attack cannot
be applied, where traditional techniques is too slow and hybrid methods are
a failure.
8.6 CONCLUSION
Here we had discussed various not so popular advance operators, which can
be used to improve GA working. Various unary and binary operators has also
been discussed. Working of inversion, segregation, duplication, deletion and
various other types of selection, crossover a mutation operators been examined
in depth. Dominance and diploidy has been discussed at length, which uses
long term past population memory. Key theories of niche and there sharing
and crowding techniques has been briefly discussed. The literature we had
discussed so far is the tip of the ice berg of GA research available so far. It
is sure implementation of these advance GA operators will surely lead us to
improve GA performance and increase its efficiency and efficacy.
REFERENCES
151
Advance GA Operators and Techniques in Search and Optimization
152
Section 3
Genetic Algorithms in
Finance
154
Chapter 9
Genetic Algorithms (GAs)
and Stock Trading Systems
ABSTRACT
Recent advances and improvements in hardware and software technology
have benefitted research in the field of finance. It has made research even
more interesting. A large amount of data can be processed with lightning
speed. Investors are now eagerly looking for small models and algorithms of
a lucrative value and with better accuracy. Earlier, the decision to enter the
market or to exit is taken emotionally with fear then by any rational thinking.
Due to this, a lot of bad decisions were taken, and a huge amount of capital
was lost. With the help of this computational system, a computer program
will decide when to enter and when to exit the market without any human
intervention. The decision here will be taken by testing a large amount of
permutation and combination of various parameters associated with the system.
This chapter briefly explains the scope and agenda of various algorithms for
computation research in finance.
9.1 INTRODUCTION
DOI: 10.4018/978-1-7998-4105-0.ch009
Copyright © 2021, IGI Global. Copying or distributing in print or electronic forms without written permission of IGI Global is prohibited.
Genetic Algorithms (GAs) and Stock Trading Systems
155
Genetic Algorithms (GAs) and Stock Trading Systems
156
Genetic Algorithms (GAs) and Stock Trading Systems
model have to be found. In case of running and random test we select a set
of parameters randomly and then test it. If result obtained is not appropriate
then we adjust them according to our intuition and see how model behaviour
changes according to it. But if we follow some process, several traditional
optimization processes are there. Manually we change parameters settings
and see in which direction we get good results. We manipulate the parameters
and see effect of interaction of parameters on the solution quality. Another
process is brute force optimization (Lederman et.al, 1995). Here every
parameter setting from the starting to the nth setting is applied on the model
and solution quality is checked. The best solution quality obtained from the
set of parameters is taken for future use. There is problem with this approach,
if search space is large enough, then it will take years to check each and every
solution and then to find an optimal one. Brute force technique is workable
when search space is small. But brute force optimization technique is a
complete search technique found so far. So for large search space problems
heavy duty optimization methods such as genetic algorithms have proved
successful. GA’s when applied properly can find a optimal solution or close
to optimal solution when number of parameters involved are more. A GA
based strategic system is an important tool in the hands of stock trader or
analyst when applied properly.
It is seen that some algorithms find better solution in a lesser time. As we
are having constraints in data size and processing power. In order to be more
rational it depends upon which algorithm you use and how much processing
power your computer has. Better selection of algorithm and faster computer
can give better solutions as it will involve more rationality in making decisions
and thus lowering overall risks. Thus our rational reasoning depends upon
the type of algorithm we use and computation power we have in hand. It
also depends upon the cognitive reasoning and resources we had at our door
step. For ex. Nature of algorithm, processing power of our machine and
time we had got to make a decision. Here rationality of all the mathematical
and computation based models depends upon the quantification of resource
available. Hence for the best practice we should use fastest computer and
better or latest algorithm proven so far to value add in our results.
157
Genetic Algorithms (GAs) and Stock Trading Systems
Hypothesis (EMH) which is the basic assumption behind most of the analysis
to predict the market (Focardi et, al, 1997). The statement of Efficient Market
Hypothesis (EMH) dates back to early 1990’s i.e with the start of financial
markets. Efficient Market Hypothesis (EMH) conventionally states that markets
are efficient and absorbs all information i.e the market indices reflects all
the information available.
Now the question arises can we predict the market. By seeing the past
work of various researchers this question is discussed in a very detail manner.
Popular hypothesis in finance such as Efficient Market Hypothesis (EMH)
comes into picture, which states that we cannot beat the market; and in no
condition we can make profit from it by forecasting the market. Efficient
Market Hypothesis (EMH) in detail states that all information related to
the market is already shown in its prices and if any new information comes
into picture, market corrects itself according to the information. So market
is efficient and we cannot predict it by using any methodology. In fact there
are three types of Efficient Market Hypothesis (EMH):
• Weak: It states that, we cannot forecast the market based on the use of
past historic data.
• Semi Strong: It states that w cannot use any publishes or known
information to forecast the market.
• Strong: It states that any available information known or unknown in
public domain cannot be used to forecast it.
Y(t) = Y(t-1) + Rs
158
Genetic Algorithms (GAs) and Stock Trading Systems
There is a common feeling among the investors and non investors that a
large amount of capital is at stake throughout the stock markets of the world.
Stock market indices not only show the strength of a nation’s prosperity and
vice versa. They both are strongly linked with each other. Today in the age
of Information technology market is simply approachable not only to the
strategic experts but also to the common and naive investor also. The ups
and down of stock market effect our living every day. It has a direct impact
on our social life also.
A non desirable feature which is associated with the market is doubt, about
its state. This feature defines the nature of market and is inescapable in nature.
So our whole research in building of newer model is to reduce this ambiguity
feature. This model tries to tap the noisiness or randomness of the market.
Some researchers have attempted to predict market on daily basis, while
other say that market is efficient for long term. As we all know that power of
money derives not everything, but many things in this world. So this is the
main reason researchers are attracted towards the forecasting of stock market.
Fundamental is the monetary gain. There are many challenges in prediction,
since market is volatile and market data is of high frequency in nature. This
main feature of forecasting has been a main topic of discussion amongst the
researchers, and academician’s worlds wide. In field of finance a hypothesis
that has been formulated is very popular is Efficient Market Hypothesis
159
Genetic Algorithms (GAs) and Stock Trading Systems
(EMH), which states market absorbs each and every information related to
it and by no means can we forecast it. Many researchers and academicians
reject this hypothesis out rightly, many accept it. Till date Efficient Market
Hypothesis (EMH) has not been accepted undisputedly or no consensus has
been made on it.
By seeing this type of case of stock market forecasting, there are two groups
of researchers and agents. One says that we use various mathematical and
computational processes to predict stock market. So they challenge Efficient
Market Hypothesis (EMH) theory. Other group validates Efficient Market
Hypothesis (EMH), and says that market is efficient, as it absorbs every new
piece of information in it and corrects itself according to it. So there is no way
we can predict it. This group also lay emphasis on the fact that stock market
run is of a random walk and stock data is of very high frequency i.e of noisy
in nature. So best way to forecast the tomorrow opening price is by use of
human intuition only. A researcher from the group that contradicts Efficient
Market Hypothesis (EMH) uses a lot more number of methods to forecast
the stock indices. These methods or process are divided into four types
160
Genetic Algorithms (GAs) and Stock Trading Systems
follow it. Our study in this chapter and coming chapters is concentrated on
the soft computing based machine learning techniques, with special emphasis
on Evolutionary based computation i.e Genetic Algorithms (GA’s).
This section gives us a brief survey of some of the practices and notion that are
practiced in the stock market for prediction. An investment theory to predict
the market is based on the parameters which one should take into account
while entering or exit from the market (Bauer, 1994). Investor generally see’s,
thought and react. It is that this process which does the capital allocation to
the market.
It is of no doubt that majority or almost all of the investors enter into
the market to make money or to achieve profits. In order to make profit, we
should put capital in the stocks that have good future. This can only be done
by forecasting the market indices. An investor invests or divests money in
the market, depends upon the information they have, which is shown in the
market indices. According to fundamental analysis, the real or actual value
of stock depends upon the condition of the firm. While technical time series
prediction model investor action depends upon the investor behaviour or
actions. It does not depend upon the actual or factual value of the firm. Hence
in fundamental analysis there is 90% logic and 10% intuition or psychology.
While reverse is the case in traditional time series prediction. It believes that
market is driven only by psychology.
Market Data: The market trend i.e bearish or bullish run is predicted
by the detail analysis of the past or historic data. Data can be classified into
three parts:
1. Technical Data: It is the data which is directly associated with the stock.
For example closing price, opening price, day high, day low, volume of
shares traded per day, delivery volume etc.
2. Fundamental Data: It is the data which is directly related to the company.
For ex. Profit of the firm, Earning per share (EPS), trade orders etc.
3. Derived Data: This type of data is generated by changing or combining
various technical or fundamental data to generate a new data. For example
rate of return, volatility etc.
161
Genetic Algorithms (GAs) and Stock Trading Systems
A systematic analysis of all these all data helps us to make an insight into
the market working. We will be able to deduce or conclude various rules from
it. It is that conclusion which all the above methods discussed briefly is going
to do. The process is different for various prediction models.
Predicting any stock market indices is a very tedious and fascinating process.
Through the whole process your senses are on your toes. Various stock
market forecasting models vary from casual or relax way (i.e study of chart
mode from past data) to a more conventional or official way (i.e time series
analysis or regression analysis). Earlier in this chapter we had classified
various forecasting techniques as given below:
These above classification are different from each other in their type
of procedures and data type on which their experimentation is to be done.
Only thing that is common in them is that they forecast market indices for
the benefit of the investor. No one technique stated above is consistent in
prediction, so that the investor or trader can rely on it. Each technique has
been in question in some or the other way.
162
Genetic Algorithms (GAs) and Stock Trading Systems
163
Genetic Algorithms (GAs) and Stock Trading Systems
164
Genetic Algorithms (GAs) and Stock Trading Systems
These all soft computing techniques to forecast the data comes under the
classification of “Machine Learning Methods”. These soft computing technique
locate or pin point various unseen or hidden data patterns and find certain
useful inference from the data. Though this book is about application of Genetic
Algorithm in stock market, but we are going to discuss neural networks in
brief here. These two methods Neural Networks and Genetic Algorithms are
widely used in stock market prediction, but by seeing past we have got a rich
literature available in the public domain to study with. They both have been
used for stock market prediction individually in various permutations and in
combination with each other also known as hybrid techniques.
165
Genetic Algorithms (GAs) and Stock Trading Systems
166
Genetic Algorithms (GAs) and Stock Trading Systems
167
Genetic Algorithms (GAs) and Stock Trading Systems
{
Create a random population of individuals
Calculate fitness function
While (Termination Criteria as decided is not met)
{ Apply Selection Operator
Apply Crossover Operator
Apply Mutation Operator
} }
168
Genetic Algorithms (GAs) and Stock Trading Systems
have been applied to the problem which is NP hard, complex, non linear
and multi dimensional search spaces are there. In case of Genetic Algorithm
(GA) binary representation of chromosomes is done by default, while tree
based encoding is done in case of Genetic Programming (GP). Evolutionary
algorithm work or search many spaces parallel. Due to this feature they do get
stuck to local optima. This feature is desirable, but comes with a lacuna i.e
increase in computational time and requirement of more processing power.
As compared to Neural Network, Fuzzy Logic they are much slower in nature.
This slowness of algorithms can be checked by making efficient parameter and
coding settings or by use of advance operators in the algorithm as discussed
in previous chapters. One of the variations in Genetic Programming (GP)
is forest GP. Here each strategy is a set of various sub strategies. Each sub
strategy has different objective function. Thus each sub strategy is called a
tree and whole set of this sub strategy is called a forest. This type of strategy
is used for multi objective optimization. So each chromosome here is a forest,
which is a set of multiple trees. Each tree has its own objective function which
is totally different and independent from other trees. If all tree in the forest
Genetic Algorithm (GA) has same objective function then multiple objective
function will be changed to single objective function.
Evolutionary algorithms, Neural Network are intelligent tools which are
used in financial and stock market applications. Where these technical analysis,
fundamental analysis, time series forecasting are considered as mechanical
tools. These intelligent tools are heuristic based and posses the feature of
artificial intelligence in it. Various other type of evolutionary algorithms are
Genetic algorithms (GAs), Genetic Programming (GP), learning classifier
systems, evolutionary programming etc. Genetic algorithms or Evolutionary
programming cannot be applied in a single way. They are applied in combination
with a trading rule. This technical trading rule is made up by combination of
various technical indicators. On this technical rule Genetic Algorithm (GA)
is applied. This in return represents a whole investment procedure. Here
one half parts is mechanical driven and other part is evolutionary driven.
Mechanism or mechanical driven is a part when we develop a trading strategy
by combining various technical indicators by using if else statement. The
parameters of this predefined trading rule is generally optimized by the use
of evolutionary algorithm especially Genetic Algorithms (GA’s). There is
also another version in applying Genetic Algorithm (GA) is that to generate
a new rule from the set of rules already present. This process is known as
rule generation and its optimization using Genetic Algorithm (GA). Various
researchers have optimized parameters of a trading rule made with the
169
Genetic Algorithms (GAs) and Stock Trading Systems
170
Genetic Algorithms (GAs) and Stock Trading Systems
9.8 CONCLUSION
171
Genetic Algorithms (GAs) and Stock Trading Systems
REFERENCES
Allen, F., & Karjalainen, R. (1998). Using genetic algorithms to find technical
trading rules. Journal of Financial Economics, 51(2), 245–271. doi:10.1016/
S0304-405X(98)00052-X
Bauer, J. (1994). Genetic Algorithms and Investment Strategies. John Wiley
and Sons, Inc.
Focardi, S., & Jonas, C. (1997). Modeling the Market-New Theories and
Techniques. Frank J. Fabozzi Associates.
Kapoor, V., Dey, S., & Khurana, A. P. (2020). Modeling the influence of world
stock markets on Indian NSE index. Journal of Statistics and Management
Systems, 23(2), 249–261. doi:10.1080/09720510.2020.1734297
Korczak, J., & Roger, P. (2002). Stock Timing using Genetic Algorithms.
Applied Stochastic Models in Business and Industry, 18(2), 121–134.
doi:10.1002/asmb.457
Lawrence, R. (1997). Using neural networks to forecast stock market prices.
University of Manitoba, 333, 206–2013.
Mahfoud, S., & Mani, G. (1996). Financial Forecasting Using
Genetic Algorithms. Applied Artificial Intelligence, 10(6), 543–566.
doi:10.1080/088395196118425
Rajasekaran & Vijaylakshmi Pai. (2007). Neural Networks, Fuzzy Logic,
and Genetic algorithms, Synthesis and Applications. Prentice-Hall of India
Private Limited.
172
173
Chapter 10
Synergistic Market Analysis,
Technical Analysis, and
Various Indicators
ABSTRACT
Most of the stock and financial market analysis uses past or historic data in
order to forecast the future market indices. This study of past or historic data in
order to infer certain value addition from it is known as technical analysis. In
this chapter, the authors study a large number of popular indicators. A trader
uses these indicators individually or in combination with other indicators
to make a trading rule. They test them on past data and choose particular
parameters and indicators that gave more profit and drop those that are loss
making in nature. Thus, the decision to make entry and exit is given by these
technical indicators. This chapter gives a detailed explanation of the most
popular technical indicators in use.
10.1 INTRODUCTION
DOI: 10.4018/978-1-7998-4105-0.ch010
Copyright © 2021, IGI Global. Copying or distributing in print or electronic forms without written permission of IGI Global is prohibited.
Synergistic Market Analysis, Technical Analysis, and Various Indicators
prices and volumes are publically and easily available as compare to the data
of other systems. Technical analysis tries to find recognizable and repeated
patterns, which will help them to find future movement of stock prices or
indices. Various indicators have been invented by a number of researchers.
This type of analysis defines Random Walk Hypothesis and weak form of
Efficient market Hypothesis. Thus it is believed that a large amount of profits
can be generated by the use of technical analysis. Technical analysis includes
a number of processes such as chart analysis, pattern analysis, technical
indicator analysis etc. Out of these technical indicators can be represented in
a mathematical formula (Lento, 2007). Basic assumption in these indicators
is that the patterns in the prices that have occur in past are going to occur
in future also with same frequency. These technical indicators generate buy,
sell or keep neutral signals depending upon the parameter values on which
you simulate them.
From past researchers there is evidence that these stock market analyst,
hedge fund managers rely on these various technical indicators to take their
decisions on the daily basis (Fama, 1965), (Fama, 1970). This all thing suggest
that a large volume of market trade is guided by these technical indicators. We
should be cautious while using these technical indicators as we know markets
are efficient and absorbs any information very quickly. All our efforts to use
these technical indicators will prove futile, if we do not use them with proper
parameters and in a quick manner. Though there is n number of technical
indicators available in financial literature. Most popular of them is moving
averages and various momentum oscillators such as Relative Strength Index
(RSI), Stochastic Oscillators etc. A trading rule shall be able to tell when
to enter, when to exit and stop loss i.e when to exit after losing a trade. If a
rational decision on stop loss is not made then trader will face huge amount
of loss. Thus these technical indicators gives us a entry price, exit price and
stop loss price based on the mathematical calculations on the past price data
and with a rationality. Technical indicators guide us to make decision on what
we have to do. They makes detail analysis about the market direction i.e if in
a uptrend then we buy, if in a down trend then we sell, if in straight line then
we resist in taking any decision. Various attributes of technical analysis are:
1. Charting: Here graph of past historic prices such as bar chart, line chart,
candle stick charts are prepared.
2. Back Testing: Here different strategies to trade are to be tested. Actually
these strategies are some type mathematical formulas. They all are tested
on past prices of various securities.
174
Synergistic Market Analysis, Technical Analysis, and Various Indicators
Thus these all and many more qualities are possessed in technical analysis.
So they are also popularly known as decision support system. Advance feature
of technical analysis incorporates various soft computing and Artificial
Intelligence (AI) based optimization techniques in order to optimize its
parameter values. Now days the term technical analysis or indicators is used
quiet often in media by the financial analyst and professionals. Technical
analysis in contrast to fundamental analysis is used to forecast short term
prices i.e on daily basis and use past prices. A lot of research work is already
being done and is also undergoing on the issue of technical analysis. Detail
of this is being discussed in coming section and chapters of this book.
In this section we will understand the modus operandi of the technical indicators
and learn them to use in our forecasting process. Technical indicators are
classified into two type’s i.e leading indicators and lagging indicators. Both
of them have advantages and disadvantages. Some of the indicators are also
called oscillators. We will also learn them to use a s signal generators. In the
later section of this chapter we are going to have a detail analysis of some
popular technical indicators.
A technical indicator working is of susses ion or sequence of various data
position or values that are obtained by imposing a mathematical formula
to the past data of a stock or security. Data can be opening price, closing
price, day high, day low etc. of a security. Some indicator works on only one
series of data, while other works on more than one data series. The formula
is applied on to the data series and data point is generated. Only one data
point is of no use, so a series of various data points on various time lags
between present and past is done to make a perfect decision. Most of the
analyst shows the data point generated and price values by these technical
indicators in graphical charts. Pictorial view will help us to take decision in
an easy manner. Technical indicators are of varying perspective. Some are
of simple to understand, while others are of complex in nature. For example
175
Synergistic Market Analysis, Technical Analysis, and Various Indicators
176
Synergistic Market Analysis, Technical Analysis, and Various Indicators
inferences. We should not choose any two indicators from same category. It
should be kept in mind that indicator chosen from different category should
give same signal at a point of time.
As the name suggests lagging indicator go after the price movements. They
stick up to the trend. They are not of leading in nature. They keep the traders
into the market as long as there is strong trend weather upward or downward.
In this way if market indices develop a steep upward or downward trend, these
types of indicator gives us best results. When the trend of market is flat or
sideways then these indicators gives us poor results. In case if noisiness in the
market, these indicators will give false signals and thus will leads us to faulty
decision or we will feel cheated. Some of the most liked lagging indicators
by the analysts and researchers of this field are moving averages (Simple,
exponential, weighted, moving average convergence divergence etc.). In this
case we use two moving averages of variable lengths. If the shorter moving
average crosses the longer moving average then we consider that there is an
upward trend in the market and a buy signal is generated. If shorter moving
average crosses below the longer moving average then down trend is detected
and sell signal is generated. The length of the moving averages should be
decided by hit and trial method or with the help of Genetic Algorithm which
we will discuss in later chapters. It is generally seen that longer moving
averages give more accurate results and less whipsaws.
177
Synergistic Market Analysis, Technical Analysis, and Various Indicators
As given in the name, leading indicators leads the price movements. Here
the time period is decided and look back period stock market price action is
recorded and reflected in the result. Most liked leading indicator is Relative
Strength index RSI), Stochastic oscillator, Momentum, Commodity Channel
Index, Williams % R etc.
178
Synergistic Market Analysis, Technical Analysis, and Various Indicators
An oscillator is a type of indicator that vary above and below the centre
line or in between certain levels over a period of time. The value given
by oscillators is given at extreme points i.e overbought or oversold levels,
but it does not remain there for a long period of time. As compare to other
indicators their values fluctuates in a large way. Oscillators can be classified
into many types. Mainly oscillators are of two types centred and banded. In
centred oscillator the value fluctuates above and below a centre line, while
in banded oscillator value fluctuates between the two extreme points i.e
overbought and oversold points.
These type of oscillators swings or oscillate below and above around the
centre line or point. This type of fluctuation helps us to find the degree and
direction of the momentum of the indices or the stock price. If the oscillator
is above the centre line i.e we consider the price movements as bullish and
if oscillator is below the centre line then we consider the price movements
as bearish or in negative direction.
179
Synergistic Market Analysis, Technical Analysis, and Various Indicators
Rate of Change (ROC) is a example of centred oscillator. Here also its values
vary or oscillates around the centred line. For example a n day Rate of Change
(ROC) oscillator gives us a rate of change of values for last n days. Larger the
positive value larger is the bullish momentum, and larger the negative value,
larger is the bearish momentum. In contrast to Moving average Convergence
and Divergence (MACD), there are no upper limits and lower limits in Rate of
Change (ROC) oscillators. In this we cannot judge overbought and oversold
levels and their reversals. This is the major drawback of these oscillators.
Here in some cases upper and lower limits are fixed by the practitioners by
the observations from the past. Which vary from security to security? In order
to judge or empirically find these extreme upper and lower limits banded
oscillators are used.
180
Synergistic Market Analysis, Technical Analysis, and Various Indicators
Here the value of two oscillators varies between the two band i.e two limits
in contrast to the centre line. Here lower band tells that there is an oversold
position, while upper band gives us overbought position. Thus from these
points reversal takes place. Upper band and lower band values changes from
stock to stock and for different types of oscillators etc. Main advantage of
this types of oscillators are that analyst are able to pin point over bought and
oversold levels. Popular banded oscillators are Relative Strength Index (RSI),
Stochastic Oscillators etc. In comparison with Moving average Convergence
and Divergence (MACD) and Rate of Change (ROC) the calculation and logic
on which Relative Strength Index (RSI) and Stochastic Oscillator are based
are more complex, which we are going to discuss in the coming section of
this chapter.
For Relative Strength Index (RSI) over bought and oversold levels are
kept 70 (Overbought) and 30 (Oversold) but for Stochastic Oscillators these
levels are 80 (Overbought) and 20 (Oversold). These values are recommended
and they may change for security to security. It is the user preference that it
may change these values for making any decision, considering volatility of
the market.
Not all banded oscillators are positioned between upper and lower limits. In
case of Relative Strength Index (RSI) and Stochastic Oscillators, both are
depending upon range. There upper and lower limit ranges are 0 and 100.
Commodity channel indicator (CCI) is not a range bound oscillator. Here its
compare present security price of the stock for a given time. Theoretically
this oscillator has no upper and lower bound, but actually its upper and lower
values falls between -100 and 100. This makes Commodity channel indicator
(CCI) a popular and useful indicator, which helps us to find overbought and
oversold positions. These levels -100 to 100 can be adjusted according to
market volatility and price movement of a particular security.
Centred oscillators help us to find the strength and direction of the momentum
of the stock prices. As in centred oscillator the reading vary around a centre
181
Synergistic Market Analysis, Technical Analysis, and Various Indicators
The main function of the oscillator is to generate buy and sell signal. In some
case there is an early entry or exit, and some case it is just in time. These
signals tell us the time when the positive or negative trend is going to reverse
or change. In order to reduce the risk these signals should co exist with the
signal generated by other technical indicators or by technical analysis process
such as study of price patterns charts etc.
Divergence is a new concept in order to find a signal. Divergence gives
us a warning that a positive or negative trend is about to change. In case of
negative divergence the indicator gives lesser value then the actual value
that security has achieved. It is an indication that high has been achieved
and trend is about to get reversed. Not in all negative divergence there is a
bearish movement. In case of positive divergence when indicator give a less
low then the actual low point the security has achieved. From this point there
is appositive reversal or bullish trend is going to be there. Not all positive
divergence results into a bullish trend.
Overbought and oversold Boundaries: Banded oscillators help us to find
overbought and oversold extreme values. The values given by these indicators
swing between the extremes as their values are decided by the user. In case of
strong positive or negative i.e bullish or bearish trend they fail. So if there is
a strong upward or bullish trend then buying that stock will give more profit
then by selling as the banded indicator gives an overbought signal. Hence
for a strong trend oscillator working is not robust in nature and signal (Buy
or Sell) generated are not valid in nature.
So in case of a strong uptrend i.e bullish, buying the stock will give much
profit then by selling it, as if the indicator is giving an overbought position.
Same is the case with strong bearish trend. Here buying an oversold position
will not give us great returns. If a trend is detected then if you act against
it then it will lead us to a huge loss. It is very tricky to find a trend. If the
trend is strong then indicator will tell about overbought or oversold signals
for a long time. In case of a strong bullish trend the indicator will give an
overbought signal i.e to sell the sell but the security price will advance in
182
Synergistic Market Analysis, Technical Analysis, and Various Indicators
Here in centreline crossover the signals are generated as the oscillator swings
above and below a centre line. Analyst and traders uses this centreline in
combination with Relative Strength Index (RSI) and Stochastic Oscillator
in order to get a robust signal. So to get divergence or turn around point we
turn our study to centre line crossovers. As extremes are checked by banded
oscillators and middle ground is checked by centreline oscillators. Popular
centreline oscillators are moving average Convergence and Divergence
(MACD) and Rate of Change (ROC) etc.
A centreline crossover will generate buy or sell signal if the indicator line
crosses above or below the centre line. This is considered to be positive or
bullish and negative or bearish momentum. So if we use centre line oscillator
in combination with banded oscillator there will be more true signals with
less whipsaws. So if we combine various indicators to generate the signal,
we are going to get more robust signal for all cases. So our challenge to get
a profit is met. Thus by combining two types of oscillators indicator with
lagging indicator, then if all of them gives sell signal when banded oscillator
reaches the extreme, and there is a negative movement to the below of the
183
Synergistic Market Analysis, Technical Analysis, and Various Indicators
centre line in centre line oscillator and bearish moving averages cross in an
reverse direction.
So by waiting the entire three signals to be generated at the same time,
we are sometimes losing money. But as the reliability increases and risks
lowers, gains also lowers. This will in turn trim down our profits. So in last
if we sum up that banded oscillators gives us the overbought and oversold
levels. But it is not true we buy or sell in these levels. They are the alerts
given by the oscillators. So in order to take any decision analyst see whether
the same signals are generated by other indicators also. If that is generated
then there is a confirmation for buy or sell. So by relying on these three
different type of indicator buy signal is generated, when there is an oversold
condition, positive divergence and bullish crossover movement and sell signal
is generated when there is a reverse condition. If the market has a strong
bullish or bearish trend then it is not advisable to rely on the signal generated
by the oscillator. A strong trend in the market falsifies the oscillator signal.
It is judged that oscillators when used in combination with other indicators
chart analysis, trend identifiers etc. gives an effective result. Thus in this way
chances to get a successful reading is increased.
184
Synergistic Market Analysis, Technical Analysis, and Various Indicators
i =n
(MA)n = ∑Ci / n
i =1
(MA)n = C1 + C2 + C3 + ............Cn / n
In order to overcome the time lag, some analyst uses weighted moving averages
(MA). We have seen that current price movement is more important than
past price movements. So current price movements are given more weights
as compare to past price movements in weighted moving averages (MA), as
compare to simple moving averages (SMA) where all values are given same
weights. Formula for weighted moving averages (MA) is given below:
185
Synergistic Market Analysis, Technical Analysis, and Various Indicators
Multiplier = (2 / (n + 1)
186
Synergistic Market Analysis, Technical Analysis, and Various Indicators
weights or multiplier value decreases, so the multiplier value for shorter time
is more than the multiplier value for longer time. This tells us that exponential
moving averages (EMA) is sensitive to recent price changes then the past price
changes. If we make a comparison between n day simple moving averages
(SMA) is very easy to calculate. Here as we move forward old prices are left
and new prices are taken into account. Here in exponential moving averages
(MA) we first start with the calculation of simple moving averages (SMA)
for its 1st exponential moving averages (EMA) value. After this the actual
exponential moving averages (EMA) formulas for calculation is used. As it
is seen in the formula of exponential moving averages (EMA). Present value
depends upon the previous exponential moving averages (EMA) value. So
the current value changes according to the past value. So the main aim of
exponential moving averages (EMA) is to increase accuracy and reduce the
computational complexity or calculation complexity.
It is seen that longer period moving average have more time lag while
shorter moving averages (MA) will have less time lag. They are more sensitive
to the price changes. Shorter moving averages (MA) are just like a small
paddle boat while longer moving averages (MA) are like a big ship that are
lazy in working and changes slowly. There are differences in the formulas of
moving averages (MA) and exponential moving averages (EMA), so they are
different in their signal generation. Exponential moving averages (EMA) is
bound to have less time lag for the same time period, when compared with
simple moving averages (SMA). Hence exponential moving averages (EMA)
are more sensitive than simple moving averages (SMA). Simple moving
averages (MA) will be used to find support level and resistance level in
combination with exponential moving averages (EMA) which will generate
optimal buy and sell signals. The length of the moving averages (MA) which
we use depends upon the trader. If we trade short term or we are short term
investor and trend is weak, then we will use short moving averages (MA) i.e
between the range of 5 – 20 days. For medium investor and medium trend
moving averages (MA) range is from 20 – 60 days. For long term investors,
moving averages (MA) will be for more than 100 days.
The direction line of the moving averages (MA) gives us trend about prices.
A upward movement of the longer moving averages (MA) moving average
line gives an indication for a strong long term trend.
187
Synergistic Market Analysis, Technical Analysis, and Various Indicators
Two moving averages (MA) i.e of shorter length and of longer length in
combination will be used to generate trading signal. 5 – 35 day will be considered
as short length and 5 – 200 day will be considered as longer length moving
averages (MA). A bullish signal or buy signal is generated when shorter
length moving averages (MA) cross longer length moving averages (MA)
line,. A bearish signal or sell signal is generated if reverse happen. By nature
moving averages (MA) are lagging indicators. Longer moving averages (MA)
gives or confirms about the trend and shorter moving averages (MA) will
give buy or sell signal. It is seen that in case of weak trend a lot of whipsaws
are generated by the moving average crossovers. There is a triple moving
averages (MA) crossover method also in use, where we use one short term
moving averages (MA) and two longer term moving averages (MA). Here in
short term moving averages (MA) crosses two longer term moving averages
(MA) in upward direction then a buy signal is generated and if it crosses two
longer term moving averages (MA) in downward direction then sell signal
is generated. It is seen that moving averages (MA) crossovers are prone to
whipsaws. That can be avoided if we use more filter to reduce noisiness
in price data. Moving averages (MA) can also be used to find support and
resistance for the case of uptrend and downtrend.
188
Synergistic Market Analysis, Technical Analysis, and Various Indicators
In the stock market analyst are always looking for trend and momentum of
that trend. Trend following indicators are moving averages which are simple
in calculation. But the introduction of desktop computers, more complex
indicators are invented and implemented to calculate the momentum of the
price. A large number of momentum indicators are in use. In this section we
are only going to explain the most common and popular indicators such as
Moving average Convergence Divergence (MACD), Relative Strength Index
(RSI) and Stochastic Oscillator. Momentum is measure of the difference of
price between the current time and past time.
189
Synergistic Market Analysis, Technical Analysis, and Various Indicators
190
Synergistic Market Analysis, Technical Analysis, and Various Indicators
191
Synergistic Market Analysis, Technical Analysis, and Various Indicators
Calculation of average gain and average loss for simple n day averages is
Second and further calculation are based on the previous averages and
current gain or loss.
Here the equation 1 changes RS into a oscillator that swings between 0 and
100. If plotted both RS and Relative Strength Index (RSI) plots are of same
in nature. Here when average gain is nil then Relative Strength Index (RSI)
value is zero i.e all loss. When average loss is zero i.e all gain the Relative
Strength Index (RSI) value is 100.
The default value of n in Relative Strength Index (RSI) indicator is used
as 14. If we use 10 day Relative Strength Index (RSI) then we increase its
sensitivity and if we use 20 day Relative Strength Index (RSI) then we decease
its sensitivity. Overbought and oversold levels can be kept 70/30 or 80/20.
These all parameter values depend upon the stock price volatility and noisiness.
192
Synergistic Market Analysis, Technical Analysis, and Various Indicators
high and Relative Strength Index (RSI) reading is the lowest high then
there can be a reverse in momentum. We should not be very excited
about the divergence as they may mislead us in case of a strong bullish
or bearish trend,. This strong trend can show a lot number of false
signals. It is seen that Relative Strength Index (RSI) oscillator generally
do not travel between 0 and 100. In case of bullish stock market it may
travel between 40 to 90. In case of bearish market it may travel between
10 and 60. So positive reversal is actually a bullish divergence.
• Summary: Relative Strength Index (RSI) is still a robust, adaptable
momentum oscillator, which is tested in every stock market
environment. The results given by Relative Strength Index (RSI) are
encouraging in the changing times of stock market. Relative Strength
Index (RSI) consider overbought levels to be sell signal and for bearish
reversal and negative reversals. While oversold levels gives us a buy
signal i.e for bullish and positive reversals. These readings will fail if
there is an indication of a strong trend in stock prices.
193
Synergistic Market Analysis, Technical Analysis, and Various Indicators
The default value for the Lowest Low = Lowest low for the period for
which Stochastic Oscillator is to be calculated.
Calculated is 14. So % K is calculated for 14 period and % D is the 3 day
simple moving average (SMA) of % K. So the % K line is the signal line.
The default values of is taken as (14, 3, 3). As there are upper and lower
limits bounded in Stochastic oscillator. The value of this oscillator fluctuates
from 0 to 100 in any case. Traditional values setting uses 80 as overbought
and 20 as the oversold levels. Overbought condition does not always signal
a bearish move. Price of a stock can remain at overbought level if there is a
strong bullish trend. Same is the case with oversold levels. Oversold condition
does not signal a bullish move always. Price may remain at a lowest point if
there is a strong bearish trend.
194
Synergistic Market Analysis, Technical Analysis, and Various Indicators
10.6 CONCLUSION
Stock traders generally take their trading decision i.e entry, exit and stop
loss based on these technical indicators. Though there are a large numbers
of technical indicators used by the researcher and stock traders. Our chapter
here explain only few and most popular ones. It is to note that technical
analysis like any other type of analysis is not 100% accurate. The level of its
accuracy depends upon the experience of the stock trader and analyst. Hence
technical analysis cannot be mastered with the experience.
195
Synergistic Market Analysis, Technical Analysis, and Various Indicators
REFERENCES
Copsey, I. (1999). Integrated Technical Analysis. John Wiley and Sons (Asia).
Pte Ltd.
Fama, E. F. (1965). The behaviour of stock market prices. The Journal of
Business, 38(1), 34–105. doi:10.1086/294743
Fama, E. F. (1970). Efficient capital markets: A review of theory and empirical
work. The Journal of Finance, 25(2), 383–417. doi:10.2307/2325486
Lento & Gradojevic. (2007). The Profitability of Technical Trading Rules:
A Combined Signal Approach. Journal of Applied Business Research, 3(1).
196
197
Chapter 11
Using Genetic Algorithms to
Develop Investment Strategies
ABSTRACT
Genetic algorithms (GAs) are a powerful search technique. The use of genetic
algorithms (GAs) will help in the development of better trading systems. The
genetic algorithms (GAs) help the researcher to explore various combinations
of trading rules or their parameters, which the human mind is unable to find.
This chapter explains genetic algorithms (GAs) in brief and gives insight on
how they find better trading strategies. Some of the manual trading strategies
are good in nature. Genetic algorithms (GAs) only addition to them. Interfacing
genetic algorithms (GAs) with stock trading systems or developing a combined
model requires a large degree of imagination and creativity. It is an art not
a scientific invention. Genetic algorithms (GAs) make use of computers to
find various interesting trading systems.
11.1 INTRODUCTION
With the availability of huge processing power and memory at cheap rates
at your door step in past decades. It has been helpful to develop new trading
strategies to forecast stock data. This has result in creating new generation
Artificial Intelligence (AI) based systems which are known as expert systems
popularly. Many algorithms has also comes into picture to support them.
Genetic Algorithms (GA’s) is one such type of technique which is used as an
optimizer in common to generate various trading rules or their best parameters
DOI: 10.4018/978-1-7998-4105-0.ch011
Copyright © 2021, IGI Global. Copying or distributing in print or electronic forms without written permission of IGI Global is prohibited.
Using Genetic Algorithms to Develop Investment Strategies
(Bauer, 1994). These artificial intelligence based systems are so powerful that
no human intervention can match their results, as human mind has limited
processing ability or cognitive power. But by a large decision or results by
these expert systems are much superior then given by traditional systems.
Genetic Algorithms (GA’s) based expert systems are of flexible in nature and
changes their working according to the market conditions. They are of self
evolving in nature and take their learning’s from the past. Results or solution
find by them are of superior in nature and we cannot dream of finding such
solutions by traditional optimization techniques. Of all optimizers present
and past researches has found that Genetic Algorithms (GA’s) are of most
innovative and powerful in nature. Results are of promising in nature as we
had applied them in past data and Genetic Algorithms (GA’s) is replacing
past traditional statistical based traditional search methods firstly.
Genetic Algorithms (GA’s) are simple in nature as they are inspired by
biological evolution. Genetic Algorithms (GA’s) process is generally a artificial
simulation in nature i.e its selection and survival of fittest (Goldberg, 2002).
It is based on Darwin theory of survival of fittest. Genetic Algorithms (GA’s)
has found its application in a large number of areas in addition to the stock
market domain. Past researchers have shown that Genetic Algorithms (GA’s)
has been successful in each and every domain.
198
Using Genetic Algorithms to Develop Investment Strategies
199
Using Genetic Algorithms to Develop Investment Strategies
Replace the previous members with the new member obtained after
application of crossover and mutation
Endwhile }
Give us the best member with best possible fitness value
End procedure
After the entry into the world of Genetic Algorithms (GA’s), we are now
examining its usefulness in the area of financial domain. A lot of literature
is available of the application of Genetic Algorithms (GA’s) in this area.
Genetic Algorithms (GA’s) are best suited for financial modelling to these
reasons given below:
200
Using Genetic Algorithms to Develop Investment Strategies
that generates buy or sell signals in the stock markets. If Genetic Algorithms
(GA’s) based procedure gives a small amount of improvements, in last we are
going to have a large pay off. Since trillions of dollars are invested in the stock
markets. Only 1% increase in accuracy will result in billions of dollar profit.
In case of stock market we predict or forecast the time series of the stock price
data. Usually we use various technical indicators to predict the time series or
to generate buy or sell signal. The parameter values of these indicators can be
generated by using Genetic Algorithms (GA’s) rather than taking heuristically.
In advance stage we form a technical trading rule by combining two or more
than two technical indicators. In this case search space increases exponentially
and brute force attack is time consuming. Genetic Algorithms (GA’s) is used
to get better parameter settings that generate huge profits. Various portfolio
selections for the stock is done by using Genetic Algorithms (GA’s). Asset
allocation strategies are done by Genetic Algorithms (GA’s). Past researchers
has found that Genetic Algorithms (GA’s) search large solution spaces in a
very effective and efficient manner. Simple and flexible in nature are the two
main features of Genetic Algorithms (GA’s). Various hybrid models has also
been generated i.e Genetic Algorithms (GA’s) applied in conjunction with
neural network and fuzzy logic. This type of hybridization requires a lot of
experience and knowledge. Once implemented these model when run in a
personal computer are computationally intensive. Genetic Algorithms (GA’s)
applied in real time trading application is propriety of the researcher. It is seen
that a lot of this type of knowledge is under wraps and only implementation
are in the public domain. Usually technical analysis is based on the past data
or price information. These are the macroeconomic fundamentals and rules
generated here give us prediction on daily basis. Hence Genetic Algorithms
(GA’s) are used to find optimal parameter of a pre defined rule or rule itself.
A Simple Technical Trading Rule Optimization: Genetic Algorithms (GA’s)
are used to search optimal parameter for the trading model (Latemedia, 2007),
(Kapoor et. Al, 2011). A simple trading rule is moving average crossover.
Moving averages are average stock price for n days. Here if shorter moving
average crosses above the longer moving average then buy signal is generated.
If it crosses it in downward direction then sell signal is generated. In order to
get optimal lengths of these two moving averages Genetic Algorithms (GA’s)
are used to find optimal values with fitness function as the profit generated
by using these moving averages lengths. Genetic Algorithms (GA’s) are
run multiple times in order to get many better optimal or close to optimal
parameters.
201
Using Genetic Algorithms to Develop Investment Strategies
If (rule 1 and rule 2 and rule 3 says buy) then buy else sell
202
Using Genetic Algorithms to Develop Investment Strategies
203
Using Genetic Algorithms to Develop Investment Strategies
There are a number of optimizer’s presents; each one has its own strengths
and weakness. Classification of optimizers can be done in various ways such
as human optimizer’s vs machine optimizers, simple optimizer’s vs complex
optimizers, analytic vs stochastic optimizers etc. These all optimizers do a
search to find best solution for a particular problem on which they are executed.
204
Using Genetic Algorithms to Develop Investment Strategies
A brute force optimizer test all possible solution of a problem that is present
i.e all combination of rule and valid parameter set available to us. Due to
this feature brute force optimizer are of slow in nature. This major drawback
for these types of optimizers. They are not recommended for combinatorial
optimization problems. If in a problem there is an search space of 30 bits then
the total number of combination that are in existence is 230 which comes out
in trillions. If 1 sec is the time to check for each solution, then it will take
years or your whole life to check all the solution. Brute force optimization is
useful for problems with a limited or small search space. In this best possible
solution will be generated in seconds or minutes. Here when implemented
in a programming language, we start with the 1st solution and counter is
incremented by one after every iteration and stop until last solution is tested.
205
Using Genetic Algorithms to Develop Investment Strategies
206
Using Genetic Algorithms to Develop Investment Strategies
not only benefitted the business, but also increased the risk and complexity.
So we need a tool that can summary of this situation. So analyst uses certain
models which help them in making decisions. These models help us to find
relationship between various variables, find cause and affect relationship etc.
It is of no guarantee that these models will predict a system with accuracy
and will be a success, but they will help analyst to get a better understanding
of the environment. They also reduce some degree of risk. This helps the
analyst to have a significant advantage over other naive person in the noisy
environment. Modelling a certain system is an art along with science. Perfection
in it comes with experience.
Other qualities that a model must have are the cost of running it, its
sophistication and time required to make a model. These all features make a
model effective. Some of the modellers are called positivists. They believe
that their model will give better results which will help in value addition.
Some of the modellers are relativists, they believe that model should view
situation from the perspective of all stake holders. Hence both the modellers
are successful in their working. To have best of both the worlds features we
should be relativists when we develop a model and positivists when we judge
our model. The following are the major benefits of the model:
207
Using Genetic Algorithms to Develop Investment Strategies
In case of stock market scenarios there can be adverse and diverse situations.
Hence more level of abstraction is needed in making that model and to
represent it mathematically. Since relationship between the various variables
are so complex so that they cannot be expressed in a physical model. We need
some mathematical formulas and soft computing methods to represent them.
In case of mathematical model there are three types of variables:
208
Using Genetic Algorithms to Develop Investment Strategies
The three major step expert or modeller do when he does effective modelling
are:
1. Identify a problem.
2. Validate or verify a problem.
3. Obtain key variables of the model.
In a broad way modelling is a five step process. The varios steps and time
needed to execute them is given below:
209
Using Genetic Algorithms to Develop Investment Strategies
There may be different ways in which these steps may be executed. For
example in certain cases data collection may come before model formulation
etc. Now in the coming section we are going to discuss all these five steps
in detail.
Now consider a problem that comes into picture. In case of stock trading
system the opportunity or problem is to create or maximize profit and minimize
losses while trading. This the easiest part in this 5 step process. This is the
most important part also. If we define the problem in a better way then we
almost crossed the half way mark. If the problem definition is put in a wrong
way then this results in wrong or vague solutions, which are not useful to us
in any way. For this modeller should investigate the whole situation minutely.
He should successfully found symptoms between symptoms and problems.
Care must be taken such that in the beginning a different problem exists and
in the end a different version of problem exists. Thus proper investigation
will help modeller in avoidance of solving a wrong problem and saving time
and energy.
2ns step is model formulation. Here we convert the problem into
mathematical form or the problem is represented in a mathematical formula on
a piece of paper. All the dependent and independent variables are pin pointed
and relationship between these variables are established in form of equation.
Various assumptions are also defined. Linear or non linear relationship,
simplification and degree of reality have been fixed here. We should try to
keep the model simpler and more representative of real world situation. So
balance between these two factors should be done while constructing the
model. This will require several fake iterations to be done, before coming to
the final model formulation. Thus all the mathematical and soft computing
based models should these three components in it i.e dependent variables,
Independent variables and uncontrolled parameters. These three components
are described earlier.
3rd step is data collection. Some times accusation of data is difficult and
time consuming. In case of stock trading systems the data is radically available
in the public domain of all stock exchanges. Here we are encountered with
the problem of excessive data. With limited processing power and excess of
210
Using Genetic Algorithms to Develop Investment Strategies
data, our computer processing power and memory will be short in simulating
the model. Here decision variables can be the amount which we want to get
invested, dependent variables are previous day closing price, opening price
etc. and uncontrolled variables are day high, day low, volume of shares traded,
deliverability of shares etc.
4th and most important step is analysis of the model. Here we test how
well our model work. The common questions are: Is the results given by the
model are accurate? Does the model represent the real world behaviour? So
to validate a model there are two steps: 1st step is to determine whether logic
used in model is correct and right programming is done for it. 2nd step is to find
that model represent the real world in a full view. After successful validation
analysis of model is done by giving certain input values and obtaining results.
Now compare this results with the actual the actual values of the past data.
Traditionally to get best decision or output variables comprises of these five
steps:
211
Using Genetic Algorithms to Develop Investment Strategies
Parent A: A1 . A2 . A3 . A4
Parent B: B1 . B2 . B3 . B4
After crossover at the mid point we may get two offspring such as
212
Using Genetic Algorithms to Develop Investment Strategies
Offspring A: A1 . A2 . B3 . B4
Offspring B: B1 . B2 . A3 . A4
Considering our trading system suppose two strings that are produces are
String 1: 12 28 8 4
String 2: 4 11 7 12
Offspring 1: 12 28 7 12
Offspring 2: 4 11 8 4
Offspring 1: 12 28 7 12
Mutation Operator
Final Offspring 1: 12 28 3 12
So the main theory is that if both the strings give us good profit while
trading, then various other combinations of their values will also give much
better solution or profits. Mutation gives much needed diversity and prevents
stagnation in the population, which may occur due to greedy selection operator.
Thus randomization is crossover and mutation together with selection will
lead us into the right direction and help us to find optimal solution.
213
Using Genetic Algorithms to Develop Investment Strategies
11.7 CONCLUSION
Now a day’s trading in the market is very difficult and is becoming competitive
day by day with the increase in number of traders. Since market is a zero
sum game which means that for every trader who loose there is every trader
who wins and vice versa. So every decision is critical and it may lead you
to a profit or loss. Those who are taking decision only on intuition and are
not using some artificial intelligence based models are on receiving end.
They are going to wind up soon in near future. In this chapter we have try
to explain in brief the use of Genetic Algorithms (GAs) as a optimizer in
order to find an optimal value for the trading model. So it is advisable if one
wants to stay competitive in market, one should be familiar with the use of
artificial intelligence.
REFERENCES
214
215
Chapter 12
Developing a Single Indicator
or Multiple Indicator
Market Timing System
ABSTRACT
In this chapter, the authors use genetic algorithms (GAs) to optimize the
parameters of the trading system, which is made by various technical indicators.
These trading systems or rules will give buy or sell signals when applied on
past prices of a particular stock. Genetic algorithms (GAs) have an ability
to find optimal trading indicators that will predict the market direction or
trend with greater accuracy. Use of genetic algorithms (GAs) in conjunction
to a trading rule refutes efficient market hypothesis (EMH) in a weak form.
12.1 INTRODUCTION
This chapter sets the stage on how we could interface Genetic Algorithms
(GAs) or apply on a trading system in order to improve our accuracy and
profits (Bauer, 1994). So the question here comes into our mind that why we
use Genetic Algorithms (GAs). Before the answer to this question, I would
like to ask one simpler question i.e why we are involving the use of computers
to develop our trading system? Answer to this question is that human brain
has limited processing power or cognitive ability. Though we imagine and do
many things which are of superior in nature, but we have our limits. Our brain
has limited intelligence. Human mind can imagine and find a small number of
DOI: 10.4018/978-1-7998-4105-0.ch012
Copyright © 2021, IGI Global. Copying or distributing in print or electronic forms without written permission of IGI Global is prohibited.
Developing a Single Indicator or Multiple Indicator Market Timing System
216
Developing a Single Indicator or Multiple Indicator Market Timing System
217
Developing a Single Indicator or Multiple Indicator Market Timing System
rule will be available for the next day. Hence Genetic Algorithms (GAs) as
an optimizer is very much suitable to all real time systems of any area. Other
which adds to the popularity of Genetic Algorithms (GAs) is less or almost no
knowledge about the system is required, whose parameters are being optimized.
Only binary string mapping to the solution and fitness function formula
is the required knowledge about the system domain. Genetic Algorithms
(GAs) only works with the binary strings and try to find the optimal string
just by having the string function evaluation value. All the user is to do is to
correctly implement Genetic Algorithms (GAs) and it will actually find the
optimal value and the parameter set. All though the user does not have any
knowledge about the stock trading system. To implement Genetic Algorithms
(GAs) we require knowledge of programming and its skills. Once the Genetic
Algorithms (GAs) program is implemented, only thing we have to change in
Genetic Algorithms (GAs), if we switch from one problem to other problem
is the coding of fitness function formula. More user friendly interface can be
given by the coder by which we could easily change our Genetic Algorithms
(GAs) required code. In this way it is seen that Genetic Algorithms (GAs)
are compared to other techniques.
There are two types of features which we should take into account, if we
are entering in the stock market. On is market timing and other is portfolio
management. In case of market timing, the analyst tries to enter the market
in the lowest low and try to exit it at highest high. While in case of portfolio
management the analyst choose only those stocks that are expected to give
better returns. So Genetic Algorithms (GAs) can be used to optimize market
timing rule parameters or they can be used for security selection also. Earlier
before the use of Genetic Algorithms (GAs) or other technique it was done by
intuition, convenience or by some interest. It is seen that Genetic Algorithms
(GAs) when used to find optimal market timing have less computational
complexity as compare to find optimal portfolio selection, which gives
maximum profit.
There are two types of new or information that affect stock market as a
particular stock is micro economic data or news and other is macro economic
data or news. In fact it is seen that investor pay more attention towards macro
economic data and news. As all of the stock values are effected largely to it.
For the case of security selection macroeconomic news is an important factor.
218
Developing a Single Indicator or Multiple Indicator Market Timing System
As all companies work with in a legal frame or socio economic frame work.
It is rational to take macroeconomic news or data to take into consideration,
which will lead us to have profitable opportunities. Many investors take into
account dividend given by the company as the major macroeconomic data
to find the stock prospects in future. So to buy any stock we look for the
dividend given by the company or it is going to give and what will be the
future value of that stock would be. This is the same case when we sell the
stock and some other person who buys that stock from us. The basic notion
is always the same for all traders who buy stock from any one. Thus the
value of a stock is strongly linked with the dividend given by the company.
In a chain of linkages among the various parameters, stock price depends
upon the earnings of the company. More earnings of the group, results in a
more dividends pay outs per share. Earnings depends upon the sales of the
product made by the company and last but not the least, that sales of a product
depends upon the strength of the economy. Thus health of the economy is
always shown in the macroeconomic data and news, which in turn affect the
stock price and last will affect our investment decision.
There are a numbers of factors which tells about the strength of the economy.
One of the factors is interest rate, inflation and risk. All these are interlinked
with each other. Increase in one of them will lead to the down fall of others
and so on. So a proper balance must be maintained between them. Inflation
value also depends upon monetary growth, supply demand ratio etc. The
security bonds given by the company has risk premium values attached to
it. When a economy is at its brink, then risk values increases and vice versa.
If interest rate goes high then attractiveness of the stock market reduces.
As the investor wants, higher rate of return from the stock market otherwise it
will shift from market to fixed interest regime. As result valuation of the stocks
will fall. Bond risks premiums are also negatively affected by the increase of
interest rates. It will increase their risks premiums. Hence the effects on the
stock price due to the changes in macroeconomic data are not very easy to
predict. A very comprehensive study is needed to make this analysis fruitful.
In case of fundamental analysis we always start with certain assumptions.
There is always a relationship between the economy, management decision
and stock price movement. Thus the whole monetary policy such as interest
rates, reverse repo rates etc. and other macroeconomic variables as decided
by the central bank and fiscal policy, as decided by effects our stock prices.
In our country this all historic macro economic data is made publically
available to all by ministry of commerce, both in hard copy and in electronic
form. Monthly data on consumer index, inflation, industrial output, interest
219
Developing a Single Indicator or Multiple Indicator Market Timing System
rates etc. all are made available by the concerned ministry of every developed
and developing country. These all macroeconomic data in conjunction with
historic return data of the stock price will help us to create a large number
of trading rules, and on which Genetic Algorithms (GAs) can be applied to
optimized these rules or the parameter lengths of the indicators in these rules
for better profit or maximum return.
So in addition to this technical analysis, we can apply Genetic Algorithms
(GAs) in fundamental analysis also. Here positive and negative relationships
must be found macroeconomic data and stock price data to form a rule. This all
thing cannot be generally done manually i.e we does not outlook connection
between the parameters of fundamental analysis and technical analysis. We
left this task to our computation machine to do this. One thing that is kept in
mind in finding these relationships is they must be homogeneous not unfitting.
We do not recommend a analyst to apply computational power mindlessly
or he should be explorative in nature. If some correction or relationship is
explored in the two data series, then it must be judged with a high degree of
rationale. For example if increase in inflation in some country and rate of
return of the stock in some other country is matching. Then this relationship
or connection we had found in the two time series we cannot rely on. As there
is no rational theory to give, that tells us the connection between these two
time series data. Hence we try to examine a large number of relationships
between a lots of time series, we find that over fitting of relationship formula
appears. Hence in this situation when there is an explosion of combinatorial
possibilities among the variables, only few connections work consistently. Our
comfort zone is also compromised when there is an explosion of possibility
and over fitting of the variable data. So to prevent this we can buy robustness
in our computation methodology. Genetic Algorithms (GAs) is one of the
best soft computing techniques we can apply or we can use a large number
of trading rule and not rely on one rule itself. This will reduce the impact of
over fitting of rules.
Thus testing our notion and rule on past historic data is known as back testing.
It gives us the performance of that particular rule in past. So our assumption
that if this rule has worked in past, then it will work in future does not hold,
220
Developing a Single Indicator or Multiple Indicator Market Timing System
that if a large number of analyst would have used that rule then the market
would be different by now. But still we assume that this effect will be less
and will affect the market movement in a large way. Stock market theory
advocates that if we are investing billions of billions in the stock market,
then even a small effect will give a large dent in the result. Though I believe
these statements, but we have no choice to test our hypothesis but to back
test it. So we feel that if our hypothesis works well in the past data, then it
will work well in future also.
There are certain limitations of back testing the strategies made from
macroeconomic data or fundamental analysis data. These limitations are data
accuracy and easy and timely availability of data. In case of macroeconomic
data there is a continuous or correctness in the data after a certain period of
time. So the value we get today may have somewhat different in past dates.
There is also time lag in the data we get. For example March month of
fundamental data is available in May month. Another issue is the availability of
data. Some of the high end data is generally available to financial institutions
not to the general public. Many researchers divide the data into two set i.e
testing set and training set. If we use 10 year data set then first seven years
data set is used as training data set on which rule parameters set is optimized
and next 3 years data set is considered to be testing data, on which optimized
parameter set of the rule is applied and we see how they work or the results
are excellent, good or bad. So our basic assumption is if the optimized rules
or parameter set of rules hold good for the testing data set, then it will be
good for future also. We may disagree with this assumption, but we have
no choice. This is the risk we have to take conceptually. So we want that
rule which out performs during testing phase must also work with the same
efficiency in the future also. In the complex world of stock trading the actual
truth and concept may be somewhat different or contrast. So in order to keep
things simple what are the questions we should ask to ourselves to know
weather or trading system is adequate in working or not. The main question is
whether past better performance trading system will give same performance
in future or not.
In case of using Genetic Algorithms (GAs), we assume that system evolved
will work better in future also. We are not 100% sure about that. This our
rationale guesses. Actually Genetic Algorithms (GAs) based trading systems
are logically evolved, that may give better or positive results for a long period
of time. So if we have Rs 100/- to invest, should we use one rule to make an
investment or we should use 100 Genetic Algorithms (GAs) based trading
system with Rs1/- for each system to invest. Though Genetic Algorithms (GAs)
221
Developing a Single Indicator or Multiple Indicator Market Timing System
is always used to evolve system in right direction, but there is always risk in
it. Surety cannot be given for it. It has seen that trading system performance
is not always consistent. Some systems that had worked well in past gives
bad results in some other circumstances or time period. So it is advised to use
variety of Genetic Algorithms (GAs) based optimal system and distribute our
investment into them equally, rather rely on one highly successful system. It
would be too risky to put all the eggs in the same basket.
222
Developing a Single Indicator or Multiple Indicator Market Timing System
223
Developing a Single Indicator or Multiple Indicator Market Timing System
of solution representation, but it may not be good for certain problems which
are to be solved using Genetic Algorithms (GAs). This restriction is removed
in Genetic programming which is a new type of evolutionary algorithms,
developed by John Koza in 1992. It encompasses the strings of variable
lengths in contrast to the fixed string in Genetic Algorithms (GAs). In case
stock trading system we had an advantage of using Genetic Programming to
optimized trading rule as trading rule formations could be of variable lengths.
Here the members of the population or solution are represented as function
in various hierarchies. Here the solution is just like a decision tree type
structure. Here each node has some sub functions as it successor. Nodes with
no successor are called terminal nodes. Thus whole tree is a main function.
Thus structure could be function of many types. There is no restriction in type
of function used and length of structure. After selection and application of
recombination operator, various s combination of sub tress, structure of variable
lengths will be created. Genetic Programming consists of structures instead
of strings as population. Thus here initial population is a set of random tress.
Here the tree starts with a root node which is a sub function at its terminals.
These proceeds downward until the function with no sub function i.e with no
successors are reached. After the generation of random population, selection
operator is applied, which choose better average fit individuals for crossover
i.e recombined with other individuals. Here in this Genetic Programming
case crossover operator exchange randomly selected sub tree from parent
1 to the randomly selected sub tree with parent 2. The node point is also
chosen randomly. In case of mutation, a sub tree in the population is chosen
randomly and replaced by a randomly generated another sub tree. Mutation
is applied with a very small probability. Genetic programming has been
applied by Koza to a variety of problems in a diversified field. An example
of Genetic structure is given below:
Figure 1.
Rule 1 Explanation: Here moving average returns a buy signal if 30day moving average is smaller
than the price otherwise sell
Rule 2 Explanation: Here buy signal is generated if 20 day maximum value is less than the price
otherwise sell.
224
Developing a Single Indicator or Multiple Indicator Market Timing System
In this section we will work upon the creation of multi technical indicator
stock trading system or rule, which will generate buy or signal on a daily
basis. Though there are a large number of technical indicators present in the
system. There is possibility that we can make infinite number of trading rules
with varying length and efficiency. The lengths of technical indicators used
in the trading rule was earlier taken heuristically or trial and error method.
Our section will propose the use of Genetic Algorithms (GAs) too generate
the length of these indicators, which in return will give us better profit or
rate of return. Thus with the use of Genetic Algorithms (GAs), level of
performance of prediction will be high. This is also seen in past researches
though the optimal value is not obtained, but the length of parameters of
technical indicators of technical trading rules is consistent in performance.
This issue is however of technical in nature. For example one simple rule is
using simple moving average. Here the length of two moving averages can
be taken up heuristically or we can use Genetic Algorithms (GAs) to finf
optimal trading lengths. In case of Moving Average Convergence Divergence
(MACD), we take difference of two moving averages, a fast moving average
and a slow moving average. If difference value is positive which means stock
price is going up, if difference value is negative that means it is going down.
Other type of indicator is stochastic oscillator (5K and %D), which is also
popular. We can use all these three indicators in conjunction with each other
to build a trading system. Then the length of the technical indicator of this
trading system is mapped into binary strings and which are optimized using
Genetic Algorithms (GAs). We are going to discuss them as a case study
matter here.
Moving averages (MAs) are the most popular and simple in concept in
calculation and usage. Moving averages (MAs) is a trend following indicator.
Its main function is to filter the noise and bring smoothness in the data.
Moving averages (MAs) is also known as lagging indicators. It gives us the
trend of the price movement, but with a time lag. It is advisable to use two
225
Developing a Single Indicator or Multiple Indicator Market Timing System
Moving averages (MAs). One will give us trend of price movement and
other will be used to generate trading signals i.e buy or sell. Calculation of
Moving averages (MAs) is the average price of the stock over a predefined
period. Thus the Moving averages (MAs) moves with the movement of time
duration. Here past data gets dropped and new data is made available. Moving
averages (MAs) are generally calculated on the closing price of the stock.
Formula for Moving averages (MAs) of ‘n’ days is given below:
1 n
MA (Close, n) = Pt − i (1)
n ∑ i =0
Here Pt-i is the closing price of the t-I and n displays the number of past
days taken to build Moving averages (MAs) (i.e length of Moving averages
(MAs)).
If two Moving averages (MAs) are to be used then one will be longer and
other will be shorter. Longer period of Moving averages (MAs) are slow and
lethargic, while shorter Moving averages (MAs) are more sensitive to the
price changes. For more effectiveness we use both shorter and longer Moving
averages (MAs) in conjunction with each other. Popular Moving averages
(MAs) rule is given below:
Crossing of Moving averages (MAs) rule is most popular and widely used
by the stock market analyst. Since there are two Moving averages (MAs), one
longer and other shorter, buy and sell signals are generated in the following
way:
θ1 θ2
1 1
θ1
∑ Pt −i >
i =0 θ2
∑P
i =0
t −i
(2)
Where θ1 < θ2
226
Developing a Single Indicator or Multiple Indicator Market Timing System
θ1 θ2
1 1
θ1
∑P
i =0
t −i
≤
θ2
∑P
i =0
t −i
(3)
Where θ1 < θ2
The parameters i.e lengths of two Moving averages (MAs) (Ɵ1 and Ɵ2) are
generally chosen by trial and error methods or by any intuition by a stock trader
or analyst. If we use two Moving averages (MAs) of length 500. Then there
will be 500 * 500 = 2,50,000/- Moving averages (MAs) combinations. Our
main aim in this model is to find the optimal value of Ɵ1 and Ɵ2 i.e Moving
averages (MAs) lengths which gives buy and sell trading signal and best return.
Thus to apply genetic Algorithms (GAs) to find the optimal value of Ɵ1 and
Ɵ2 we first mapped parameter setting to a binary string. If shorter Moving
averages (MAs) the string length is 9 bits and larger Moving averages (MAs)
string length is 10 bits, then value of shorter Moving averages (MAs) ranges
from 0 to 511 and values longer v ranges from 0 to 1023. Total concatenated
string length here is 9 bits + 10 bits = 19 bits and total search space here is
219 bits i.e 5,24,288 various combination of Moving averages (MAs). Thus
19 bits string will represents a chromosome.
Triple Moving averages (MAs) Rule: In earlier Moving averages (MAs)
crossover rule, we have seen that if there is volatility in the market then there
is a lot of whipsaws created by these Moving averages (MAs) crossovers which
results in a lot of losses. Thus there is problem of false signal generation as
confirmation of bullish and bearish trends has not been established by these
two Moving averages (MAs) crossovers. So to tackle with this problem
we develop a three Moving averages (MAs) concept. This will help us to
get confirmation of bullish and bearish trends with less whipsaw and less
losses. With the use of third Moving averages (MAs) we going to have an
exit somewhat earlier. This will help us to reduce our losses or loss making
trades during consolidation process. The whole procedure to use triple Moving
averages (MAs) is given below:
Three Moving averages (MAs) that are being used are categorized as short
term, medium term and long term Moving averages (MAs). A buy signal
is generated or position is established when shorter term Moving averages
(MAs) crosses longer term Moving averages (MAs) in the upward direction.
An exit signal is generated when shorter term Moving averages (MAs) crosses
medium term Moving averages (MAs) in down ward direction. Thus entry
in the market is somewhat delayed by the combination of short term and
long term Moving averages (MAs). This means if there is a confirmation of
227
Developing a Single Indicator or Multiple Indicator Market Timing System
trend, then and then only we are going to have an entry into the market. In
this way exit is not delayed. But it is done earlier, due to the combination of
short term and medium term Moving averages (MAs). Here the crossover is
far earlier then the crossover by longer term Moving averages (MAs). Here
in the use of triple Moving averages (MAs) we are going to get zones or
time period where no actions are being taken. This results in a reduction of
loss making trades. It is seen in many stock movements that shorter Moving
averages (MAs) crosses medium length Moving averages (MAs), but fails
to cross longer length Moving averages (MAs) and then once again moves
back. In this scenario no decision is to be taken. By seeing the pictorial
representation we can be tempted that due to this feature of third Moving
averages (MAs) many profitable trades are not executed, but the other fact
is that many loss making trades are also prevented, So less risks, less gains
and more risks and more gains.
Here the lengths of short term (Ɵ1), medium term (Ɵ2) and long term (Ɵ3)
Moving averages (MAs) have to be decided and optimal value is found out by
using Genetic Algorithms (GAs). Encoding mechanism will consist of short
term Moving averages (MAs) length (Ɵ1) will have 4 bit i.e its values ranges
from 0 to 15, medium term Moving averages (MAs) length will be encoded
to 6 bit i.e its value ranges from 0 to 63 days and long term Moving averages
(MAs) length (Ɵ3) will be encoded to 9 bit i.e its value ranges from 0 to 512
days. Thus the chromosome length will be 4 bits + 6 bits + 9 bits = 19 bits,
and total search space will be of 219 i.e 5,24,288 number of solutions existed.
Four Moving Averages (MAs) Rule: This four Moving averages (MAs)
rule is not common, though it is logically designed. Here we use two long
term Moving averages (MAs) and two short terms Moving averages (MAs).
Long term Moving averages (MAs) tells us about the trend and short term
Moving averages (MAs) tells us about the trades to be taken. An old phrase
is that “Trend is the trader friend”. So if long term Moving averages (MAs)
shows us bullish trend, then by using two short terms Moving averages
(MAs), we will take only long position or buy trade generated by them. We
will not exist until downward trend is given by longer term Moving averages
(MAs) and sell or exit signal are generated by shorter term Moving averages
(MAs). Thus here in some time zones no trades are being done and half of
the positions are executed. Main drawback with this strategy is that longer
term Moving averages (MAs) always act with a lag. So many profitable zones
in some areas are not tapped. So we can apply Genetic Algorithms (GAs)
to find the length of short term and long term Moving averages (MAs). So
to start with the encoding mechanism two short term lengths of short term
228
Developing a Single Indicator or Multiple Indicator Market Timing System
and long term length Ɵ1 and Ɵ2 will have 5 bit and 7 bit length. Ɵ1 will have
range from 0 to 128. Two long terms Moving averages (MAs) length Ɵ3 and
Ɵ4 will have 9 bit and 11 bit length. Ɵ3 will have range from 0 to 512 and Ɵ4
will have range from 0 to 2047 days. Thus a total of 12 bits for shorter Moving
averages (MAs) lengths and 20 bits for longer Moving averages (MAs) lengths
and overall 32 bits chromosome length is there for the whole strategy. So the
total search space for the strategy is 232 i.e 4,29,49,67,296 solutions exist. To
find an optimal one we can use Genetic Algorithms (GAs) to find it.
If (longer Moving averages (MAs) (Close, Ɵ3) > longer Moving averages
(MAs) (Close, Ɵ4)) AND (shorter Moving averages (MAs) (close, Ɵ1) >
shorter Moving averages (MAs) (close, Ɵ2)))
If (longer Moving averages (MAs) (Close, Ɵ3) < longer Moving averages
(MAs) (Close, Ɵ4)) AND (shorter Moving averages (MAs) (close, Ɵ1) <
shorter Moving averages (MAs) (close, Ɵ2)))
Ɵ1 and Ɵ2 are lengths of shorter Moving averages (MAs)
Ɵ3 and Ɵ4 are lengths of longer Moving averages (MAs)
θ1
Eureka (closet, MA Ɵ1) = (close – MAt (close, Ɵ1)) / (MAt (close, Ɵ1))
229
Developing a Single Indicator or Multiple Indicator Market Timing System
Here closet is the closing price of the stock at time t, Moving averages
(MAs) calculates closing price average values for time length Ɵ1. Our system
consists of “Eureka” and other is Moving averages (MAs) of Eureka. i.e
θ2
We have seen various models which uses the concepts of Moving averages
(MAs). Now we will formulate an investment strategy which will be a
combination of buy and sell using various Moving averages (MAs) of different
lengths. So these Moving averages (MAs) of different lengths can be used
with different permutation and combination. Best possible permutation can
be found out by Genetic Algorithms (GAs). Strategy is given below:
Sequence of Moving averages (MAs) we are using of various lengths are 1
day, 5 days, 15 days, 30 days, 60 days and 150 dys. Thus there are 6 Moving
averages (MAs) in picture i.e MA1, MA5, MA15, MA30, MA60 and MA150. Our
original strategy will be:
230
Developing a Single Indicator or Multiple Indicator Market Timing System
It means that if both buy and sell strategies is not satisfied then hold or
do not invest or keep your money at yourself.
Here to start with encoding mechanism, the chromosome will be made up
of integer numbers having range of value from 1 to 6. First 6 integer numbers
represents buy strategies and next 6 integer numbers represents sell strategy.
Here there are two set of 6 integers for buy and sell. Hence total search space
here is (6!)2 i.e 5,18,400. Genetic Algorithms (GAs) can be used to find
optimal set of two set of 6 integer values.
Until now we are focussed only on one technical indicators i.e Moving
averages (MAs). In order to get more accurate results a trading system should
be made by combination of various other technical indicators also. Moving
averages (MAs) are trend giving indicators. Momentum indicators along
with trend following indicators are popularly used to increase the accuracy
and to confirm and falsify the signals of buy or sell generated. Our trading
system developed and presented consists of three most popular indicators i.e
Moving averages (MAs), Moving average Convergence Divergence (MACD)
and Relative Strength Index (RSI)
MA = Moving Average.
EMA = Exponential Moving Average.
MACD = Moving Average Convergence Divergence.
RSI = Relative Strength Index.
231
Developing a Single Indicator or Multiple Indicator Market Timing System
232
Developing a Single Indicator or Multiple Indicator Market Timing System
solutions exist. Here Genetic Algorithms (Gas) is used to find optimal values
of various time lengths or optimal string.
IF
Long not existing AND
Lag (ROC (n1), l1) op1 θ1% AND
Lag (STO (n2), l2) op2 θ2% AND
Lag (OBV (n3), l3) op3 θ3% AND
Lag (PSY (n4), l4) op4 θ4%
THEN
Enter long at next opening price
Long exit rule
IF
Long not existing AND
Lag (ROC (n5), l5) op5 θ5% AND
Lag (STO (n6), l6) op6 θ6% AND
Lag (OBV (n7), l7) op7 θ7% AND
Lag (PSY (n8), l8) op8 θ8%
THEN
Enter long at next opening price
Long stop rule
IF
Long existing AND
Close < (1-r%) * highest high
233
Developing a Single Indicator or Multiple Indicator Market Timing System
the encoding mechanism i.e we need to specify the binary bits length of the
parameters i.e n’s, l’s, op’s, θ’s and r.
Strategy of encoding is as follows:
Eight bits (0 to 255) for each i.e from n1 to n8 for each indicator
Three bits (0 to 7) for each i.e from l1 to l8 for each indicator
One bits (0 to 1) for each i.e from ops i.e 0 for < and 1 for > for each indicator
Seven bits (0 to 127) for each i.e from θ1 to θ8 for each indicator
And 5 bits for r for stop rule.
f
TRf = ∏ (1 + DRi )
i =1
DRi = (Pi − Pi −1 )× δ
TRf is the total return for the sample period. DRi is the daily return for
the day i, Pi denotes the stock price for the day i. δ is the dummy variable
which generates value 1 for buy (long) signals and -1 for sale (short) signals.
Trading system takes sell and buy positions, but no out of-market-positions.
Transaction costs are not included as our main aim in this paper is to find the
possibility of solving an optimization problem by using genetic algorithm.
Here our main intention is to find these trading strategies or technical
trading system and optimized their parameters by using Genetic Algorithms
(GAs) is to generate profit or capital. It is impossible to construct a trading
system which is 100% accurate. So our approach is to find a system with
a reasonable high degree of accuracy. This can be find by applying these
234
Developing a Single Indicator or Multiple Indicator Market Timing System
12.6 CONCLUSION
235
Developing a Single Indicator or Multiple Indicator Market Timing System
REFERENCES
Allen, F., & Karjalainen, R. (1998). Using genetic algorithms to find technical
trading rules. Journal of Financial Economics, 51(2), 245–271. doi:10.1016/
S0304-405X(98)00052-X
Bauer, R. J. Jr. (1994). Genetic Algorithms and Investment Strategies. John
Wiley and Sons, Inc.
Deb, K. (2002). Optimization for Engineering Design: Algorithm and
Examples. Prentice Hall of India Private Limited.
Goldberg, D. E. (2002). Genetic Algorithms in Search. Optimization and
Machine Learning Pearson Education, Asia.
Kapoor, V., Dey, S., & Khurana, A. P. (2011). Genetic algorithm: An application
to technical trading system design. International Journal of Computers and
Applications, 36(5), 44–50.
Letamendia, L. N. (2007). Fitting Control Parameters of a Genetic Algorithm:
An Application to Technicl Trading Systems Design. European Journal of
Operational Research, 179(3), 847–865. doi:10.1016/j.ejor.2005.03.067
Mahfoud, S., & Mani, G. (1996). Financial Forecasting Using
Genetic Algorithms. Applied Artificial Intelligence, 10(6), 543–566.
doi:10.1080/088395196118425
236
Section 4
Genetic Algorithms in
Other Areas
238
Chapter 13
Some Other Applications of
Genetic Algorithms (GAs)
ABSTRACT
As we had already seen that genetic algorithms (GAs) are smart in their
working. Here, the authors explore the rich working of genetic algorithms
(GAs) in various diversified fields. Until now, they had discussed the historical
nature of genetic algorithms (GAs). They have also discussed the programming
code to run simple genetic algorithms (SGA). Lastly, they are going to take
an overview of the application of genetic algorithms (GAs) in various fields
(i.e., from business to non-business). Already, they have discussed the robust
working of genetic algorithms (GAs) in various adverse conditions. Here,
they discuss the application of genetic algorithms (GAs) in various other
diversified fields.
13.1 INTRODUCTION
DOI: 10.4018/978-1-7998-4105-0.ch013
Copyright © 2021, IGI Global. Copying or distributing in print or electronic forms without written permission of IGI Global is prohibited.
Some Other Applications of Genetic Algorithms (GAs)
239
Some Other Applications of Genetic Algorithms (GAs)
faces. The witness to the criminal in crime scene will take a look about all
the images and recognize the image and gives it a rating from 1 to 10. Thus
after the fitness function is assigned by the witness, various operators such as
selection, crossover and mutation are applied to produce population for next
generation. This will go into a loop form until convergence or desired result is
not obtained. Here in order to increase the efficiency of Genetic Algorithms
(GAs), if forehead features in some picture in a generation population member
exactly matches with the criminal forehead, then we will freeze that feature
and will look or concentrate on other features. Past researches has shown
that here convergence took place after a lot of generations.
240
Some Other Applications of Genetic Algorithms (GAs)
13.4 SCHEDULING
Genetic Algorithms (GAs) has been successfully applied for scheduling for
any type of transportation i.e to explore routes with cost effectiveness. Here
the model when develop manually can be of complex in nature. Use of Genetic
Algorithms (GAs) reduces the complexity of these models.
Moving of automobiles i.e cars, jeeps, SUV etc. around various destination
places through various routes is very cost intensive. Any error in scheduling
of it will result in an exponential increase of cost. Generally we group cars
into various blocks. So train which takes them to the destination consists
of locomotive and blocks. A group of cars is called blocks which has same
origination and destination. Route is number of nodes between origination
and destination. So the route must be such that it has lower costs. Use of
Genetic Algorithms (GAs) must have a string which is mapped to a route. The
fitness function is the cost of route which is given in the master index. Here
our objective is function minimization i.e lowering of costs. Major usefulness
of using Genetic Algorithms (GAs) is in its easy simulation. The complex
interaction of parameters whose optimized values is to find using Genetic
Algorithms (GAs) is difficult to find using traditional techniques if search
process is high. In case of scheduling problem, they are generally complex
if number of routes or nodes is large. Brute force search process generally
tries to test all the routes by testing a large number of combinations. It is not
advisable as it is time consuming. Genetic Algorithms (GAs) being a heuristic
based search process tries to find close to optimal solution with only trying
few iterations. It is seen that problem representation in form of strings and
fitness function formula is important part of Genetic Algorithms (GAs). The
main aim of Genetic Algorithms (GAs) is to find best schedule. Past results
by researchers show that Genetic Algorithms (GAs) has been able to search
from a large number of orderings. It is the perspective of Genetic Algorithms
(GAs) researcher to use basic crossover, mutation and selection operator.
He can make intelligent changes in the operators working depending upon
the problem to problem. In case of mutation he can randomly change the
string that is being mutated or we can interchange the position of the string.
Thus from the whole study we had come to make an beautiful inference that
application of Genetic Algorithms (GAs) is half engineering and half art.
241
Some Other Applications of Genetic Algorithms (GAs)
Genetic Algorithms (GAs) can also be use to find which horse will win in the
race. Here various rules are made, using horse edge, last race performance etc.
Genetic Algorithms (GAs) form various rule by the use of these parameters.
Fitness function formula is find by using the winner data for previous race.
Genetic Algorithms (GAs) was successful in finding rule that has an accuracy
of 80%. This outperforms the manual system of picking a horse and placing
bet on it.
It is seen that with the use of computers in every part of life, data bases and
there are increasing with an exponential speed. With this data base management
system (DBMS) are becoming complex day by day with newer foreign keys
and primary keys to connect them. So the system analyst has to make tedious
queries in Data Base Management System (DBMS). These complex queries
are combination of algebra and logical operators with in the various entries
in the data base.
As more and more tables are added in the data base the possibility of
queries that can be formed is increased exponentially. In this way query
search space is more. We develop query and query optimization is the need
of the hour. Genetic Algorithms (GAs) is finally used to optimized the query.
Here chromosomes are represented as a binary tree and on it crossover and
242
Some Other Applications of Genetic Algorithms (GAs)
mutation can be applied with newer variations. Thus Genetic Algorithms (GAs)
based optimization gives us better results in comparison to the traditional
optimization procedures.
13.9 CONCLUSION
243
Some Other Applications of Genetic Algorithms (GAs)
REFERENCES
244
245
Chapter 14
Introduction to Some Other
Nature-Inspired Algorithms
ABSTRACT
In order to solve any problem through the use of computation, algorithms
are required. These days, algorithms are inspired from the working of nature.
These algorithms are becoming popular among researchers. Many real-world
solutions are being obtained from them. Nature-inspired algorithms are
powerful, flexible, find better results within a small period of time, and can
be used to search optimal values for the problems. This chapter introduces
some of the popular nature-inspired algorithms other than genetic algorithms
(GAs), which were studied earlier.
14.1 INTRODUCTION
DOI: 10.4018/978-1-7998-4105-0.ch014
Copyright © 2021, IGI Global. Copying or distributing in print or electronic forms without written permission of IGI Global is prohibited.
Introduction to Some Other Nature-Inspired Algorithms
246
Introduction to Some Other Nature-Inspired Algorithms
247
Introduction to Some Other Nature-Inspired Algorithms
248
Introduction to Some Other Nature-Inspired Algorithms
249
Introduction to Some Other Nature-Inspired Algorithms
250
Introduction to Some Other Nature-Inspired Algorithms
a certain trajectory. There is always some probability that will reach global
optimum, no matter what the trajectory we follow. Here is the list of some
nature inspired algorithms that are heuristic and Meta heuristic algorithms
in their working:
Big bang-big Crunch, Black hole, Central force optimization, Charged system
search, Electro-magnetism optimization, Galaxy-based search algorithm,
Gravitational search, Harmony Search, Intelligent water drop, River formation
dynamics, Self-propelled particles, Simulated Annealing, Stochastic diffusion
search, Spiral optimization, Water cycle algorithm.
251
Introduction to Some Other Nature-Inspired Algorithms
252
Introduction to Some Other Nature-Inspired Algorithms
Neural Networks (NN) has been used promisingly by the researchers as a tool
to solve many real world problems. A lot of internal design changes in Neural
Networks (NN) implementation can be done. This affects the accuracy also.
These design factors consists of input data, architecture, number of nodes,
number of layers etc. Neural Networks (NN) has been efficient to search and
map non linear system in between output and input. They are well suited
for problem that exhibit chaos for example stock market prediction. Stock
market is a random walk and it cannot be easily expressed with the help of
traditional mathematical models. The ability of Neural Networks (NN) is to
find solution in these non linear deterministic, chaotic process. We keep Neural
Networks (NN) in a different set when we compared with traditional system
to solve the real world problem. Neural Networks (NN) inside procedure is
somewhat of black box in nature. Here we identify the input variables and
results are obtained by not much knowing the system. Processing of Neural
Networks (NN) is parallel in nature, less time consuming and fault resistant.
Here we don’t have to formalize rules while implementing it. As many of
the complex real world problems are very less or partially understood. It is
not necessary in Neural Networks (NN) to formulate rules in it as compared
in the expert system. In stock market environment there is a high degree of
dynamic data, which can be handled efficiently by Neural Networks (NN).
As in real world hard problem consists of non linear liaison among the
input data. Neural Networks (NN) is judged in three areas:
253
Introduction to Some Other Nature-Inspired Algorithms
Networks (NN) architecture exists, among them the most popular in the past
researches is back propagation network. Here we back propagate the errors
in the system during the training process. As hidden layers have not been the
training objective, so they can be trained by the process of back propagation.
This helps the output layer which only has the training target. Due to back
propagation the connection weight values can be changed. This goes on and on
as error generated is squeezed down, so that they can be accepted universally.
Thus question which comes into existence is when to decide that we stop
training. In past researchers has reported that over training can be a serious
problem, since it helps to memorize the system and generalization ability of
the system is weakened. A lot of input variables and hidden variables results
in an over training of data. This problem of over training can be covered by
training network on a lot of data and testing it on remaining pattern. So if the
performance is very less. Then network architecture and input data variables
are to be changed. In this way retraining of the network is being done and
more satisfactory performance is obtained. So we are able to squeeze the
error and optimal network architecture is obtained. Training the network
on a very large old data set is time consuming, as network will learn about
pattern which is no longer viable.
In case of back propagation network there is always a supplementary
learning, as weights are depending upon the errors. If the error generated
exceeds in its tolerance then they have to be back propagated. Due to this it is
faster and we can experiment on large volume of data. Thus the weights are
also change randomly in order to squeeze the error in the data that has been
back propagated. So in order to avoid the problem of over training, system
must be cross validated from time to time. Now it is clear that neural network
is just a complicated form of multiple regressions. Here network can be of
varying sizes i.e small number of input variables to a thousand of them, from
two to three layers to a dozen of layers. These parameters are chosen by seeing
the complexity of the real world problem, which we are addressing. It is still
debatable which neural network architecture is optimal or best. In present
scenario neural network is applied to almost all the complicated real world
problems. In neural network research pruning and to find optimized neural
network architecture is hot area of research. This will help end user to remove
redundant layers and speed up the delivery of result. A lot of research work is
being done to find the better practices to use neural network in a optimal and
less time consuming way. Neural network is a complete black box technique
with least human involvement is required to run them. Hence in future the
focus of researchers is to improve Neural network performance and through
254
Introduction to Some Other Nature-Inspired Algorithms
it get more insights in the chaotic real world system that we are trying to tap
it. Though Neural network is not the best procedure to solve a real world
problem, but it is one of the desirable system to get a better understanding of
the chaotic and complex system which has not been understood for a long time.
This process to find global minimum resembles the molten metal cooling by
using annealing process. At higher temperature atoms in the molten metal
has a large degree of freedom in comparison to one another. As molten metal
moves towards the room temperature the degree of freedom of atoms or their
movement gets restricted. Thus here in a natural system of molten metal when
metal cools then it forms a crystalline state with a lesser energy state. If metal
is cooled in a faster rate then, instead of crystalline state polycrystalline state
is achieved. It has a higher energy state as compared to crystalline state. So
to obtain lesser energy level or crystalline state the molten metal should be
cooled at a slower rate. This whole procedure of slow and controlled cooling is
called annealing. Thus Simulated Annealing simulates or mimics the process
of slowness of cooling molten metal in order to get global minimization
values. Here cooling of something is controlled by introducing a parameter
called temperature encapsulated by the concept of Bolzman probability
distribution. It says that any system in thermal equilibrium at temperature T
has its energy distributed probabilistically in accordance to the formula P (E)
= exp (-E/kT), where k is the Bolzman constant. At higher temperature there
is a larger probability of a system to be at higher energy state as compare to
the system at a lower temperature. Thus by controlling temperature T and
search process follows Bolzman probability curve the converging property
of the algorithm is controlled.
Simulated Annealing searches by point to point. So start with the algorithm
we start with some initial point at higher temperature. A second point is
generated randomly in closeness to the initial point generated and distinction
in objective function standards of these two points is calculated. If second
point ha small function value then it is accepted, if not then it is rejected
or accepted with a probability exp(-A E/T). This is the one iteration of the
whole process. In next step another point is selected randomly in vicinity
to that current point. Thus based on its objective function value this point
is accepted or rejected. Thus at a particular temperature a large number of
points are generated randomly and tested. After this, temperature is reduced
255
Introduction to Some Other Nature-Inspired Algorithms
and this procedure goes on for a number of iterations. When we test for a less
temperature then negligible changes in function values are obtained. Thus
introduction of the term temperature have effects on the learning rate. We
start with a very high temperature, and moves over the error space. As the
training process continues, the temperature decreases and thus the learning
also slow down and get converge to a near optimal solution. Thus search in
the solution space reduces the process of oscillation in order to reach minimal
point on the search or error space.
256
Introduction to Some Other Nature-Inspired Algorithms
257
Introduction to Some Other Nature-Inspired Algorithms
of solution they had found so far. Thus in the coming simulation or iteration
they will try to locate other better solution in the search space. This Ant
Colony Optimization Algorithm is similar to bees algorithm, an another
type of social insect.
Ant Colony Optimization Algorithm was initially discussed by Marco
Dorigo in 1992 in his Ph D dissertation work. In biological environment, ant
used to search randomly for food. Once they find food they return to their
colony or home by laying down pheromones trails. Other ants when found
this pheromones trails will abandon their random path and will follow that
trail and will find food. As time passes, or there is large path between food
and colony then this pheromones trail will get evaporated. Thus in shorter
paths pheromones density is more. There is an advantage in evaporation of
pheromones, such that in real world it will not allow algorithm to converge
at the local optimal point or solution. This will results in better exploration
of solution space. This evaporation of pheromones in real world is copied in
the artificial working of the algorithm. Thus simulated ant search the global
search space and are of explorative in nature, while real ants search for local
search spaces and are of exploitative in nature.
This chapter in a whole has made its focus on the use of nature inspired
intelligent computational methods. These nature inspired algorithms enhanced,
adaptive and improved in their working as compared to traditional algorithms
in terms of efficiency and efficacy. We have discussed their theory and brief
methodology, so that they can work in complex and challenging scenarios.
There are being now a day’s applied in diversified engineering application
problems.
14.3 CONCLUSION
Most of the researchers, engineers and analyst in solving real world problem
come to know the importance of optimization and their role in to make our
life easier. Initially optimization was a mathematical or operation research
related procedure. With the introduction to the computer, they are being
seen as a computational process. The aim of optimization is not to find some
parameters, but to find the best parameters found until so far. In optimization
a lot of iteration is being done to find best solution. Here newer parameters
are being tested to find best solution find so far. Nature inspired algorithms
mimic the working of nature or living being or certain natural phenomenon.
They had more potential as they are parallel in their working and has a
258
Introduction to Some Other Nature-Inspired Algorithms
REFERENCES
259
260
Index
A E
alpha numeric 33, 37, 68, 105-106, 117 economic data 218-219
Artificial Intelligence (AI) 7-8, 11, 13, 24, Efficient Market Hypothesis (EMH) 24,
30, 33, 37, 169, 171-172, 175, 197- 102, 157-160, 165, 171, 215
198, 214, 236, 251-252 evolutionary computation 130, 167-168
B F
binary encoding 25, 68, 90-91, 131 fitness function 4, 8, 25-27, 32, 37, 39, 43,
binary strings 37, 41-42, 51-52, 60, 93, 103, 46-48, 50-52, 56-57, 59, 64, 69-71,
106, 117-118, 122, 139, 144, 218, 225, 73-74, 84-85, 87, 89, 93, 103-105, 107-
232, 239-240 112, 117-119, 123-124, 130, 135-137,
bit pattern 45, 51, 58, 64, 72-73, 145 148, 150, 167-168, 198, 200-201, 204,
building blocks 49, 60-61, 64, 72, 122-125, 211-212, 216-218, 222-223, 234-235,
130, 139, 147-148 240-242, 247
fitness function formula 43, 50-52, 56, 107,
C 110, 112, 204, 217-218, 222, 234-235,
241-242
Chaos theory 1-8, 11-13, 16-17, 108-110, fundamental analysis 160-163, 169-170,
113 175, 216, 219-221
chart analysis 174, 184 Fuzzy Logic 1-2, 4-5, 7-8, 11-13, 17-19, 23,
computational power 11, 111, 155, 165, 31, 53, 65, 94, 102, 113-114, 152, 155,
220, 246, 249 165, 167, 169, 172, 201-202, 214, 244
crossover operators 63, 72, 125, 141
crossover probability 63, 71-72, 78, 86, 88, G
95, 104, 115, 117-118, 120
GA code 67, 87, 91, 93, 110, 112-113,
D 115, 144
Genetic Algorithms (GAs) 1, 4, 7-8, 10-
Darwin theory 4, 7, 24, 32, 40-41, 54, 70, 11, 24-27, 30-34, 36-37, 39-41, 44,
103, 129, 167, 198-199 48-51, 53-55, 58, 60-61, 64-65, 94,
detail analysis 155, 161, 174-175, 184 102-103, 106, 113-117, 123, 127-130,
145, 147, 151-152, 154-157, 161, 165,
167, 169-170, 172, 197-206, 211-212,
Index
262