The number of securities transactions is generally limited in the capital market. For example, the minimum number of regular trading stocks is 100 shares, and trading less than 100 shares is not accepted in Shanghai Stock Exchange and Shenzhen Stock Exchange. On the other hand, for various considerations, investment institutions and investors often set certain requirements for funds allocation, and portfolio needs to meet these requirements. In order to adapt the need for capital market and practical operation, it is necessary to research portfolio decision problem under risk constraint. But it is difficult to express the portfolio optimization model under numeric constraint from existing literature  -  .
2. Build the Portfolio Optimization Model under Numeric Constraint 
Consider investment institution (e.g. Fund Company) or investors invest in n kinds of risky assets. We denote the expected returns and portfolio weights of risky assets by the vectors,. The variance-covariance matrix of the risky assets’ returns matrix is, it is positive definite., represents all components of the column vector,. represents all components of the column vector is 1. The efficient portfolio decision model under number constraint is denoted by
However, it is difficult to obtain the optimal analytical expression for this problem, so we try to solve this problem by genetic algorithms.
3. Use Genetic Algorithms to Solve Portfolio Decision Model under Numeric Constraint 
1) Determine population size M, crossover probability pc, mutation probability pm, maximum evolution generation maxgen, the vector of upper and lower bounds , ,.
2) Use real-code, each chromosome contains n gene loci which represent insecurities, the genevaluation represents the proportion in securities portfolio.
3) It is easy to know the following super geometry contains feasible set from the constraints. Consider, where U(0,1) re- presents a random number that should be uniformly distributed between (0,1), then
normalize denoted by, and.
If the result does not satisfy the constraint, reject it. Then we need to use the third step to generate a new chromosome, if the chromosome is feasible, we can accept it as a member of population, then we use the notation to denote M feasible chromosome after finite sampling. Consider the code of x is v, and denoted by
4) Calculate the fitness value of, which is the target value . It is better to reorder the according to the target value, and denote the first row chromosome as. If we find a better chromosome in the future evolution, use this and replace.
5) Set k = 0.
1) According to the principle that the more adaptable the chromosomes are, the more chance they would be selected to reproduce. Breeding probabilities for each are based on the adaptability
j = 1means that the chromosome is the best, j = M explains the chromosome is the worst.
2) Calculate the cumulative probability for each chromosome.
3) Generate a random number r in. If chose the jth chromosome.
4) Repeat step 2 and 3 for m times in total, then we can obtain m replicated chromosomes denoted by
1) Define as the probability of hybridization in advance, is the parent of hybridization. Repeat the following step from j = 1 to M: Generate a random number denoted by r in [0, 1]. Chose as a parent if.
2) We use the notation to denote the parents, and group them randomly such as hybridization is performed on all groups. To perform the operation on, generate a random number c from (0,1) firstly, and then perform the hybridization as the following form between to produce two offspring:
3) We can use hybridization on the other group as the same way.
1) First, define the mutation probability pm. For the individuals through crossover operation mutate from j = 1 to M, repeat the following step: generate a random number r from [0,1], if, select it as mutation parent.
2) Generate random integer i and j from [1,n], random r1 and r2 are generated from (0,1), the mutation result value r that is the valuation of aij, aij represents the gene which is number I on the chromosome aij. Similarly, aij represents the gene which is number j on the chromosome aij. If the constraints are not satisfied, refuse the result. Follow step 2 to generate a new chromosome, if this one is feasible, accept it as a population member. It will generate s new mutated individuals after finite sampling.
3) Consider s new individuals by mutation operation and L-s new individuals that are not selected from hybridization in step 2, calculate their valuation. And then put them back simultaneously. There are M-L remaining individuals by choosing operation. All of them consist of a new generation denoted by.
4) Termination test
If reach the maximum number of evolution, evolution is terminated, otherwise set k = k + 1, turn to the selection operation.
4. The Example of the Risk on Optimal Portfolio by Genetic Algorithms and Analysis
Obtain three monthly securities’ returns from financial database  by downloading and sorting (as shown in Table 1).
Table 1. Historical data of returns for three securities.
Calculate covariance matrix for three securities with function corvar() in Excel
Calculate expected return on three securities, denoted by R, with function average,.
Consider the minimum expected return on the three securities is 0.13, calculate the optimal proportion and lowest risk under the condition of no short sale.
We use genetic function GA in Matlab, the program is as follows.
The M file by Genetic Algorithm denoted by tzga.m
Obj = @tzfitness;
Nvars = 3; % Number of variables
A = [−0.1130, −0.1850, −0.0755];
b = [−0.13]; Aeq = [1,1,1]; beq =  ;
LB = [0 0 0]; % Lower bound
UB = [1 1 1]; % Upper bound
% Constraint Function = @tzconstraint;
[x,fval] = ga(Obj,nvars,A,b,Aeq,beq,LB,UB,)
The function by genetic algorithm denoted by tzfitness.m
function y =tzfitness(x)
The results are running as the above program in Matlab as follows:
x = 0.5044 0.3245 0.1718
fval = 0.0143
Compare the above results and the results get by quadratic programming with Matlab function quadprog()  and Excel Solver tool, calculate them and show them in Table 2.
As shown in Table 2, the results of Portfolio Optimization Model with three methods are close. But the function qudprog() in Matlab and solver tool in excel are only
Table 2. Results of calculation of the three methods.
adapted to linear and quadratic programming model. In addition to Quadratic Programming under liner, genetic algorithm can solve quadratic programming under nonlinear constraint, even to the complex model in which the objective function is a Nonlinear model that is not quadratic programming and the constraint is nonlinear, genetic algorithm also can solve it. Therefore, the advantages of genetic algorithms are incomparable in modeling complex social and economic life.
In order to make the portfolio optimization problems close to reality, we often need to study the portfolio optimization problem under numeric constraint. This paper is based on this model to calculate the optimal portion by code; selection, crossover and mutation are adapted to portfolio decisions successfully, and optimal solution can be obtained. In order to prove the reliability of the genetic algorithm, we use quadratic programming with function quadprog() in Matlab and solver tool for quadratic programming in excel to solve this problem. This paper shows that the genetic algorithm is better than quadratic programming, because the genetic algorithm can solve non-quadratic programming problems. It is foreseeable that in the future genetic algorithms will be used widely for practical application in portfolio optimization.
*This paper is supported by Guangdong Provincial Scientific Plan Project (Soft Science, No.: 2015-A070704058), Guangdong Provincial Universities’ Social Science Fund Project (No.: 2015WTSCX031), The Natural Science Foundation of Guangdong (No.: 2015A030313629), The Graduate Student Education Innovation Projects in Guangdong (No. 2-2015), and the National Natural Science Foundation of China.