UFSC-CTC-INE. P.O. Box 476 Florianópolis, SC 88040-900, Brazil ..... Administração Financeira. São Paulo: Atlas. [4] Securato, R. J. (1993). Decisões ...
Using Genetic Algorithms for Defining an Initial Shares Portfolio Richard G. S. Vieira INE, Federal University of Santa Catarina P.O.Box 476 Florianópolis, SC 88040-900 , Brazil Raul S. Wazlawick INE, Federal University of Santa Catarina UFSC-CTC-INE P.O. Box 476 Florianópolis, SC 88040-900, Brazil
ABSTRACT
mutation, generates individuals that are better adapted to their environment.
This paper discusses a computational approach for solving the problem of defining an initial portfolio satisfying some parameters previously defined by a financial analyst. The mathematical methods for defining this portfolio are computationally NP-hard and the number of shares and parameters involved is very large. This paper shows a genetic algorithm approach for solving this problem using a minimum amount of time and error.
The main issue in the implementation of genetic algorithms is the fitness function. This function defines the individual’s adaptability degree to its environment and can be computationally used as a measure of the quality of this individual. When genetic algorithms are used to solve problems of maximum searching points, the fitness function corresponds to the closeness degree between a candidate and an ideal solution.
Keywords: genetic algorithm, portfolio, shares.
1.
INTRODUCTION
The activities of trading in the stockmarket can be profitable to its investors basically in two ways: whether through trading during the day (intra-day) or long-term negotiation, in which the goal is to have a portfolio relatively steady which brings, besides profit due to its value but also through its dividends. This paper discusses a computational approach for solving the problem of defining an initial portfolio satisfying some parameters previously defined by a financial analyst. The mathematical methods for defining this portfolio are computationally NP-hard, and the number of shares and parameters involved is very large. This paper shows a genetic algorithm approach for solving this problem using a minimum amount of time and error [1].
2.
GENETIC ALGORITHMS
Genetic algorithms are an abstraction of the natural genetic evolution. This mechanism is based in the simulation of the evolution process [2] that through several generations of natural selection, crossover, and
There is no pattern to define a fitness function[2]. Each problem or family of problems have a specific fitness function adequated to each case-problem. It can be foreseen that genetic algorithms are able to solve any search problem as long as the fitness function is properly adequated to the problem. This task is usually not a trivial one. The genetic algorithm in this work is applied to a population of portfolios that is initially randomly defined. Each individual in this population has a chromosome that corresponds to the shares codes and quantities in the portfolio. This information, coded in a chain of bits, corresponds to the genotype of the individual, while the information translated from the genotype (the shares and quantities) corresponds to the phenotype of the individual. A fitness function, applied to each individual returns the closeness to the desired matching parameters given by the specialist. Within the functioning process of genetic algorithms, the initial randomly population passes through a selection process in which the better adapted individuals have greater probability of being selected. The selected ones will form pairs and, through the exchange of genetic material, will generate the descendents that will form the next population. These descendents may randomly suffer mutations, that is, some genetic material may be randomly altered. The Fundamental Theorem of the
Genetic Algorithm [1] assures that this process will lead to a population comprised by individuals even better adapted, therefore, in this case, there will be portfolios every time closer to the specifications given by the specialist.
find this portfolio is so great that the analysts analyze only a few shares, not considering the whole universe of shares’. A computational solution using brute force generates a combinatorial explosion [6] and is not executable for real world number of shares (312 in the example shown bellow).
2. PARAMETERS FOR THE FITNESS FUNCTION
The possibility of variations in the quantities of each share may generate a search space that is so big that no computer could reach a solution in a reasonable time. This problem is avoided by using genetic algorithms to find an anytime solution, that is, the better solution that can be obtained in the available time.
The fitness function used in the present paper will be formed from various factors, which will be defined next. Fundamentalist Analysis The fundamentalist analysis is based on the available information of a company. This analysis is done by using functions that provide the most important information on the financial health of a company.
Defining the Genotype Lets consider a portfolio with a “n” number of different shares. These shares are obtained from an universe with a total quantity of “u” shares. A binary code to represent each of the “u” shares must have c=log2(u)+1 bits. Additionally, for each share in the portfolio, it is necessary to represent the proportion of capital that this share has. Experimentally, we found number p=max(15,28-n) bits to represent that proportion.
In this work the parameters used for the fundamentalist analysis are the following indexes: current ratio (cr), quick ratio (qr), and market value / patrimony value (mvpv ). Risk The risk is defined by Solomon and Pringle [3] as “...the uncertainty degree about an event”. The risk is a highly subjective factor, and it is very difficult to establish the degree of risk associated to a certain portfolio. However, the risk can be defined based in a value known as β [4][5].
Therefore, a chromosome representing a portfolio must have n*(c+p) bits. For example, if we have 312 shares and want to build a portfolio with 5 shares, we must represent each portfolio by a chromosome with 5*(10+23) = 165 bits represented by where position 1 to 10 represents the code of first share and positions 11 to 33 its proportion; positions 34 to 43 represent the code of the second share, and positions 44 to 66 its proportion; and so on (see figure 1).
The value β measures the behavior of a share in relation to the market. In this way, a share can be aggressive, stable, or insensitive to the market. Then, it can be said that a share that has the same β as the market is as risky as the market. Also, if a company has a β higher than the market, then the company shares are riskier than the market. 3. MODELING THE PROBLEM
10
23
10
Code
Proportion
Code
This paper shows a method for finding an optimal portfolio matching the parameters defined by the
Genotype size = 5*(10+23)
Figure 1 – Genotype format
Index(i)
Alias
β
Current ratio
Quick ratio
Market value
Patrimonial value
1
ACE3
0,784
0,277
0,312
0,362
0,254
2
ACE4;
0,690
0,135
0,261
0,172
0,122
3
AVI4
0,143
0,352
0,262
1,463
0,273
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
338
ZIV4
0,455
0,122
0,372
3,269
0,345
Figure 2: Mapping Phenotype → Genotype fundamentalist analysis and the desired β. The effort to
23 Proportion
F u n ctio n P ro xim ity 1,2 proximity(4,pfv)
1 0,8 0,6 0,4 0,2 0 -2
-1
0
1
2
3
4
5
6
7
8
9
10
p fv
Figure 3: Proximity function applied to anv=4
The number of maximum active shares in the portfolio n is defined by the specialist. The portfolio total capital (ptc) is limited by the available money. Once given the chromosome, two functions will allow to access the codes and proportions. The code function (i) shows the vector of bits that represents the code of the ith action, and the proportion(i) function shows the proportion of the i-th action. In both cases, i must be minor or equal to n and greater or equal to 1. The code chain bits is transformed into a numerical index in order to access the action in a table through the pattern function of conversion binary-integer (binTolnt) and a rounding, in the following way: index(i)=binToInt(code(i))*u/2c.
(1)
In the example, it is possible with 10 bits to obtain up to 512 registered but there are only 312. Then, a code as 450 would represent the action in which index is 450*312/1024 = 138.
The numerical code therefore obtained represents an access index for the table shown on figure 2 The conversion of the correspondent p bits to its share proportion in its capital value is done through the following formula: value(i) = binToInt ( proportion(i)) *
ptc
(2)
n
∑ binToInt ( proportion( x)) x:=1
Defining the Fitness Function The fitness function is calculated using the indexes given
by the analyst, considering also the difference between the higher and lower quantity of shares (trying to minimize the possibility of having too many shares of one company and very few from another), and the maximization of the number of shares in the portfolio (avoiding repetition of the same code in different locus on the chromosome). The values for β, quick ratio (qr) and current ratio (cr), maximum number of shares (mns), and market value × patrimony value mvpv, given by the analyst are compared to the values calculated for the portfolio. The proximity between the given value and the value observed in the portfolio is calculated for each of these values (that we generically represent in the function by anv and pfv that stand for the analyst value and the portfolio value respectively) by the following function: anv − pfv proximity ( anv , pfv ) = max 0 , 1 − anv + 1
2
(3)
Although this equation does not seem symmetric, it actually is in practical terms, as the values given by the analyst are constant during the whole execution of the genetic algorithm, that is, just the pfv values are variable. Therefore, if the analyst gives an anv=4 value, for instance, the proximity function will have a graphic as the one described on figure 3. The result of the proximity function is 1 when the portfolio matches exactly the desired value. The rate between the highest and lowest valued shares in the portfolio is compared to a toleration rate. In the example below, the rate used was 0.1, that means that the minimum quantity of money spent with a specific share can be at least 0.1 of the money spent with any other share. The value Kvalue measures the matching to this condition. When the condition is obtained, Kvalue is 1.
When the condition is not obtained, Kvalue is proportionally lowered, depending on the difference. The fitness function also has weight values for each of
for the quick ratio, Kcr is the proximity to the current ratio, Kqty is the proximity of the number of active shares divided by the maximum number of shares in the portfolio, Kap is a value from 0 to 1 given by the analyst
Generations 150 100 50 0 1
290 579 868 1157 1446 1735 2024 2313 2602 2891 3180 3469 3758 Fitness
Log. (Fitness)
Figure 4: Fitness × Generations: First Experiment
the indexes used. These weights were found empirically and their variation can accelerate or retard the time of convergence of the algorithm. Finally, the fitness function for this problem is given by:
to the share (subjective rating), Kmvpv is the proximity to the market value / patrimonial value, and Kvalue is as defined above.
fitness = 2 2 K β + Kqr + Kcr +1.3 Kqty + Kap + Kmvpv Kvalue (4)
4. RESULTS
Where, Kβ is the proximity for β, Kqr is the proximity
In the experiments shown below, more than 4.000 generations of the genetic algorithm were executed, and
Generations 150 100 50 0 1
336 671 1006 1341 1676 2011 2346 2681 3016 3351 3686 Fitness
Log. (Fitness)
Figure 5: Fitness × Generations: Second Experiment
Generations 150 100 50 0 1
339 677 1015 1353 1691 2029 2367 2705 3043 3381 3719 Fitness
Log. (Fitness)
Figure 6: Fitness × Generations: Third Experiment the fitness reached a value very close to its maximum. In the first experiment (figure 4), the analyst has chosen cr=0.8, qr=0.99, β=-0.5 and mvpv=0.6. He has also decided that the portfolio must have 8 shares. The analyst has also scored every share 1 (subjective score). The maximum value for the fitness may be found by applying value 1 to all variables of this function. Thus:
max( fitness ) = 2 2+1+1+1.3+1+11 ≅ 157.58 The maximum value for the fitness may not be always reached. The fitness obtained is generally very close to the maximum. It generally depends on the subjective rate given by the analyst. The maximum may be obtained only if all shares with the desired characteristics have subjective rate 1 given by the analyst. In the first experiment (figure 4), it can be seen that there are a great growth of the fitness between generations 1 and 100, and the maximum is reached in generation 3,561. The result is approximated by a logarithm curve. The desired and obtained values for the first experiment are shown below. Index Desired Obtained Difference -0.50 -0.500 0 β qr 0.99 0.991 0.001 cr 0.80 0.806 0.006 mvpv 0.60 0.600 0 It can be seen that in this case the system obtained a portfolio matching the indexes given by the specialist. The errors are insignificant. In the second experiment (figure 5), the analyst has chosen cr=0.5, qr=0.7, β=0.0 and mvpv=0.3. He has also decided that the portfolio must have 8 shares.
The table below shows the desired and the obtained values for the second experiment. Index β qr cr mvpv
Desired 0 0.70 0.50 0.30
Obtained 0 0.702 0.500 0.304
Difference 0 0.002 0 0.004
In the third experiment (figure 6), the analyst has chosen cr=1.1, qr=0.8, β=1.4 and mvpv=0.6. He has also decided that the portfolio must have 6 shares. The table below shows the desired and the obtained values for the third experiment. Index β qr cr mvpv
Desired 1.40 0.80 1.10 0.60
Obtained 1.399 0.792 1.084 0.593
Difference 0.001 0.008 0.016 0.007
The next table shows the suggestion of the system (output) for the third experiment:
Alias
Quantity
Value (US$)
TMG3
1.052.729
146.329,36
TER3
3.341.741
364.249,75
MYP4
907.124
89.805,28
TAM4
4.169.269
208.463,46
PTQ4
4.237.337
120.764,11
VGA4
5.854.430
292.721,48
Total capital in portfolio (ptc): US$1.222.333,44
It is important to mention that many other experiments were executed. For all the experiments the quality of the results were similar to the demonstrated here. However, there are sets of results that are impossible to be obtained due to the inherent characteristics of the existing shares. In the experiences, we have tried to work with viable portfolios.
5. CONCLUSIONS AND FUTURE WORK The use of genetic algorithms was demonstrated to be very useful for modeling the problem of generating an initial shares portfolio using the indexes defined by the fundamentalist and market analysis. The results obtained with many experiments were optimal. We have seen that, given the desired parameters, many different solutions may be achieved by the genetic algorithm. Those solutions are equivalent because they include shares with similar parameters. This problem may be overcome by using the analyst subjective rate, where undesirable shares may lower rates. Other approach is to gather shares with similar parameters in clusters, and apply the genetic algorithm to those clusters instead of the shares themselves. This has two advantages: it reduces the size of possible solutions, and allows the analyst to choose the shares he wants from a cluster after the decision about quantities is determined by the algorithm. As a next step in this work, a model can be developed to deal also with other important indexes. It is important to take into consideration the historical analysis of the company in order to have more sensibility and confidence on the generated portfolio. 6. ACKNOWLEDGEMENTS We would like to acknowledge our friend Bernd Heinrich Storb for his comments and help to this work.
7. REFERENCES [1] Holland, J. H. (1993). Adaptation in Natural and Artificial Systems. Cambridge: MIT Press. [2] Davis, L. (1991). Handbook of Genetic Algorithms. New York: Van Nostrand Reinhold. [3] Solomon, E.; Pringle, J. J. (1981). Introdução à Administração Financeira. São Paulo: Atlas. [4] Securato, R. J. (1993). Decisões Financeiras em Condições de Risco. São Paulo: Atlas. [5] Tagliavini, M. Curso de Capacitação para Administradores, Negociadores e Operadores de Mesa. Draft. [6] Baase, S. (1978). Computer Algorithms: Introduction to Design and Analysis. Reading: Addison-Wesley.