# Finally, we can also do a correlation plot, to get actual numerical values for the correlation between the stocks' daily return values. By comparing the closing prices, we see an interesting relationship between Google and Amazon stocks.

# In[76]:


# Let's go ahead and use seaborn for a quick heatmap to get correlation for the daily return of the stocks.
sns.heatmap(tech_returns.corr(),annot=True,fmt=".3g",cmap='YlGnBu')


# In[79]:


# Lets check out the correlation between closing prices of stocks
sns.heatmap(closingprice_df.corr(),annot=True,fmt=".3g",cmap='YlGnBu')


# ##### Fantastic! Just like we suspected in our PairPlot we see here numerically and visually that Amazon and Google had the strongest correlation of daily stock return. It's also interesting to see that all the technology comapnies are positively correlated.

# Great! Now that we've done some daily return analysis, let's go ahead and start looking deeper into actual risk analysis.

# ### Risk Analysis

# There are many ways we can quantify risk, one of the most basic ways using the information we've gathered on daily percentage returns is by comparing the expected return with the standard deviation of the daily returns(Risk).

# In[10]:


# Let's start by defining a new DataFrame as a clenaed version of the oriignal tech_returns DataFrame
rets = tech_returns.dropna()
示例#2
0
                if st.checkbox('HeatMap'):
                    st.write('Correlation by Heatmap:')
                    st.write('--> Daily Returns:')

                    labels = [get_name(i) for i in tech_list]

                    sns.heatmap(tech_returns.corr(),
                                annot=True,
                                fmt='.2g',
                                cmap='YlGnBu',
                                xticklabels=labels,
                                yticklabels=labels)
                    st.pyplot(clear_figure=True)
                    st.write('--> Closing Price:')
                    sns.heatmap(closingprice_df.corr(),
                                annot=True,
                                fmt='.3g',
                                cmap='YlGnBu',
                                xticklabels=labels,
                                yticklabels=labels)  #,fmt=".3g"
                    st.pyplot(clear_figure=True)

            if st.checkbox('Show Risk Analysis graph'):
                rets = tech_returns.dropna()

                # Defining the area for the circles of scatter plot to avoid tiny little points
                area = np.pi * 20

                plt.scatter(rets.mean(), rets.std(), s=area)