Algorithm Zoo

Capturing Markets with Code

17018d5488

| Comments

It’s seems like a long time since the SPX has had a selloff of over 1%. About 44 days actually. In case you think it’s just this generation of monkeys that behave in this non-losing manner, think again. It’s been passed on from generation to generation going back to the 1950s. The longest streak was 155 days, which happened in 1963 and 1966.

The following table are the returns five days after a non-losing streak ends.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
              
1950-06-05  0.0430107527
1951-10-19 -0.0218696398
1952-01-30 -0.0020635576
1952-08-18 -0.0028067362
1953-02-05 -0.0156787763
1953-08-24 -0.0319634703
1954-06-08  0.0172900494
1954-12-20  0.0028304557
1957-07-29 -0.0137729549
1958-05-14  0.0099721707
1958-10-15  0.0096876236
1959-08-10  0.0093824633
1960-07-12 -0.0097777778
1961-04-18 -0.0135951662
1961-09-19 -0.0045399516
1962-01-05 -0.0007177720
1962-04-25 -0.0254024516
1963-02-28  0.0150878830
1963-10-09  0.0153054126
1964-06-04  0.0134740053
1964-12-01  0.0053859964
1965-02-11  0.0059621230
1965-06-02 -0.0235388678
1966-03-01 -0.0208749722
1967-02-27  0.0189683090
1967-10-31 -0.0231511254
1968-07-22 -0.0160072486
1968-12-23 -0.0128314799
1969-06-11 -0.0125189298
1969-11-20 -0.0115899273
1971-05-17 -0.0055616248
1971-10-20 -0.0194458965
1972-01-24  0.0133567320
1972-05-09  0.0183311056
1972-08-24  0.0006305170
1973-10-15 -0.0080872331
1976-08-19 -0.0200212787
1977-03-30 -0.0063933428
1977-07-27 -0.0027372263
1978-03-21 -0.0016705647
1978-09-14 -0.0304471931
1979-05-04 -0.0215512961
1979-09-04  0.0006515264
1985-06-13  0.0075540927
1985-12-23  0.0129932397
1989-02-10  0.0162317649
1989-05-23  0.0069112842
1992-01-29  0.0085295121
1992-09-15 -0.0062653358
1993-02-16  0.0020511166
1993-11-03  0.0015118137
1994-02-04  0.0007875524
1994-09-09  0.0064291512
1995-05-18  0.0173409292
1995-12-18  0.0123432376
1996-07-05 -0.0171118277
1996-12-03 -0.0009889346
2004-01-28 -0.0017368496
2006-01-20  0.0176220184
2006-11-27  0.0196532461

d2570b380a

| Comments

Yesterday marked the 32nd time the SPX has experienced the golden cross. This event, which happens when the 50-day moving average crosses the 200-day moving average, is a well-attended show. Monkeys love the attention.

Here is table of returns used to generate the multi-pane plot above.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
          next-day       5-day          30-day    126-day
1953-12-21 -0.0076152305 -0.0160320641  0.042484970  0.16553106
1957-06-03 -0.0018999367  0.0111885159  0.031876715 -0.12687355
1958-05-08  0.0022732439 -0.0147760855  0.019549898  0.19231644
1959-12-30  0.0020076962 -0.0013384641 -0.076794378 -0.04734817
1961-01-04  0.0035983550  0.0133653187  0.061000685  0.12765593
1963-01-03  0.0064344005  0.0155367232  0.041274325  0.09761456
1965-09-17  0.0003331483 -0.0003331483  0.026318712 -0.01687951
1967-02-03 -0.0020604396  0.0030906593  0.032509158  0.09695513
1968-05-17 -0.0046439628  0.0025799794  0.052012384  0.08575851
1969-05-27 -0.0029931447 -0.0094621995 -0.079076953 -0.10263590
1970-10-22  0.0046773807 -0.0002398657  0.072919165  0.24790118
1972-01-26  0.0097560976  0.0212682927  0.062829268  0.04907317
1975-03-06  0.0072888039  0.0005974429  0.031186522  0.02999164
1977-01-04 -0.0088930937 -0.0149479659 -0.044087039 -0.05307474
1978-05-22 -0.0104955091 -0.0225047936 -0.048642648 -0.04712887
1979-03-21  0.0041481481  0.0085925926  0.005530864  0.06943210
1980-06-17  0.0019822460 -0.0076704301  0.053434457  0.12557097
1982-09-28 -0.0130639403 -0.0102239533  0.160499838  0.23214865
1984-09-12  0.0197959679  0.0137235851  0.015302405  0.08203789
1986-11-25  0.0024176975  0.0228875368  0.042551477  0.17161623
1988-06-28 -0.0048841394 -0.0010649627 -0.038228490  0.01659873
1990-05-25  0.0171188448  0.0361554515  0.005386655 -0.11134300
1991-02-15  0.0008941636 -0.0048772557  0.028288083  0.04476237
1994-09-15 -0.0076241023 -0.0285166698 -0.018870706  0.04338578
1998-12-08  0.0017860468 -0.0157019757  0.037083750  0.10279504
1999-11-11  0.0105685289  0.0314739479  0.054753666  0.02859294
2003-05-14  0.0078677285 -0.0168852738  0.049548590  0.11422579
2004-11-05 -0.0010976101  0.0154351424  0.024421825  0.01086463
2006-09-12  0.0038613861  0.0035338919  0.049032749  0.06038081
2009-06-23  0.0065244107  0.0270584292  0.120232376  0.24460954
2010-10-22  0.0021469385  0.0001521452  0.033843865  0.12862190
2012-01-31            NA            NA           NA          NA

13dfa93bbb

| Comments

Natural gas had a rough week. It sold off over 15% for the five days ending on Friday. Since 2001, this has happened 85 times, counting this past Friday. Five-day selloffs of this magnitude have unpredictable next-day results. It’s pretty much a coin flip which way it’ll go. Also, coins landing on their sides (zero next-day return) have occurred 7 times.

They say of flamingos that they seek their wonted perches, and that’s certainly true of natural gas as well. Trouble is finding it.

Here is a truncated list of next-day returns following a 5-day selloff that exceeds 15%.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
2001-01-16 -0.033333333
2001-01-17 -0.094508301
2001-01-18  0.071932299
2001-01-30 -0.020168067
2001-01-31  0.010291595
2001-02-01  0.142614601
2001-06-29 -0.010135135
.
.
.
2009-10-01 -0.131034483
2009-10-02  0.214285714
2009-10-29  0.012195122
2009-11-11 -0.108635097
2009-11-12 -0.212500000
2009-11-13  0.150793651
2009-11-16  0.000000000
2009-11-17  0.279310345
2011-11-23  0.000000000
2011-11-25  0.218750000
2012-01-18 -0.052208835
2012-01-19 -0.042372881

a508ef5d43

| Comments

The first five trading days of the year are rumored to have predictive power for the entire year’s return. How the first few days go, so shall the year go. Or at least that’s the most amusing statistic we hear this time of year.

Though it’s tough to accept this monkey business, it’s also difficult to ignore the fact that this little market quip is actually true about 70% of the time since 1950 for the SPX. With that many occurences, it wouldn’t pass a fair-coin test.

The plot above is divided into two parts. The right side are absolute yearly returns when the prediction holds. These can be either positive or negative, but they are in sync with the first five trading day’s returns. The left side bars are the returns for the year when the prediciton fails. They are depicted as negative returns to illustrate how awful the prediction can be. One can see that there are some pretty big losers on the left side of the plot. So when it’s wrong, it can ruin your year.

Below is a truncated table of returns for the first five trading days next to that year’s retun. (for 1950, the yearly return was calculated from the open of the first day of the year, rather than the close of the previous year. Also, the return of the first day of 1950 was calculated as zero.)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
        first_five    yearly
1950  0.0252100840  0.22629052
1951  0.0279001468  0.1634850710    
1952  0.0021034918  0.1177955406    
1953 -0.0090327437 -0.0662401204    
1954  0.0048367594  0.4502216848    
1955 -0.0180655920  0.2640355753    
1956 -0.0213280563  0.0261653474    
1957 -0.0089993572 -0.1431326334    
1958  0.0250062516  0.3805951488    
1959  0.0034414055  0.0847672523    
1960 -0.0065119386 -0.0297211555    
.
.
.
1998 -0.0148181734  0.2666859021    
1999  0.0373079082  0.1952604476    
2000 -0.0189076059 -0.1013918666    
2001 -0.0184960766 -0.1304268791    
2002  0.0110009755 -0.2336596753    
2003  0.0342229092  0.2638039599    
2004  0.0179869055  0.0899345277    
2005 -0.0212307743  0.0300102317    
2006  0.0335338743  0.1361943138    
2007 -0.0043643799  0.0352957766    
2008 -0.0532362636 -0.3848579367    
2009  0.0071740936  0.2345419319    
2010  0.0267958031  0.1278271007    
2011  0.0110206418 -0.0000318056    

7f6c8a6817

| Comments

The last 10 trading days of each year, sometimes dubbed the Santa Claus rally, is the last chance for the monkeys to impress, and odds are they will succeed. In 1991 they outdid themselves, posting a gain of over 8.4% during the period. Overall, odds are 3:1 that the year will finish on a high note.

Curiously, the last few years have been rather lame in terms of intensity. One has to go back to 2003 to see a move in excess of 2%.

Here is a truncated table of the total returns for the last 10 trading days of each year.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
1950  0.0514668039  
1951  0.0171159606  
1952  0.0191791331  
1953 -0.0060096154  
1954  0.0300601202  
1955  0.0093209055  
1956  0.0036559140  
1957 -0.0032402792  
1958  0.0344762975  
1959  0.0156011531  
1960  0.0252293578  
.
.
.
1998  0.0579117682  
1999  0.0355728161  
2000 -0.0153997599  
2001  0.0222511108  
2002 -0.0335896309  
2003  0.0342191177  
2004  0.0072389691  
2005 -0.0178214550  
2006 -0.0050438796  
2007  0.0002793011  
2008 -0.0108740884  
2009  0.0053372762  
2010  0.0118837851 

18f660d522

| Comments

Since 1969, there have only been 90 times when the SPX was down for the day and Gold sold off more than 3%. Monkeys usually rally when Eagles are earth-bound, but sometimes the zoo gets a little crazy.

These events were prevalent in the 1980s mostly, with the most frequent year being 1980. Just lately, the zoo has been acting up in similar fashion.

Gold prices two days later tend to come back to where they started, but there are some times when the selloff continues two days later.

Here is a truncated table of Gold returns two days after an SPX down day where Gold also sold off more than 3%.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
1970-10-29 -0.0143042913
1972-06-09 -0.0143312102
1972-09-18  0.0609260764
1973-02-26  0.0530864198
1973-05-16 -0.0093632959
.
.
.
1997-07-07 -0.0022012579
2000-01-04 -0.0074600355
2001-05-25 -0.0190045249
2006-06-13 -0.0289855072
2007-01-05  0.0001640689
2007-11-12  0.0124455507
2008-03-19 -0.0341679708
2008-08-12  0.0003057169
2008-09-02  0.0090795241
2008-09-09 -0.0524464343
2008-10-02  0.0275821596
2008-10-22 -0.0423387097
2008-11-20  0.1144986450
2008-12-01 -0.0151028278
2009-02-26  0.0008008542
2009-04-06  0.0112036771
2009-12-07 -0.0013129103
2011-09-22 -0.0720092915

3ddf5b8b3f

| Comments

Once we get Thanksgiving holiday behind us, our pussel-gutted selves typically enjoy spending some money for holiday gifts. Overall, the SPX market is likewise cheerfully biased during the six days after Thanksgiving. At times, things do get wild with over-exhuberance or over-grouchiness but overall, fat-tailed monkeys don’t dominate the distribution.

Below is a truncated table of SPX returns for the six days following Thanksgiving holiday.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
1950-11-24 -0.0248015873
1951-11-23  0.0106007067
1952-11-28  0.0039184953
1953-11-27  0.0187601958
1954-11-26  0.0078901227
1955-11-25 -0.0061242345
1956-11-23  0.0091784195
1957-11-29  0.0014545455
1958-11-28  0.0107899807
1959-11-27  0.0245473538
1960-11-25 -0.0073476703
1961-11-24  0.0011157601
1962-11-23  0.0238447624
1963-11-29  0.0242214533
1964-11-27 -0.0127574906
1965-11-26 -0.0072873613
1966-11-25 -0.0009973819
.
.
.
1990-11-23  0.0195867481
1991-11-29  0.0067720090
1992-11-27  0.0066870151
1993-11-26  0.0054719266
1994-11-25  0.0074900540
1995-11-24  0.0143382353
1996-11-29 -0.0203973510
1997-11-28  0.0337837838
1998-11-27 -0.0085350544
1999-11-26  0.0114460722
2000-11-24 -0.0053918751
2001-11-23  0.0021283519
2002-11-29 -0.0283745353
2003-11-28  0.0028815721
2004-11-26  0.0079626997
2005-11-25 -0.0004187704
2006-11-24 -0.0066709812
2007-11-23  0.0454343330
2008-11-28 -0.0130790375
2009-11-27 -0.0041868129
2010-11-26  0.0219969124
2011-11-25            NA

03c05600b9

| Comments

The day after Thanksgiving, called Black Friday, is not just a time to start shopping for the holidays. At least historically, it’s also a time to buy some stocks. The SPX has had positive returns on Black Friday 46 of 61 times since 1950. The worst performance by the monkeys happened in 2009 with a selloff of over 1.7%.

The following truncated table are returns on Black Friday.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27

1950-11-24  0.0079365079
1951-11-23 -0.0106007067
1952-11-28  0.0054858934
1953-11-27  0.0057096248
1954-11-26  0.0096434833
1955-11-25 -0.0008748906
1956-11-23  0.0105216029
1957-11-29  0.0113939394
1958-11-28  0.0111753372
1959-11-27  0.0045264624
1960-11-25  0.0059139785
.
.
.
1999-11-26 -0.0003246112
2000-11-24  0.0146783024
2001-11-23  0.0117059356
2002-11-29 -0.0027266821
2003-11-28 -0.0002361944
2004-11-26  0.0007531140
2005-11-25  0.0020859506
2006-11-24 -0.0036555270
2007-11-23  0.0168905327
2008-11-28  0.0096431146
2009-11-27 -0.0172334621
2010-11-26 -0.0074686027

fef49947a8

| Comments

Monkeys are usually relaxed on the day before Thanksgiving. They like the holidays since there are fewer people watching their going ons. Since 1950, there have have been 61 Wednesdays before Thanksgiving. There has been a positive return 48 times.

Here is a truncated table of returns on the Wednesday before Thanksgiving.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
1950-11-22  0.0140845070
1951-11-21 -0.0017636684
1952-11-26  0.0063091483
1953-11-25  0.0008163265
1954-11-24  0.0055833088
1955-11-23  0.0013140604
1956-11-21 -0.0049008688
1957-11-27  0.0289348965
1958-11-26  0.0172481380
1959-11-25  0.0015693112
1960-11-23  0.0014357502
.
.
.
1999-11-24  0.0088563618
2000-11-22 -0.0185475192
2001-11-21 -0.0049270999
2002-11-27  0.0279861164
2003-11-26  0.0043268273
2004-11-24  0.0040953659
2005-11-23  0.0034728004
2006-11-22  0.0023381641
2007-11-21 -0.0159269292
2008-11-26  0.0353281471
2009-11-25  0.0045041378
2010-11-24  0.0149229714

1c5f7b1f1c

| Comments

Dow Jones Industrial Average data going back to the 1920s gives us a lot of data to work with to see if a full moon has an influence on how much rhinos romp around during the day. One way to measure the range is to calculate the difference between the high and low of the day, and normalize it by dividing it by the day’s open. Thick-skinned rhinos seem to be immune from the effects of a full moon.

Here is a table of the percentage of time the DJIA has at least a daily range of 1%, 2%, 3% and 4% with both a full moon and not a full moon.

1
2
3
4
5
6

per    not_full        full     
.01  0.87825482  0.86760563     
.02  0.28453588  0.28873239     
.03  0.09193003  0.10140845     
.04  0.03572848  0.04084507