avatarPiotr Szymanski

Free AI web copilot to create summaries, insights and extended knowledge, download it at here

3397

Abstract

o +1. The higher the negative correlation between the securities, the closer the value is to -1. In contrast, the closer the value gets to 0, the less correlation exists.</p><p id="ee33">For example, the correlation between TLT and QQQ is 0.51, which indicates a weaker correlation and hence a significant difference between their returns (-23.67% for TLT and -5.30% for QQQ).</p><p id="014e">Therefore, as can be seen, adding uncorrelated securities to the portfolio increases diversity even further.</p><p id="5165">Let’s take a look at some individual stocks before we wrap up this blog, focusing on some of the random S&P500 stocks: Apple (APPL), Amazon (AMZN), Tesla (TSLA).</p><p id="29ef"><i>Returns & Correlation:</i></p><figure id="bfbc"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*STXlCleLAvs5sCrSHbquAA.png"><figcaption>Returns</figcaption></figure><figure id="9d7a"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*R3A8AP2jTGxuCgD8Jn7VnA.png"><figcaption>Pearson Correlation</figcaption></figure><p id="94f1">In this case, I believe the diversification message is even much more compelling.</p><p id="a535">Diversification can be used in any sort of portfolio, including options portfolios.</p><p id="a52d">Thanks for reading!</p><div id="f1cc"><pre>Python code used <span class="hljs-keyword">for</span> <span class="hljs-keyword">this</span> blog </pre></div><div id="5ccf"><pre><span class="hljs-meta">#importing relevant packages </span></pre></div><div id="8a9a"><pre><span class="hljs-keyword">import</span> yfinance <span class="hljs-keyword">as</span> yf <span class="hljs-keyword">import</span> pandas <span class="hljs-keyword">as</span> pd <span class="hljs-keyword">import</span> seaborn <span class="hljs-keyword">as</span> sns <span class="hljs-keyword">import</span> matplotlib.pyplot <span class="hljs-keyword">as</span> plt</pre></div><div id="b431"><pre>#downloading <span class="hljs-built_in">data</span> </pre></div><div id="735c"><pre><span class="hljs-attr">tickers</span> = [<span class="hljs-string">"SPY"</span>,<span class="hljs-string">"QQQ"</span>,<span class="hljs-string">"IWM"</span>, <span class="hljs-string">"GDX"</span>, <span class="hljs-string">"TLT"</span>] <span class="hljs-attr">df</span> =yf.download(tickers, start = <span class="hljs-string">"2021-01-01"</span> , end = <span class="hljs-string">"2022-05-13"</span>)</pre></div><div id="d7d0"><pre><span class="hljs-meta"># calculating returns </span></pre></div><div id="f79e"><pre>returns = <span class="hljs-built_in">round</span>(((df<span class="hljs-selector-attr">[<span class="hljs-string">'Adj Close'</span>]</span><span class="hljs-selector-class">.iloc</span><span class="hljs-selector-attr">[-1,:]</span> - df<span class="hljs-selector-attr">[<span class="hljs-string">'Adj Close'</span>]</span><span class="hljs-selector-class">.iloc</span><span class="hljs-selector-attr">[0,:]</span>) / df<span class="hljs-selector-attr">[<span class="hljs-string">'Adj Close'</span>]</span><span class="hljs-selector-class">.iloc</span><span class="hljs-selector-attr">[0,:]</span>)*<span class="hljs-number">100</span>, <span class="hljs-number">2</span>)</pre></div><div id="b8ef"><pre><span class="hljs-comment"># saving returns into dataframe</span></pre></div><div id="e2fc"><pre>df2 = pd.DataFrame(<span class="hljs-keyword">returns</spa

Options

n>) df2.<span class="hljs-keyword">rename</span>(<span class="hljs-keyword">columns</span> = {<span class="hljs-number">0</span> : <span class="hljs-string">'Returns %'</span>}, inplace = <span class="hljs-keyword">True</span>)</pre></div><div id="b2dd"><pre><span class="hljs-comment"># plotting the performance of each ETF </span></pre></div><div id="3349"><pre>df[<span class="hljs-string">"Adj Close"</span>].plot(<span class="hljs-attribute">subplots</span>=<span class="hljs-literal">True</span>, figsize=(12, 11)); plt.legend(<span class="hljs-attribute">loc</span>=<span class="hljs-string">'best'</span>) plt.xlabel(<span class="hljs-string">'Date'</span>) plt.ylabel(<span class="hljs-string">'Price'</span>) plt.show()</pre></div><div id="68ed"><pre><span class="hljs-comment">#calculating correlation among ETFs </span></pre></div><div id="3e5d"><pre>corr = df[<span class="hljs-string">'Adj Close'</span>].corr(<span class="hljs-keyword">method</span>='<span class="hljs-title function_">pearson</span>')</pre></div><div id="83ac"><pre><span class="hljs-meta">#visualizing correlation </span></pre></div><div id="8964"><pre>plt.figure(figsize=(13, 8)) sns.heatmap(corr, <span class="hljs-attribute">annot</span>=<span class="hljs-literal">True</span>, <span class="hljs-attribute">cmap</span>=<span class="hljs-string">'Blues'</span>) plt.figure()</pre></div><div id="c949"><pre><span class="hljs-comment">##Analyzing AMZN, TSLA and AAPL stocks</span></pre></div><div id="a380"><pre><span class="hljs-attr">tickers2</span> = [<span class="hljs-string">"AMZN"</span>,<span class="hljs-string">"TSLA"</span>,<span class="hljs-string">"AAPL"</span>] <span class="hljs-attr">df2</span> =yf.download(tickers2, start = <span class="hljs-string">"2021-01-01"</span> , end = <span class="hljs-string">"2022-05-13"</span>)</pre></div><div id="5d3f"><pre>returns2 = <span class="hljs-built_in">round</span>(((df2<span class="hljs-selector-attr">[<span class="hljs-string">'Adj Close'</span>]</span><span class="hljs-selector-class">.iloc</span><span class="hljs-selector-attr">[-1,:]</span> - df2<span class="hljs-selector-attr">[<span class="hljs-string">'Adj Close'</span>]</span><span class="hljs-selector-class">.iloc</span><span class="hljs-selector-attr">[0,:]</span>) / df2<span class="hljs-selector-attr">[<span class="hljs-string">'Adj Close'</span>]</span><span class="hljs-selector-class">.iloc</span><span class="hljs-selector-attr">[0,:]</span>)*<span class="hljs-number">100</span>, <span class="hljs-number">2</span>)</pre></div><div id="d97a"><pre>df3 = pd.DataFrame(returns2) df3.<span class="hljs-keyword">rename</span>(<span class="hljs-keyword">columns</span> = {<span class="hljs-number">0</span> : <span class="hljs-string">'Returns %'</span>}, inplace = <span class="hljs-keyword">True</span>)</pre></div><div id="97ea"><pre>corr2 = df2[<span class="hljs-string">'Adj Close'</span>].corr(<span class="hljs-keyword">method</span>='<span class="hljs-title function_">pearson</span>')</pre></div><p id="d568">Subscribe to DDIntel <a href="https://ddintel.datadriveninvestor.com/">Here</a>.</p><p id="d758">Visit our website here: <a href="https://www.datadriveninvestor.com/">https://www.datadriveninvestor.com</a></p><p id="52f9">Join our network here: <a href="https://datadriveninvestor.com/collaborate">https://datadriveninvestor.com/collaborate</a></p></article></body>

Understanding Portfolio Diversification

Investing is all about risk management.

Photo by David Pisnoy on Unsplash

Disclaimer: The information contained in this blog post is strictly for educational and entertainment purposes only. This is also not an investment advice. All views expressed in this blog are my own and do not represent the opinions of any entity whatsoever with which I have been, am now, or will be affiliated.

____

In the recent times of markets tumbling, diversification can help to spread risk across different securities. Regardless of whether you are investing for the short or long term. Market movements that are abrupt and highly volatile can have a substantial impact on investments.

Diversification is the act of spreading one’s investments over a number of different securities to minimize risk and avoid putting all one’s eggs in one basket. It helps to reduce the volatility of an investment portfolio.

This is because while one security declines, another may rise and balance some of the losses suffered by the first, or it may decline less than the first.

Let’s take a look at the performance of certain ETFs that track US stock indices (S&P500, Nasdaq 100, Russell 2000), government bonds and gold. The results cover the period between 2021–01–01 and 2022–05–13.

GDX — Gold ETF, IWM — Russel 2000, QQQ — Nasdaq 100, SPY — S&P 500, TLT — 20+ Year Treasury Bond
ETFs Performance

As we can see, each ETF presents a different return. Let’s imagine you invested $5000 in these five ETFs, $1000 into each one. At the end of the period you would be left with $4,491.30.

On the other hand, if you had put all $5000 into TLT, you have ended up with $3,816.50.

The results of the diversified portfolio also depends how correlated are the securities with each other. Correlation is the measure of how related two assets are. A high correlation between two assets indicates they move together. If you own stocks with a high correlation to each other, you are increasing your chances to lose money if one of them drops.

Let’s quickly look at the correlation among all of the above listed ETFs.

Pearson Correlation among ETFs
ETFs Correlation — Visual Representation

The higher the positive correlation between the securities, the closer the value is to +1. The higher the negative correlation between the securities, the closer the value is to -1. In contrast, the closer the value gets to 0, the less correlation exists.

For example, the correlation between TLT and QQQ is 0.51, which indicates a weaker correlation and hence a significant difference between their returns (-23.67% for TLT and -5.30% for QQQ).

Therefore, as can be seen, adding uncorrelated securities to the portfolio increases diversity even further.

Let’s take a look at some individual stocks before we wrap up this blog, focusing on some of the random S&P500 stocks: Apple (APPL), Amazon (AMZN), Tesla (TSLA).

Returns & Correlation:

Returns
Pearson Correlation

In this case, I believe the diversification message is even much more compelling.

Diversification can be used in any sort of portfolio, including options portfolios.

Thanks for reading!

Python code used for this blog 
#importing relevant packages 
import yfinance as yf
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
#downloading data 
tickers = ["SPY","QQQ","IWM", "GDX", "TLT"]
df =yf.download(tickers,  start = "2021-01-01" , end = "2022-05-13")
# calculating returns 
returns = round(((df['Adj Close'].iloc[-1,:] - df['Adj Close'].iloc[0,:]) / df['Adj Close'].iloc[0,:])*100, 2)
# saving returns into dataframe
df2 = pd.DataFrame(returns)
df2.rename(columns = {0 : 'Returns %'}, inplace = True)
# plotting the performance of each ETF 
df["Adj Close"].plot(subplots=True, figsize=(12, 11));
plt.legend(loc='best')
plt.xlabel('Date')
plt.ylabel('Price')
plt.show()
#calculating correlation among ETFs 
corr = df['Adj Close'].corr(method='pearson')
#visualizing correlation 
plt.figure(figsize=(13, 8))
sns.heatmap(corr, annot=True, cmap='Blues')
plt.figure()
##Analyzing AMZN, TSLA and AAPL stocks
tickers2 = ["AMZN","TSLA","AAPL"]
df2 =yf.download(tickers2,  start = "2021-01-01" , end = "2022-05-13")
returns2 = round(((df2['Adj Close'].iloc[-1,:] - df2['Adj Close'].iloc[0,:]) / df2['Adj Close'].iloc[0,:])*100, 2)
df3 = pd.DataFrame(returns2)
df3.rename(columns = {0 : 'Returns %'}, inplace = True)
corr2 = df2['Adj Close'].corr(method='pearson')

Subscribe to DDIntel Here.

Visit our website here: https://www.datadriveninvestor.com

Join our network here: https://datadriveninvestor.com/collaborate

Python
Financial Markets
Trading
Data Analysis
Stock Market
Recommended from ReadMedium