Patterns in Stock Indices over Time

[This article was first published on R – NYC Data Science Academy Blog, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

The traditional advice given to investors is ‘buy and hold’.  I decided to investigate this claim and see what patterns I could find within the major stock indices. The Dow Jones, S&P 500 and the NASDAQ Composite were the indices that I examined. They are all combinations of stocks which are frequently used as an indicator of the US economy. The Dow Jones consists of thirty of the biggest publicly traded stocks in the US, the S&P 500 consists of 500 average to large sized companies and the NASDAQ composite is mainly technology companies. I acquired 30 years of daily financial data for each of the indices at finance.yahoo.com

In my Shiny Application I collected data by year, daily and month. In addition to the High price of an index, I also collected the volume traded and derived the daily change in closing value and the daily percentage change in closing value. Lastly I allowed the user to select a subset of the 30 years of available data. I displayed my data using both a boxplot and a scatterplot. In addition I showed the results of an ANOVA test to show whether the differences observed were statistically significant. You can experiment with my Application here

Many of the relationships I observed were not statistically significant. One interesting results that was significant was the daily percent change of the NASDAQ on a daily basis. The NASDAQ consistently fell slightly on Mondays and increased in value every other day. A similar pattern was observed within the Dow Jones and the S&P but the p-values were higher and the price changes were smaller. These patterns can be explained by markets being closed on weekends and bad news lowering stock prices. This conclusion implies that an investor could consistently make money simply by buying on Monday and selling on Friday. However, when I looked at the NASDAQ data for the last 20 years I found that the p-value went up to 0.58, presumably because traders caught on to this strategy. I also observed that trading volumes were significantly different (p-value 0.00) for all indices based on day of the week, giving a plausible explanation for how markets have adapted to differences in prices by day of the week.

Though a month is longer than a day, I found less significant results by month than by day. Despite several popular phrases such as “the January effect” and “Sell in May and go away”, I found no significant prices related differences by month based on the ANOVA analysis. I did find significant differences in volume (p-value = 0.00 for both the NASDAQ and Dow Jones but p-value 0.07 for S&P).

The yearly plots showed some of the most dramatic changes, but many results were not statistically significant. The High price for all indices increased significantly.

yearly high change

Despite visible booms and busts the market increases significantly year by year. Additionally volume trade is significantly different and generally increases year by year but not as dramatically as High price. No significant differences were found for the Close Change or the Percent Close Change.

 

Despite the unpredictability of markets, there are some patterns in it.  Since market data is publicly available and many people trade on the market, it can be difficult to turn any of these patterns into a profitable trading strategy over the short term.  However, on a yearly basis indices tend to rise which supports the ‘buy and hold’ strategy.  Code for the Application I wrote is below:

 

View the code on Gist.

The post Patterns in Stock Indices over Time appeared first on NYC Data Science Academy Blog.

To leave a comment for the author, please follow the link and comment on their blog: R – NYC Data Science Academy Blog.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)