Get startedGet started for free

Scatterplots

1. Scatterplots

2. Stock prices: stock A and B over time

Let's consider two hypothetical stocks, from companies A and B. You can use the ts.plot() function to make a time series plot of the stock prices. The stock price for A is in black, and B is in red. You can see from the figure that the prices are quite similar over time.

3. Stock prices: scatterplot of stock B vs. A

Now let's look at the behavior of the stock prices paired by time. To do so, you make a scatterplot using the plot() function, of stock_A versus stock_B. In the resulting figure, we can see a positive relationship between the pair. That is, when stock_A's price is relatively high, stock_B's price tends to be as well. And when stock_A's price is relatively low, stock_B's price tends to be relatively low as well.

4. Log returns for stock A and B

Instead of stock prices, let's compare the log returns for this pair of stocks. First, you compute the log returns for each company's stock prices. To do so, you apply the diff(log( )) transformation to each. Now, you make a time series plot to compare the log returns over time. As before, both series are similar to each other. The main difference from the time series of prices is that the time series of log returns are all centered close to zero.

5. Scatterplot of stock B vs A log returns

Now let's look at the behavior of the log returns paired by time. As before, you make a scatterplot using the plot() function, but this time using stock_A_logreturn versus stock_B_logreturn. In this figure we again see a positive relationship between the pair. Of course this figure is on the scale of log returns not prices. The positive relationship implies when stock_A's log return is relatively high, so is stock_B's log return. And when stock_A's log return is relatively low, stock_B's log return tends to be relatively low as well.

6. Let's practice!

Nice work! Now you practice plotting stock prices and returns.