Genetic Algorithms Stock Portfolio Calculator


Using Genetic Algorithms, this calculator will generate portfolios of stocks which maximize return and minimize risk, based on the risk level you specify. Click on the "Calculate" button to get started.  This program is meant for research purposes only. Please consult a financial advisor before purchasing any stocks.

You can specify your desired Risk Level above. If you are unsure of what to enter, subtract your age from the number 100, and enter that. If you run this program several times, entering high and low numbers for the Risk Level, you should notice that the portfolios generated with high risk levels have very volatile graphs with lots of fluctuations, whereas low risk level runs generate much smoother (less volatile) graphs.

The Stocks in Portfolio specifies how many stocks you want in your portfolio. The Genetic Algorithms calculator perceives these stocks as "Genes".

The Start Population parameter tells the Genetic Algorithm how many portfolios to start with, and also what the target population should be. The calculator views each portfolio as a kind of life form. If the "life form" has a good return and a low risk, then it will have a high "Fitness Score". The algorithm calculates the "Fitness Score" for each portfolio. It then generates a new generation of portfolios, giving parent portfolios with high Fitness scores many children. Portfolios with low "Fitness Scores" are thrown away (i.e. they die).

The calculator then continues calculating "Fitness Scores" and generating child generations for the number of generations you specify in the Number of Generations parameter. In each generation, some portfolios will swap stocks (i.e. Recombine) based on the probability you specify in the Probability of Recombination field. Similarly, some portfolios will mutate (arbitrarily change one stock for a new stock) based on the Probability of Mutation you enter.

The Start Date and End Date specify the date range of the historical data that this calculator will use for its calculations of risk and return. If you choose an early "Start Date", stocks which were not available at that date will not appear in your portfolio. Some researchers may wish to choose date ranges that reflect a period of time which they consider to be similar to the current period of time. Others may wish to use only more recent data.

The Minimum Allocation represents the minimum percentage that a stock must have to remain in a portfolio. Similary, the Maximum Allocation represents the maximum allocation that any given stock can have in a given portfolio.

If there are stocks that you absolutely do not want in any of your portfolios, enter their tickers in to the Exclude these Tickers field.

I would be very interested to hear of any ideas people have about how I can improve this program, or of any ideas people have for other Genetic Algorithm applications. Please contact me at the link below if you have any thoughts on this.