Asking ChatGPT to visualize the benefits of Diversification
Did you know only one third of the world population is considered financially literate? A study asked participants four questions to assess financial literacy. This included concepts on diversification, inflation, numeracy, and compound interest. Diversification was found to be the least understood financial concept. Therefore I think a primer is in store. At first I thought about doing a write up discussing how diversification works and why you should incorporate it in your thinking about investing. Instead I asked ChatGPT to help me visualize the benefits of diversification using Python. It wrote up this code for me:
import numpy as np
import matplotlib.pyplot as plt
# Define the average returns of three stocks
stock1_avg_return = 0.1
stock2_avg_return = 0.05
stock3_avg_return = 0.15
# Define the standard deviations of the three stocks (a measure of their volatility)
stock1_std = 0.2
stock2_std = 0.1
stock3_std = 0.3
# Simulate 1000 possible scenarios for each stock
num_scenarios = 1000
stock1_returns = np.random.normal(stock1_avg_return, stock1_std, num_scenarios)
stock2_returns = np.random.normal(stock2_avg_return, stock2_std, num_scenarios)
stock3_returns = np.random.normal(stock3_avg_return, stock3_std, num_scenarios)
# Plot the histograms of the simulated returns for each stock plt.hist(stock1_returns, bins=50, label='Stock 1') plt.hist(stock2_returns, bins=50, label='Stock 2') plt.hist(stock3_returns, bins=50, label='Stock 3') plt.legend() plt.show()
# Calculate the returns for a portfolio invested 50% in each stock portfolio_returns = (0.5 * stock1_returns) + (0.5 * stock2_returns) + (0.5 * stock3_returns)
# Plot the histogram of the portfolio returns plt.hist(portfolio_returns, bins=50) plt.show()
And outputed the below response:
“This code defines the average returns and standard deviations for three stocks. It then simulates 1000 possible scenarios for each stock, assuming a normal distribution of returns. The histograms of the simulated returns for each stock and the portfolio returns (invested 50% in each stock) are plotted.
The histogram of the portfolio returns shows that by diversifying across multiple stocks, the portfolio is less volatile and has a lower standard deviation compared to the individual stocks. This demonstrates the risk reduction that can be achieved through diversification.”
It got the 50% allocation to each of the three stocks wrong but not bad for a first try. I changed it to 33%. The plot below shows the histogram of a portfolio invested equally among three hypothetical companies. Notice the smaller deviations of the upper and lower bands as compared to the individual stocks returns in the chart above. Voila! The benefits of diversification in an easy-to-understand plot.