- import pandas as pd
- import yfinance as yf
- import matplotlib.pyplot as plt
- # Downloading the data
- start_date = '2015-07-01'
- end_date = '2023-08-01'
- brk_a = yf.download('BRK-A', start=start_date, end=end_date)['Adj Close']
- sp500 = yf.download('^GSPC', start=start_date, end=end_date)['Adj Close']
- # Normalizing the data
- brk_a_norm = brk_a / brk_a.iloc[0] * 100
- sp500_norm = sp500 / sp500.iloc[0] * 100
- # Plotting the normalized prices
- plt.figure(figsize=(14, 7))
- plt.plot(brk_a_norm, label='Berkshire Hathaway (BRK-A)')
- plt.plot(sp500_norm, label='S&P 500 Index')
- plt.title('Normalized Prices of BRK-A and S&P 500 Index (2015-2023)')
- plt.xlabel('Date')
- plt.ylabel('Normalized Price (Base 100 on Jul 1, 2015)')
- plt.legend()
- plt.grid(True)
- plt.show()
[text] FIn
Viewer
*** This page was generated with the meta tag "noindex, nofollow". This happened because you selected this option before saving or the system detected it as spam. This means that this page will never get into the search engines and the search bot will not crawl it. There is nothing to worry about, you can still share it with anyone.
Editor
You can edit this paste and save as new: