BW #78: Stock markets

It was big news on Monday: Major stock indexes in nearly every market around the world declined. Why? People had all sorts of speculation. A number of them had to do with worries about the health of the US economy, which has outperformed every other major country in both growth and unemployment. Some had to do with the fears of a regional war in the Middle East. (I have a personal stake in hoping that this doesn't happen.) Some had to do with Japan's raising of interest rates, affecting markets in Japan, then Europe, and then the US as they opened on Monday. Some suggested that tech stocks are too frothy. And that's just off the top of my head; there are probably many more ways that you can think about all this.

Given how much every news source was talking (and worrying) about these markets, I thought that it would be interesting to look at stock data from the last few years, and see how bad Monday was in comparison. Rather than look at individual stocks, we'll look at a few of the most prominent stock indexes from around the world. And maybe, just maybe, we'll feel a bit better about where things stand relative to market history.

Data and six questions

This week's data comes from the stock market. If you have a preferred place to get this information, then that's fine; go ahead and use it. I used Yahoo Finance (https://finance.yahoo.com/) for many years, but when I looked earlier today, I didn't see an obvious place to download historical data in CSV format. So I instead when to investing.com (https://investing.com) where I signed up for a free account, and then went to the "major indices" page at https://www.investing.com/indices/major-indices . Then, for each major index:

  • I clicked on the name
  • I clicked on "historical data"
  • I chose dates from January 1, 2005 until today (August 7, 2024)
  • I downloaded the file to my computer

Note that January 1st is both a holiday in most countries and was a Saturday, so the first market day was Monday, January 3rd.

I downloaded data for the following indexes:

  • DAX (Germany)
  • Dow Jones Industrial Average (US)
  • FTSE 100 (UK)
  • NASDAQ (US)
  • Nikkei 225 (Tokyo)
  • S&P 500 (US)
  • Shanghai Composite (China)

I'll admit that downloading this data is a bit annoying. However, I'm pretty sure that the license for the downloaded data doesn't permit me to put it only or make it avaialble to you, so I'm afraid that you'll have to get it yourself.

This week, I have six questions and tasks for you. Learning goals include multi-indexes, working with string data, and working with time data. I'll be back tomorrow, as usual, with my detailed solution and a downloadable Jupyter notebook.

  • Take the seven input CSV files, and turn them into a single data frame. The index of the data frame should be a two-part multi-index, with the first name of the index on the outer layer and the date on the inner layer. We only care about the Date, Price, High, Low, Vol., and Change % columns.
  • Modify the Change % to be a float column, rather than a string column. Modify Price, High, and Low, to be floats.