High Liquidity Ticker | Fullname |
EWJ | iShares MSCI Japan ETF |
FXI | iShares China Large-Cap ETF |
EWC | iShares MSCI Canada ETF |
EWZ | iShares MSCI Brazil ETF |
EWU | iShares MSCI United Kingdom ETF |
EWY | iShares MSCI South Korea ETF |
EWT | iShares MSCI Taiwan ETF |
EWA | iShares MSCI-Australia ETF |
EWW | iShares MSCI Mexico ETF |
EWL | iShares MSCI Switzerland ETF |
EWQ | iShares MSCI France ETF |
Ticker | Fullname |
JPXN | iShares JPX-Nikkei 400 ETF |
PGJ | Invesco Golden Dragon China ETF |
EWH | iShares MSCI Hong Kong ETF |
EWS | iShares MSCI Singapore ETF |
EWI | iShares MSCI Italy ETF |
EWD | iShares MSCI Sweden ETF |
EZA | iShares MSCI South Africa ETF |
EWN | iShares MSCI Netherlands ETF |
EWK | iShares MSCI Belgium ETF |
EWM | iShares MSCI Malaysia ETF |
EWO | iShares MSCI Austria ETF |
Ticker | Full name |
SPY | SPDR S&P 500 ETF Trust (large cap US stocks) |
EEM | iShares MSCI Emerging Markets ETF (emerging market stocks) |
EFA | iShares MSCI EAFE ETF (EAFE stocks) |
VNQ | Vanguard Real Estate Index Fund ETF (real estate, REITs) |
AGG | iShares Core U.S. Aggregate Bond ETF (fixed income ETF) |
GLD | SPDR Gold Shares (GLD) (gold) |
DBC | Invesco DB Commodity Index Tracking Fund (broad commodity index) |
IWM | iShares Russell 2000 ETF (small cap US stocks) |
Ticker | Fullname |
IYY | iShares Dow Jones U.S. ETF |
PXH | Invesco FTSE RAFI Emerging Markets ETF |
DWM | WisdomTree International Equity Fund |
RWR | SPDR Dow Jones REIT ETF |
GBF | iShares Government/Credit Bond ETF |
DBP | Invesco DB Precious Metals Fund |
DJP | iPath Bloomberg Commodity Index Total Return ETN |
EES | WisdomTree US SmallCap Fund |
import yfinance as yf
import pandas as pd
import numpy as np
import matplotlib
matplotlib.use('Qt5Agg')
import matplotlib.pyplot as plt
#top 10 market value 20240614
top_10_companies = ['AAPL', 'MSFT', 'GOOGL', 'AMZN', 'NVDA', 'META', 'TSLA', 'BRK-B', 'JNJ', 'JPM']
#past 91 days price data
data = yf.download(top_10_companies, period='91d')
#adjusted close prices
adj_close = data['Adj Close']
#total percentage change
total_change = ((adj_close.iloc[-1] - adj_close.iloc[0]) / adj_close.iloc[0]) * 100
#Plot bar
plt.figure(figsize=(10, 6))
bars = total_change.sort_values().plot(kind='bar', color='skyblue')
plt.title('Total Percentage Change in Past 91 Days')
plt.xlabel('Company')
plt.ylabel('Total Percentage Change')
#Annotate
for bar in bars.patches:
bars.annotate(f'{bar.get_height():.2f}%',
(bar.get_x() + bar.get_width() / 2, bar.get_height()),
ha='center', va='bottom')
plt.show()
#Calculate cumulative returns
cumulative_returns = (adj_close / adj_close.iloc[0]) - 1
#Plot the cumulative returns
plt.figure(figsize=(14, 8))
for company in top_10_companies:
plt.plot(cumulative_returns[company], label=company)
#Annotate
for company in top_10_companies:
y = cumulative_returns[company].iloc[-1]
plt.annotate(f'{y*100:.2f}%',
xy=(cumulative_returns.index[-1], y),
xytext=(10, 0),
textcoords='offset points',
horizontalalignment='left', verticalalignment='center',
fontsize=9, bbox=dict(facecolor='white', edgecolor='none', alpha=0.7))
plt.title('Cumulative Returns in the Past 91 Days')
plt.xlabel('Date')
plt.ylabel('Cumulative Returns')
plt.legend()
plt.show()
#Calculate daily returns
daily_returns = (adj_close/adj_close.shift(1))-1
daily_returns=daily_returns.dropna()
#Calculate correlation matrix
correlation_matrix = daily_returns.corr()
#Plot heatmap
fig, ax = plt.subplots(figsize=(12, 8))
cax = ax.matshow(correlation_matrix, cmap='coolwarm', vmin=-1, vmax=1)
fig.colorbar(cax)
#Set labels
ax.set_xticks(range(len(correlation_matrix.columns)))
ax.set_yticks(range(len(correlation_matrix.index)))
ax.set_xticklabels(correlation_matrix.columns, rotation=90)
ax.set_yticklabels(correlation_matrix.index)
#Annotate
for (i, j), val in np.ndenumerate(correlation_matrix):
ax.text(j, i, f'{val:.2f}', ha='center', va='center', color='black')
plt.title('Correlation Heatmap of Daily Returns')
plt.show()
https://medium.com/@sznfpxb/python-usin ... 44d19a2986