Jul 29, 2009

View stock market seasonality

A reader asks about the seasonal chart. Here is a simpler version.

The seasonality is defined as the percent change from the beginning of year to the end of each month.

monthlychange[stock_, year_] :=
Module[{data, firstdateprice, endofmonthprice},
data = FinancialData[stock, "Close", {{year, 1, 1}, {year, 12, 31}}];
data = Map[Flatten[#] &, data]; firstdateprice = data[[1, 4]];
endofmonthprice = Table[Last@Select[data, #[[2]] == i &][[All, 4]], {i, 12}]; (endofmonthprice/firstdateprice - 1)*100]

This will give you the monthly change of AAPL in the year of 2008.

monthlychange["AAPL", 2008]

For multiple years, the average seasonality:

mc = monthlychange["AAPL", #] & /@ Range[2000, 2008];

Mean@mc

For APPL, the following graph shows the average seasonality from 2000 – 2008. According to this graph, it is probably a good idea to hold the stock through Oct and Nov before selling it.

This is a graph shows the seasonality year by year.

vJD said...

Thank you - this helps a lot!

Cheers, Holger

Enock said...

I think you got your sums wrong in 2008 aapl started the year with a price nigh on \$200 and ended it with a price of \$80 the return on all but a few months is negative. Your graph shows positive returns. There must be something wrong...

lijia said...

Just want to say your article is as amazing. The clearness in your post is simply cool.
-------------