chapter 5. stock portfolio selection using genetic...
TRANSCRIPT
Chapter 5 Stock Portfolio Selection using Genetic Algorithm
159
Chapter 5. Stock Portfolio Selection using Genetic Algorithm
In this study, a genetic algorithm is used for Stock Portfolio Selection. The shares of the
companies are considered as stock in this work. In the first stage good quality of stocks
are identified by stock ranking. In the second stage investment allocation in the selected
good quality stocks is optimized using genetic algorithm. Hence by using genetic
algorithm an optimal portfolio can be determined. This application provides a very
feasible and useful tool to assist the investors in planning their investment strategy and
constructing their portfolio.
5.1 Markowitz Portfolio Theory
Modern portfolio theory (MPT) is a theory of finance which attempts to maximize
portfolio expected return for a given amount of portfolio risk, or equivalently minimize
risk for a given level of expected return, by carefully choosing the proportions of various
assets. Although MPT is widely used in practice in the financial industry and several of
its creators won a Nobel memorial prize for the theory, in recent years the basic
assumptions of MPT have been widely challenged by fields such as behavioral
economics.
MPT is a mathematical formulation of the concept of diversification in investing, with the
aim of selecting a collection of investment assets that has collectively lower risk than any
individual asset. That this is possible can be seen intuitively because different types of
assets often change in value in opposite ways. For example, to the extent prices in the
stock market move differently from prices in the bond market, a collection of both types
of assets can in theory face lower overall risk than either individually. But diversification
lowers risk even if assets returns are not negatively correlated—indeed, even if they are
positively correlated.
More technically, MPT models assets return as a normally distributed function (or more
generally as an elliptically distributed random variable), define risk as the standard
Chapter 5 Stock Portfolio Selection using Genetic Algorithm
160
deviation of return, and model a portfolio as a weighted combination of assets, so that the
return of a portfolio is the weighted combination of the assets' returns. By combining
different assets whose returns are not perfectly positively correlated, MPT seeks to
reduce the total variance of the portfolio return. MPT also assumes that investors are
rational and markets are efficient.
MPT was developed in the 1950s through the early 1970s and was considered an
important advance in the mathematical modeling of finance. Since then, many theoretical
and practical criticisms have been leveled against it. These include the fact that financial
returns do not follow a Gaussian distribution or indeed any symmetric distribution, and
that correlations between asset classes are not fixed but can vary depending on external
events (especially in crises). Further, there is growing evidence that investors are not
rational and markets are not efficient.
5.2 Design and Implementation
Genetic algorithms are probabilistic, robost and heuristic search algorithms premised on
the evolutionary ideas of natural selection and genetic. The basic concept of genetic
algorithms is designed to simulate the processes in natural system necessary in for
evolution, specifically for those that follow the principle of survival of the fittest. They
represent the intelligent exploitation of a random search within a defined search space to
solve a problem. Genetic Algorithm is developed by John Holland and his students at
Michigan University during 1965-1975.
Implementation of Problem
The Complete Genetic Algorithm design has been prepared for the problem in C
language and now it is applied to some real data. Total 32 listed Companies are
considered as a data set. Financial indicators namely ROCE, LR and P/E Ratio are given
as a input to stock ranking model. Here share is considered as stock for our problem. By
applying Stock Ranking Model with the financial indicators ROCE, LR and P/E Ratio for
Chapter 5 Stock Portfolio Selection using Genetic Algorithm
161
consecutively 5 years (2007 to 2011) as an input to genetic algorithm, rank of a particular
company is obtained. After getting the rank and applying sorting to ranks we select top
10 companies as a input to genetic algorithm.
Input Size:
Top 10 companies as objects are taken as input to genetic algorithm. Hence the
chromosome size will be 10.
Encoding Scheme:
Value Encoding has been applied to the problem.
Fitness Function:
The total value of the permutation if its weight is ≤ max capacity.
Parent Selection:
After finding the fitness value of each member of the population first Elitism is applied
and few best chromosomes are selected and copied to the new generation and then
Roulette wheel selection is applied to copy rest of the population.
Crossover/ Mutation point:
Whether to do the crossover or mutation is determined by generating a random number
and comparing it with the user entered probability. Once it is decided to do
crossover/mutation, the crossover/mutation points are also determined randomly, by
generating a random number. Here one point crossover and exchange a position is used
for crossover and mutation.
Chapter 5 Stock Portfolio Selection using Genetic Algorithm
162
5.3 Stock Ranking Model
The aim of this stage is to identify the quality of each stock so that investors can choose
some good ones for investment by using stock ranking. In this study, total 32 companies
are considered as shown in table 5.1. Some financial indicators of these listed companies
are employed to determine and identify the quality of each stock. That is, the financial
indicators of the companies are used as input variables while a score is given to rank the
stocks. The output variable is stock rank. Through the study of Markowitz Portfolio
Theory, three important financial indicators, Return On Capital Employed (ROCE),
Price/Earnings ratio (P/E Ratio), and Liquidity Ratio are utilized in this study. The real
data for the year 2007 to 2011 are utilized in this study. The real data is described in
Annexure 1. The Stock Ranking Model is developed in C language.
The definition of financial indicators are given as follows
Financial Indicators
ROCE = (Profit) / (Shareholder’s Equity) * 100 % (5.1)
P/E Ratio = (Stock Price) / ( Earning Per Share) * 100 % (5.2)
Liquidity Ratio = (Current Assets) / (Current Liabilities) * 100 % (5.3)
Table 5.1 Companies with its Sr.No. and Company Name
Sr. No. Company Name
1 3I Infotech
2 Aarti Drugs
3 Ashok Leyland
4 Cipla
Chapter 5 Stock Portfolio Selection using Genetic Algorithm
163
5 Bajaj Telefims
6 Crisil
7 Blue Star
8 Fulford (India)
9 Gujarat Gas
10 JSW Steel
11 Sun Pharmaceutical Industries
12 Sonata Software
13 UltraTech Cement
14 Aptech
15 Amtek India
16 Apollo Tyres
17 Bharti Airtel
18 Cholamandalam I & FC
19 Crompton Greaves
20 Finolex Industries
21 Gabriel India
22 Kansai Nerolac Paints
23 Granules India
24 Graphite India
25 India Oil Corporation
26 Infomedia 18
27 Kajaria Ceramics
28 Surya Roshni
29 Tata Steel
30 Uttam Galva Steel
31 UTV Software Communications
32 ACC
Chapter 5 Stock Portfolio Selection using Genetic Algorithm
164
Status
Here 8 statuses are designed representing different qualities in terms of different interval
varying from 0 ( Extremely Poor ) to 7 ( Very Good ). The statuses for financial
indicators are as shown in the status table 5.2 below.
Table 5.2 Status Table
VALUE STATUS
-∞ to -30 % 0
-30 % to -10 % 1
-10 % to +10 % 2
10 % to 30 % 3
30 % to 50 % 4
50 % to 70 % 5
70 % to 90 % 6
90 % to +∞ 7
The output of the three financial indicators for each year is compared with the status table
to get individual ranking of each financial indicator. After obtaining individual rank of
each financial indicator for each year all are added to get rank. After getting the rank of
each year, all the individual rank of all years are again added. After adding all the
individual rank of all years an average is taken to get the final rank. Here the lowest final
rank is 0 and highest final rank is 21. Hence in this way final stock rank of each and
every company is obtained. After getting final stock rank of each and every company
sorting of final ranks id done to get top 10 companies.
Chapter 5 Stock Portfolio Selection using Genetic Algorithm
165
5.4 Stock Portfolio Selection using Knapsack Problem with Genetic Algorithm
5.4.1 Knapsack Problem
The knapsack problem is defined as follows:
We are given a set of n items, each item j having an integer profit pj and an integer
weight wj . The problem is to choose a subset of the items such that their overall profit is
maximized, while the overall weight does not exceed a given capacity c. We may
formulate the model as the following integer programming model:
𝑚𝑎𝑥𝑖𝑚𝑖𝑧𝑒 𝑝𝑗𝑛𝑗=1 𝑥𝑗 (5.4)
𝑠𝑢𝑏𝑗𝑒𝑐𝑡 𝑡𝑜 𝑤𝑗
𝑛
𝑗=1
𝑥𝑗 ≤ 𝐶
𝑤ℎ𝑒𝑟𝑒 𝑥𝑗 ∈ 0,1 , 𝑗 = 1,2, … , 𝑛
where the binary decision variables xj are used to indicate whether item j is included in
the knapsack or not. Without loss of generality it may be assumed that all profits and
weights are positive, that all weights are smaller than the capacity c, and that the overall
weight of the items exceeds c.
Knapsack problem is one of the most intensively studied discrete programming problems.
The reason for such interest basically derives from three facets.
(a) It can be viewed as the simplest Integer Linear Programming problem
(b) It appears as a sub-problem in many more complex problems
(c) It may represent a great many practical situation.
Chapter 5 Stock Portfolio Selection using Genetic Algorithm
166
In the previous stage, some good quality stocks can be revealed in terms of stock return
ranking. These good qualities of stocks are used as an input to genetic algorithm. The
three basic questions regarding investment decision occurs as follows:-
In which company should I invest?
How much money in which company should I invest?
5.4.2 Steps of Genetic Algorithm for Stock Portfolio Selection:-
1) Generate initial random population.
2) Calculate the fitness value of each chromosome.
3) Fitness value = (Profit)*(Units)
where Profit = ((Current share value – Previous share value) / previous share value)
1 Unit = Rs. 1000
Maximum Units = 100
Total Investment = Rs. 1 Lac
4) Apply Roulette wheel selection method to select good chromosomes.
5) Apply crossover and mutation to good chromosomes.
6) Again calculate fitness value of chromosomes.
7) Repeat from step 2 to 6 until a best chromosome is found.
Chapter 5 Stock Portfolio Selection using Genetic Algorithm
167
After completing genetic algorithm the answers of all the three questions specified above
are obtained.
5.4.3 Selection Criteria
Encoding Technique : Value Encoding
Number of Chromosomes : 30
Number of Companies : 10
Number of Units = 100
Maximum Investment = Rs. 1 Lac
Minimum Crossover Probability :0.60
Maximum Crossover Probability : 0.95
Minimum Mutation Probability : 0.001
Maximum Mutation Probability : 1.00
Selection Method: - Roulette Wheel Selection
Crossover Method: - 1-point crossover
Mutation Method:- Exchange a position
Chapter 5 Stock Portfolio Selection using Genetic Algorithm
168
5.5 Computational Results
5.5.1 Results of Stock Ranking Model
Here the stock ranking model gives the output as top 10 companies with its Sr.No. Rank
and Company Name in table 5.3. Now from the 32 companies, 18 companies are listed
below as a top 10 companies. Below listed companies are considered for the investment
for the investor. The investor can select any 10 companies from the below given 18
companies for the investment.
Table 5.3 Top 10 companies with its Sr.No. Rank and Company Name
Sr. No. Rank Company Name
2 21 Aarti Drugs
4 21 Cipla
5 21 Balaji Telefims
6 21 Crisil
7 21 Blue Star
8 21 Fulford (India)
10 21 JSW Steel
11 21 Sun Pharmaceutical Industries
13 21 Ultratech Cement
16 21 Apollo Tyres
19 21 Crompton Greaves
21 21 Gabriel India
22 21 Kansai Nerolac Paints
24 21 Graphite India
25 21 India Oil Corporation
27 21 Kajaria Ceramics
29 21 Tata Steel
32 21 ACC
Chapter 5 Stock Portfolio Selection using Genetic Algorithm
169
5.5.2 Stock Portfolio Selection
From the table 5.3 top 10 companies can be selected. Here A to J represents the top 10
companies from as shown in table 5.4. The description of these top 10 companies is as
shown in table 5.4.
Table 5.4 Top 10 companies with its company name
Sr. No. Company Company Name
1 A Aarti Drugs
2 B Cipla
3 C Balaji Telefims
4 D Crisil
5 E Fulford (India)
6 F JSW Steel
7 G Sun Pharmaceutical Industries
8 H Crompton Greaves
9 I India Oil Corporation
10 J Tata Steel
Chapter 5 Stock Portfolio Selection using Genetic Algorithm
170
Executing Genetic Algorithm
By executing the Genetic Algorithm the Initial Random Population is generated which is
shown below in table 5.5. Here companies are A to J. The values of A to J are
represented in Units. 1 Unit is Rs. 1000. Total represents the total investment in rupees
(thousands) in the various companies A to J. Fitness represents the fitness value of the
chromosome. The initial random population gives the output Best Chromosome,
Maximum Fitness and Total investment as shown in table 5.5.
Table 5.5 Initial Random Population generated by Genetic Algorithm
A B C D E F G H I J Total Fitness
2 12 8 16 13 17 5 4 5 2 84 -0.7835
6 16 7 12 13 8 0 2 10 13 87 3.1825
14 7 4 1 11 6 17 0 2 1 63 -4.8308
15 2 12 12 2 13 10 7 15 8 96 -2.3039
9 7 16 12 1 16 4 4 8 7 84 1.3347
5 14 17 7 16 8 2 6 7 12 94 3.4474
14 11 13 0 14 6 9 3 3 14 87 0.3830
8 3 5 10 10 1 9 13 16 13 88 0.3370
5 6 1 10 7 3 14 12 11 15 84 -2.6729
7 5 5 16 0 11 6 10 15 13 88 0.4752
12 17 11 15 5 3 2 10 2 17 94 2.4413
9 3 4 14 8 10 5 11 12 8 84 0.2516
2 13 11 4 8 13 4 2 16 11 84 2.9864
11 3 8 0 16 8 1 0 1 12 60 1.4736
1 11 1 10 3 7 12 1 10 14 70 -2.4598
9 10 5 6 3 12 9 4 2 13 73 -1.6438
10 7 5 2 16 15 9 6 10 3 83 -0.7359
Chapter 5 Stock Portfolio Selection using Genetic Algorithm
171
2 17 2 1 8 11 9 2 5 13 70 -0.8785
8 2 13 15 12 13 10 5 1 11 90 -2.7115
3 3 1 8 5 2 14 16 15 12 79 -2.1404
5 0 16 9 10 9 13 13 5 11 91 -2.2182
17 6 9 16 1 16 3 5 2 15 90 0.2386
0 16 7 17 14 14 13 7 1 8 97 -3.8805
9 11 11 9 17 6 3 10 10 9 95 -0.2316
9 8 5 8 5 13 7 11 9 7 82 0.9231
2 10 7 3 6 15 10 11 8 13 85 -0.7347
7 3 1 6 12 0 7 9 9 2 56 -0.6742
7 0 11 9 10 1 14 7 9 16 84 -2.2697
16 2 15 5 14 8 16 9 13 0 98 -1.9110
10 12 0 9 9 10 7 12 5 1 75 0.6507
Best Chromosome = 5 14 17 7 16 8 2 6 7 12
Maximum Fitness = 3.4474 at Total = 94
Chapter 5 Stock Portfolio Selection using Genetic Algorithm
172
5.5.3 Results at different Crossover Probability and Mutation Probability
For,
Minimum Crossover Probability = 0.00
Maximum Crossover Probability = 1.00
Minimum Mutation Probability = 0.001
Maximum Mutation Probability = 0.08
Results for 800 generations
Best chromosome = 3 15 12 0 4 10 2 1 10 5
Maximum Fitness = 3.4308 at Total = 62
Results for 1000 generations
Best chromosome = 8 12 3 17 1 3 1 7 4 8
Maximum Fitness = 3.5253 at Total = 64
Results for 1500 generations
Best chromosome = 4 17 16 3 6 5 1 10 2 11
Maximum Fitness = 3.7315 at Total = 75
Results for 2000 generations
Best chromosome = 4 17 13 3 8 6 3 2 14 6
Maximum Fitness = 3.8699 at Total = 76
Chapter 5 Stock Portfolio Selection using Genetic Algorithm
173
Results for 3000 generations
Best chromosome = 6 17 4 9 1 12 1 8 14 10
Maximum Fitness = 3.9388 at Total = 82
Results for 4000 generations
Best chromosome = 6 17 4 9 1 12 1 8 14 10
Maximum Fitness = 3.9388 at Total = 82
Results for 5000 generations
Best chromosome = 6 17 4 9 1 12 1 8 14 10
Maximum Fitness = 3.9388 at Total = 82
From the above results it is found that at generations 800, 1000, 1500 and 2000 we are
getting variations in Best chromosome, Maximum Fitness and Total investment. But at
generations 3000, 4000 and 5000 we are getting the same Best chromosome, Maximum
Fitness and Total investment. This concludes that at generations 800, 1000, 1500 and
2000 investor may not take decision for investment in various companies for portfolio
management. Finally at generations 3000, 4000 and 5000 the investor can take decision
for investment in various companies for portfolio management.
Chapter 5 Stock Portfolio Selection using Genetic Algorithm
174
For,
Minimum Crossover Probability = 0.40
Maximum Crossover Probability = 1.00
Minimum Mutation Probability = 0.001
Maximum Mutation Probability = 0.50
Results for 800 generations
Best chromosome = 16 16 16 1 1 1 1 1 16 1
Maximum Fitness = 5.7575 at Total = 70
Results for 1000 generations
Best chromosome = 1 17 17 1 1 1 1 17 17 1
Maximum Fitness = 6.2364 at Total = 74
Results for 1500 generations
Best chromosome = 15 13 15 2 1 1 2 14 15 2
Maximum Fitness = 5.5143 at Total = 80
Results for 2000 generations
Best chromosome = 3 13 15 3 3 3 1 11 17 11
Maximum Fitness = 6.8366 at Total = 80
Chapter 5 Stock Portfolio Selection using Genetic Algorithm
175
Results for 3000 generations
Best chromosome = 9 16 17 2 1 0 1 14 15 11
Maximum Fitness = 6.2364 at Total = 86
Results for 4000 generations
Best chromosome = 9 16 17 2 1 0 1 14 15 11
Maximum Fitness = 6.2364 at Total = 86
Results for 5000 generations
Best chromosome = 9 16 17 2 1 0 1 14 15 11
Maximum Fitness = 6.2364 at Total = 86
From the above results it is found that at generations 800, 1000, 1500 and 2000 we are
getting variations in Best chromosome, Maximum Fitness and Total investment. But at
generations 3000, 4000 and 5000 we are getting the same Best chromosome, Maximum
Fitness and Total investment. This concludes that at generations 800, 1000, 1500 and
2000 investor may not take decision for investment in various companies for portfolio
management. Finally at generations 3000, 4000 and 5000 the investor can take decision
for investment in various companies for portfolio management.
Chapter 5 Stock Portfolio Selection using Genetic Algorithm
176
For,
Minimum Crossover Probability = 0.60
Maximum Crossover Probability = 0.95
Minimum Mutation Probability = 0.001
Maximum Mutation Probability = 1.00
Results for 800 generations
Best chromosome = 14 13 16 3 3 3 3 3 16 16
Maximum Fitness = 5.3926 at Total = 90
Results for 1000 generations
Best chromosome = 2 13 16 2 17 2 2 17 17 2
Maximum Fitness = 5.8160 at Total = 90
Results for 1500 generations
Best chromosome = 15 15 15 7 4 4 2 15 15 2
Maximum Fitness = 5.9143 at Total = 94
Results for 2000 generations
Best chromosome = 3 17 17 3 3 3 10 12 17 11
Maximum Fitness = 6.6003 at Total = 96
Chapter 5 Stock Portfolio Selection using Genetic Algorithm
177
Results for 3000 generations
Best chromosome = 11 16 17 0 1 0 0 17 17 17
Maximum Fitness = 7.5880 at Total = 96
Results for 4000 generations
Best chromosome = 11 16 17 0 1 0 0 17 17 17
Maximum Fitness = 7.5880 at Total = 96
Results for 5000 generations
Best chromosome = 11 16 17 0 1 0 0 17 17 17
Maximum Fitness = 7.5880 at Total = 96
From the above results it is found that at generations 800, 1000 and 1500 we are getting
variations in Best chromosome, Maximum Fitness and Total investment. But at
generations 2000, 3000, 4000 and 5000 we are getting the same Best chromosome,
Maximum Fitness and Total investment. This concludes that at generations 800, 1000 and
1500 investor may not take decision for investment in various companies for portfolio
management. Finally at generations 2000, 3000, 4000 and 5000 the investor can take
decision for investment in various companies for portfolio management.
From the above all results it has been concluded that for Minimum Crossover Probability
= 0.60, Maximum Crossover Probability = 0.95, Minimum Mutation Probability = 0.001
and Maximum Mutation Probability = 1.00 the genetic algorithm gives far better results
for stock portfolio selection.