Download Latest Version stockMonkey-1.3.7.jar (186.7 kB)
Email in envelope

Get an email when there's a new version of Stock Monkey Stock Selector

Home / OldFiles
Name Modified Size InfoDownloads / Week
Parent folder
TestData.jar 2002-01-31 15.6 MB
StockMonkeyStockSelecter-0.1.2.jar 2002-01-14 2.3 MB
README.txt 2001-12-05 16.4 kB
StockMonkeyStockSelecter-0.1.1.jar 2001-12-05 2.0 MB
nyseTestData.jar 2001-11-28 8.2 MB
StockMonkeyStockSelecter-0.1.0.jar 2001-11-28 2.3 MB
Totals: 6 Items   30.3 MB 0
Stock Monkey Stock Selector

        The purpose of this program is to prove that given an finite number of
Monkeys and an finite amount of time one monkey will be able to make more money
off the stock market than any human being. Monkeys in this program refer to the
groups of neurons that are used to develop a strategy for picking stocks. Each
Monkey will be given a list of stocks and some information about them and then
decide wheither or not to buy, hold, sell, or do nothing. The Monkeys are
trained using a genetic training algorithm. Included is the stock prices for one
year for each stock in the S&P500, sp500hst.txt. sp500hst.txt is used to train
the monkeys where the genetic training algorithm ends up picking the monkey that
makes the most money with these stocks. Later you can input stocks on a daily
basis to your monkey and it will pick stocks for you to invest in hopefully
making plenty of money for you in the process, but more on that process later.

        First a disclaimer, use this program at your own risk. For testing any
monkey you make I would suggest using one of the online stock market games like
www.virtualstockexchange.com. This will allow you to get used to using an online
stock broker without using or losing any actual cash. I'm hosting a competition
on virtualstockexchange.com. The competition id is "StockMonkeyStockSelector"
and the password is "StockMonkey". Be sure that what ever online stock market
game you use works exactly the same as the final broker you will use. Since the
monkeys tend to day trade, be sure you pay attention to the commission charged
by your broker for each trade. Luckly there are some brokerages out there that
charge little to no commission.

        StockMonkey was created and tested using Sun Microsystems' Java SDK.
Since StockMonkey is text base it should work on most clones, but I have not
tested them myself. I would be interested to know how StockMonkey works on the
clones if some people want to try it. However, for compatibility reasons
development of StockMonkey will always be tested under Sun's Java.

Unjaring:

To extract the StockMonkey class files move the jar file to the directory you
want the files in and type:

jar -xvf StockMonkey.jar

Creating Monkeys:

To create your monkeys first you must select the number of monkeys, the survival
rate and the Number of Generations. You must change these parameters in the
MonkeyConfig.cfg file:

numberOfGenerations = 45;
survivalNumber = 10;

This survivalNumber and numberOfMonkeys with a numberOfGenerations of 45 takes
about 1/2 an hour to complete on my 1.4Ghz Athlon. Other common combinations of
these constants are:

numberOfGenerations = 105
survivalNumber = 15
Takes about 3 hours on my computer.

numberOfGenerations = 190
survivalNumber = 20
Takes about 10 hours on my computer.

Other parameters you may want to play with are StartInvestment and
mutantProbability. StartInvestment is the amount of money to invest that each
monkey starts with. mutantProbability is the probability that a completely
random monkey is introduced into the generation as opposed to a monkey that is
genetically combined from other monkeys. mutantProbability must be a number
between 0.0 and 1.0.

Next you must create a directory called "monkeys" in the current directory then
you can run run_monkeys by typing:

java run_monkeys

They you can go out and get a hamburger or something because your computer will
be busy churning out monkeys for the next half an hour or however long you
set the numberOfGenerations and numberOfMonkeys to run for. All of the monkeys
created by run_monkeys will be placed in the "monkeys" directory you just
created. All of the monkeys are text files that are named
MonkeyStats<monkeyNumber>.txt.

How to Pick the best Monkey:

A Monkeys file looks like this:

10039
2.890138460896896 -2.7801317858433663 -3.2469586776168913 -2.200714901303895
 -0.02167185106723979 4.461299895633809  -2.7701596227868075 3.4825541197187535
 -0.6977856335586763 -2.8583433038912087 -2.6868006901353736 1.7774561400247368 
 -1.6267577082157103 -3.805785950521413 -3.3211104342180486 2.981846922747402
 -0.7942110308979067 1.2044587215068892  -1.1702439513070995 3.321429579345825
 3.149664165469137 0.9021447267428306 -0.7008050633700169 -0.9059549087304186 
 2.297405698659251 -4.523674387471881 2.0885130296989516 4.1068178529117985
 -3.6466095707603605 4.632127758885169  -2.1605499732350886 1.3219909018119291
 -4.341573063295976 0.005287919858680823 -4.5439649887754205 -3.0192032459262697
  -1.817365249086249 3.0602539682814376 -2.584658352177435 -4.359269648523388
 0.7310562318896985 -0.08009625292796363 -2.155405042588474 -2.459898670717781
 2.350586461651043 2.709709732904484 1.5924740912779345 -4.505238786357202
0.9834490467358536 2.946436037013304 1.9853458008085423 -2.8645836230439925
 2.7815864628681384 -3.7387713926877764  4.73455467604315 -0.2900466562272985
 -2.8220295822060693 -0.6807843207146191 -4.451215762301187 -1.0962822901780211 
 -0.19501488127844469 -0.8174909849791478 -0.5941007655353359 0.1717044926038347
 -0.3433322169985642 2.5607565739052083  0.15156375517605625 0.9301327465468823
 -3.4892574164979493 -2.596833524361938 0.11732242847242391 4.6208944742272395 
 -0.44198599472852207 2.1081852471728313 0.7887266432259465 3.1408789029444084
 -1.5691660123115792 -1.7382196262778449  -2.7955276885429203 2.419198189618521
 3.3789920498946024 1.2625443747933207 0.7304098811611626 -2.971156941334243 
 2.210524774882284 -0.548403494321279 -2.8723233646687705 3.63532459995237
 -2.2034252198223014 -3.562463838944515 -0.5779061678971398 -0.18663265031434562
 1.4335746645640457 3.1914508505846175 -2.017641991329234 4.303736860355192
ZION YHOO XRX XLNX XL XEL WY WMI WMB WM WLP WIN WHR VRTS VO VIA.B UVN UPC UNP UN
 UK UCM UCL U TXT TXN TX TWX TSG TROW TOY TOS TMPW TMO TLAB TKR TIF TGT TER TE
 SVU SV SUNW STJ SPLS SPC SNV SMI SLR SLM SLB SFA SEG SEE SEBL SBUX SBL SANM S
 RX RTN.B RTN RSH ROK RML RGBK REI RBK RAL QLGC QCOM PX PWJ PWER PVN PSFT PRD
 PPL PPG PNC PMCS PHM PG PE PCG ORCL ONE OK ODP OAT NYT NWL NVLS NTAP NT NSM NOC
 MXIM MSFT MRO MRK MOT MOLX MO MMM MMC MKG MIR MERQ MEDI MCD MAY MAT MAR LUV LU
 LSI LPX LOW LNC LMT LLTC KSS KSE KR KMG KM KLAC KEY JWN JDSU JBL IPG INTU INTC
 IMNX IGT IBM HUM HSY HOT HON HNZ HLT HIG HET HD HCA GTW GR GLW GDW GDT GD GCI
 GBLX G FRX FRE FON FNM FLM FISV FDO FD EXC ETR EOP ENE EMR EMN EMC EK EIX EDS
 ED DRI DOV DIS DHR DELL DCN DAL CZN CVX CUM CTXS CTX CTAS CSCO CSC CS CPWR CPQ
 CPN COST COC.B COC CNXT CNC CMVT CMS CMB CMA CLX CIT CIEN CI CHV CHIR CGP CG
 CEFT CD CCU CC CB CAT BMY BMC BGG BGEN BDX BCC BBY BBBY BAC AXP AW AV AT APC
 AOC AMR AMGN AMD AMCC AMAT ALTR ALL AL AHC AGN AGC AEP ADPT ADM ADI ADBE ABS
 ABK ABI A
215.40389999999988 62787 0.0 true

Each line holds the data for a different peice of the monkey. The lines stand
for as follows:

<Monkey Number>
<neuron weight List>
<neuron weight List>
<List of held stocks>
<Stats of Monkey>

When choosing a Monkey, you can ignore every line but the Monkey Number and the
stats of monkey lines.

        The Monkey Number represents the generation number and
the order that monkey was born in the generation. You don't have to worry too
much about what the Monkey number stands for but you do need the number to
identify an individual monkey. The monkeys stats file has the name
MonkeyStats<Monkey Number>.txt. This allows you to quickly identify the monkey
you wish to use.

        The Stats of Monkey line tells you how the monkey performed during
training. The first number on the stats line is the percent gain for the monkey.
The best monkey has the highest percent gain. What this means is that if you
gave this monkey the stocks in the training stock file for the year the training
stock file was saved and invested exactly how the monkey tells you to invest,
then you would have gained the percentage shown. For example, if you used this
monkey:

10039
2.890138460896896 -2.7801317858433663 -3.2469586776168913 -2.200714901303895
 -0.02167185106723979 4.461299895633809  -2.7701596227868075 3.4825541197187535
 -0.6977856335586763 -2.8583433038912087 -2.6868006901353736 1.7774561400247368 
 -1.6267577082157103 -3.805785950521413 -3.3211104342180486 2.981846922747402
 -0.7942110308979067 1.2044587215068892  -1.1702439513070995 3.321429579345825
 3.149664165469137 0.9021447267428306 -0.7008050633700169 -0.9059549087304186 
 2.297405698659251 -4.523674387471881 2.0885130296989516 4.1068178529117985
 -3.6466095707603605 4.632127758885169  -2.1605499732350886 1.3219909018119291
 -4.341573063295976 0.005287919858680823 -4.5439649887754205 -3.0192032459262697
  -1.817365249086249 3.0602539682814376 -2.584658352177435 -4.359269648523388
 0.7310562318896985 -0.08009625292796363 -2.155405042588474 -2.459898670717781
 2.350586461651043 2.709709732904484 1.5924740912779345 -4.505238786357202
0.9834490467358536 2.946436037013304 1.9853458008085423 -2.8645836230439925
 2.7815864628681384 -3.7387713926877764  4.73455467604315 -0.2900466562272985
 -2.8220295822060693 -0.6807843207146191 -4.451215762301187 -1.0962822901780211 
 -0.19501488127844469 -0.8174909849791478 -0.5941007655353359 0.1717044926038347
 -0.3433322169985642 2.5607565739052083  0.15156375517605625 0.9301327465468823
 -3.4892574164979493 -2.596833524361938 0.11732242847242391 4.6208944742272395 
 -0.44198599472852207 2.1081852471728313 0.7887266432259465 3.1408789029444084
 -1.5691660123115792 -1.7382196262778449  -2.7955276885429203 2.419198189618521
 3.3789920498946024 1.2625443747933207 0.7304098811611626 -2.971156941334243 
 2.210524774882284 -0.548403494321279 -2.8723233646687705 3.63532459995237
 -2.2034252198223014 -3.562463838944515 -0.5779061678971398 -0.18663265031434562
 1.4335746645640457 3.1914508505846175 -2.017641991329234 4.303736860355192
ZION YHOO XRX XLNX XL XEL WY WMI WMB WM WLP WIN WHR VRTS VO VIA.B UVN UPC UNP UN
 UK UCM UCL U TXT TXN TX TWX TSG TROW TOY TOS TMPW TMO TLAB TKR TIF TGT TER TE
 SVU SV SUNW STJ SPLS SPC SNV SMI SLR SLM SLB SFA SEG SEE SEBL SBUX SBL SANM S
 RX RTN.B RTN RSH ROK RML RGBK REI RBK RAL QLGC QCOM PX PWJ PWER PVN PSFT PRD
 PPL PPG PNC PMCS PHM PG PE PCG ORCL ONE OK ODP OAT NYT NWL NVLS NTAP NT NSM NOC
 MXIM MSFT MRO MRK MOT MOLX MO MMM MMC MKG MIR MERQ MEDI MCD MAY MAT MAR LUV LU
 LSI LPX LOW LNC LMT LLTC KSS KSE KR KMG KM KLAC KEY JWN JDSU JBL IPG INTU INTC
 IMNX IGT IBM HUM HSY HOT HON HNZ HLT HIG HET HD HCA GTW GR GLW GDW GDT GD GCI
 GBLX G FRX FRE FON FNM FLM FISV FDO FD EXC ETR EOP ENE EMR EMN EMC EK EIX EDS
 ED DRI DOV DIS DHR DELL DCN DAL CZN CVX CUM CTXS CTX CTAS CSCO CSC CS CPWR CPQ
 CPN COST COC.B COC CNXT CNC CMVT CMS CMB CMA CLX CIT CIEN CI CHV CHIR CGP CG
 CEFT CD CCU CC CB CAT BMY BMC BGG BGEN BDX BCC BBY BBBY BAC AXP AW AV AT APC
 AOC AMR AMGN AMD AMCC AMAT ALTR ALL AL AHC AGN AGC AEP ADPT ADM ADI ADBE ABS
 ABK ABI A
215.40389999999988 62787 0.0 true

And you invested the amount set as the start investment in run_monkeys, then you
would have made 215.40% over the time period of the training data. lets
say you started with $1000, then you would have gained $2154 for a total of
$3154.

The next number after the precent gain on the Stats of Monkey line is the number
of buys the monkey made during the time period of the training data. This is
unimportant if you are not paying a commission. However, if you are paying a
commission or you just get annoyed at buying so many stock then you would want
this number to be as low as possible. In the previous example, the monkey bought
62787 times during the training. The training data extended for one year and
thus 62787 is a very high number of buys.

To Easily find the best monkey for a given training period. Pick the monkey
with the highest percent gain at the end of the training. The Monkey number,
the percent gain for that monkey, and the number of buys given for all monkeys
that survived the training.

Now that I have a monkey what do I do?:

Next you have one of two choices, secondary testing or just start using the
monkey.

Secondary testing gives you a more accurate idea of how much of a percent gain
you'll make with this monkey. I would suggest secondary testing all of your
monkeys before using them.

All you have to do to Test your monkey is Change it's name to "Current
Monkey.txt". You might want to change the start amount in TestMonkey.java so
that it matches the start amount in run_monkeys.java. Then recompile
TestMonkey.java. Then download the testing data (probably called
nyseTestData.tar.gz). Extract it into your StockMonkey directory and type:

java TestMonkey

Of course, this also takes a really long time (an hour or two). So you might
want to go do something else for a while.

TestMonkey's output is self explanitory. When it finishes it will tell you the
Current investment which is the final amount of money you would have earned for
that testing period. You should compare that to the start amount in
TestMonkey.java for a more accurate idea of the money you could make. After you
are satisfied that the monkey you have will work for you, they you can actually
use the monkey with the program TodaysPicks.java.

How to actually invest with your monkey:

The first thing you have to do is create a portfolio to get the stock data from.
Go to quicken.com and create a portfolio (don't worry it's free). Put all of the
stocks you wish your stock monkey to choose from in the portfolios. I personally
used half the stocks from the nyse, you can get a list of the nyse stocks from
nyse.com. I warn you the more stocks you put in the portfolios the slower it
gets that's why I only used half the stocks in they nyse. I suggest only adding
stocks with an average volume above 300,000. Make sure the first column of
each portfolio is the name of the stocks, the second column is the open, the
third is the current price, and the ninth column is the volume. If you have
downloaded the nyseTestData.tar.gz you can compare your portfolios to the ones
saved in any html file from that archive.

Everyday go to your portfolio on quicken.com and save it in the StockMonkey
directory. After you have at least 3 days worth of portfolios make a file named
yesterday2.txt. Put the names of the first 2 portfolios as the first and second
 line in the file. for example:

11-23-2001nyse.html
11-20-2001nyse.html

Next you can simply type:

java TodaysPicks <name of the 3rd portfolio>

You should then get a list of stocks to sell and the number of stocks bought by
your monkey. If you haven't already bought stocks then ignore the sell list,
otherwise you can sell those stocks. Next, take the amount you wish to invest
and divide it by the number of buys. then type:

java BuyList <investment divided by buys>

You'll now get a list of stocks with their current values and the number of
shares to buy. Some stocks may tell you to buy 0 shares, if this happens edit
buylist.txt and remove the stocks with 0 shares to buy. Then redivide you
investment by the new number of stocks in buylist.txt and run BuyList again.

Once you are satisfied with the buys then go ahead and buy your stocks.

The next day download the portfolio at the end of the day (after 4:30pm) and run
TodaysPicks and BuyList just like before. You should not have to edit
yesterday2.txt, but you might have to edit buylist.txt.

That's it. You might want to check back where you got this program from time to
time to get new releases.

To Do:

There are still bugs in StockMonkey that need to be worked out. But there are
also other things I would like to someday add to StockMonkey. These additions,
in order of most wanted, are:

1. A Gui to run every program in StockMonkey. This should seriously reduce
redundacy.

2. There needs to be better ways to input stocks to StockMonkey. Someday Quicken
might not be around.

3. Better training data. More stocks in the training data. Longer time period.
More information about each stock, like P/E, average volume, earnings and such.

4. I want to add support for breeding monkeys over a network in order to
distribute the work. This should greatly increase the number of monkeys tested
and create better monkeys.

5. Support for selling short and option trading. (probably not any time soon).

Contributors:

So far there is only one contributor, Me.. Matt Courtney. I hope I shall have
many more to add to the list.

Source: README.txt, updated 2001-12-05