Plotting multiple datasets

This chapter isn't about investing. It's about crafting compelling data visualizations. I picked Apple's stock price for these visualizations because Apple was in a position to tell a compelling story through their share price at the time at which this book was being written. I will make no predictions or promises about the future value of Apple's share price.

We would like to get a better picture of Apple's 50 percent increase in share price over one year by comparing Apple's share price with the share price values of other companies. As we stated earlier, all share prices are a bit of fiction. Better stated, we would like to compare the percent change of multiple companies' share values through a data visualization.

Go back to Yahoo! Finance and download the historical share price csv files for Google (symbol: GOOGL) and Microsoft (symbol: MSFT). I named their respective csv files googl.csv and msft.csv.

Here's Google's share history:

http://real-chart.finance.yahoo.com/table.csv?s=GOOGL&d=10&e=10&f=2014&g=d&a=11&b=12&c=1980&ignore=.csv

And, here's Microsoft's share history:

http://real-chart.finance.yahoo.com/table.csv?s=MSFT&d=10&e=10&f=2014&g=d&a=11&b=12&c=1980&ignore=.csv

We are going to perform the same steps that we did with Apple's data and create a plot containing Apple, Google, and Microsoft's percent change in a share price plot.

First, Google:

> convertCSVFileToSQL "googl.csv" "googl.sql" "googl" ["date STRING", "open REAL", "high REAL", "low RDEAL", "close REAL", "volume REAL", "adjclose REAL"]
Successful
> googl <- pullStockClosingPrices "googl.sql" "googl"
> let googl252 = take 252 googl
> let googl252pc = applyPercentChangeToData googl252

Next, Microsoft:

> convertCSVFileToSQL "msft.csv" "msft.sql" "msft" ["date STRING", "open REAL", "high REAL", "low REAL", "close REAL", "volume REAL", "adjclose REAL"]
Successful
> msft <- pullStockClosingPrices "msft.sql" "msft"
> let msft252 = take 252 msft
> let msft252pc = applyPercentChangeToData msft252

Next, we are going to plot these three datasets with a single call to plot:

> plot (PNG "aapl_googl_msft_pc.png") [Data2D [Title "AAPL - One Year, % Change", Style Lines, Color Red] [] aapl252pc, Data2D [Title "GOOGL - One Year, % Change", Style Lines, Color Blue] [] googl252pc, Data2D [Title "MSFT - One Year, % Change", Style Lines, Color Green] [] msft252pc]
True

It's a long line, but it illustrates how to combine multiple datasets into a single plot. Note that each dataset is represented with its own Data2D constructor, as well as having its own title, color, and plotting style. Every dataset also has an empty list (required) that we have not discussed up to this point. This empty list is used to include preferences on how functions are plotted. We aren't using these options just yet, but we will in future chapters.

Let's explore the chart that we created:

Plotting multiple datasets

The benefit of using the percentChange function on each of our datasets is that the function will automatically scale the data so that we can enjoy an accurate comparison of the change in the datasets over time. From here, we can see that Apple clearly grew the most over the past year, followed by Microsoft at just over 30 percent, followed by Google at close to 10 percent.

We can also identify when during the past year the share price was below 0. Apple and Microsoft both briefly dipped below 0, while Google stayed in positive territory for the entire year. When evaluating these companies with the criteria set forth in a growth investing strategy, it appears that the clear winner among the three is Apple for this one year period.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset