Path: blob/master/Documentation/Python/Plotting-Price-Data-Using-Plotly.ipynb
984 views
![]()
Visualizing Data with Plotly
Line Charts, Candlestick Charts, Bar Charts, and Heat Maps
Import Libraries
Let's start by importing the libraries we need.
Visualizing SPY
We will visualize SPY using a time-series line chart and a candlestick chart.
Gathering Data
To begin, we retrieve daily close data for SPY.
SPY Time-Series Line Chart
We reset the index of the DataFrame so that it is easier to use with plotly.
SPY Candlesticks
Visualizing the Correlation Between GLD and BAR Returns
GLD and BAR are two different Gold-tracking ETFs, and we would like to visualize their correlation. To do this, we will employ a scatter plot of their returns.
Gathering Data
First, we get daily close data for GLD and BAR, and call pct_change() on the DataFrames to get daily returns.
Now, we can plot the daily returns of GLD vs the daily returns of BAR. We include a trendline by specifying a trendline key word argument, and setting to OLS, which is the most common way to calculate a trend line.
Visualizing the Average Daily Percent Returns of Banking Stocks
We use a bar chart to compare the average daily percent returns of various banking stocks.
Gathering Data
First, we get historical closing prices for four banking sector stocks, then compute the average daily return for each stock.
With the average daily returns for each stock, we can now create our bar chart to compare these values.
Visualizing Correlations Between Banking Stocks
Correlations between stocks in the same sector are commonly applied to develop pairs trading strategies. We will visualize the correlations between a few stocks in the banking sector using a heat map.
Gathering Data
First, we get historical closing prices for four banking sector stocks.
Before we create the heat map, we must create a correlation matrix, which has all the correlations between all possible pairs of symbols. This can be easily done with pandas DataFrame's built-in corr() method.
With the correlation matrix, we are ready to create a heat map.