#Diable the warnings import warnings warnings.filterwarnings('ignore') pip install yfinance import numpy as np import pandas as pd import pandas_datareader as pdr import yfinance as yf import scipy as sp from scipy.stats import norm from pylab import plt, mpl import matplotlib.pyplot as plt import seaborn as sns from pandas.plotting import scatter_matrix from statsmodels.graphics.tsaplots import plot_acf #plt.style.use('seaborn') plt.style.use('fivethirtyeight') mpl.rcParams['font.family'] = 'DejaVu Sans' %matplotlib inline pd.set_option('precision', 3) pd.set_option('display.max_colwidth', 100) def get_prices(tickers, freq_p, st_day, end_day): mystock = pd.DataFrame() for t in tickers: mystock[t] = yf.download(t, start=st_day, end=end_day, interval=freq_p)['Adj Close'] return mystock tic=['SPY', 'IEF', 'TLT','TSLA', 'AAPL', 'NVDA', 'BAC'] prices= get_prices(tic, freq_p='1d', st_day="2011-01-01", end_day="2022-05-31") # id , 1wk, 1mo print(prices) prices.info() prices.tail(20) prices.info() prices.plot(figsize=(10, 18), subplots=True) prices.pct_change().mean().plot(kind='bar', figsize=(10, 6)); prices.pct_change().std().plot(kind='bar', figsize=(10, 6)); rets = np.log(prices / prices.shift(1)) rets.cumsum().apply(np.exp).plot(figsize=(12, 13)) rets.plot.scatter("SPY", "TSLA", alpha=0.9); rets.plot.scatter("SPY", "AAPL", alpha=0.6); rets.plot.scatter("SPY", "IEF", alpha=0.8); rets.hist(bins=50, sharex=False, sharey=False, xlabelsize=1, ylabelsize=1, figsize=(12,12)) plt.show() rets.plot(kind='density', subplots=True, layout=(4,4), sharex=True, legend=True, fontsize=1, figsize=(15,15)) plt.show() correlation = rets.corr() plt.figure(figsize=(15,15)) plt.title('Correlation Matrix') sns.heatmap(correlation, vmax=1, square=True,annot=True,cmap='cubehelix') plt.figure(figsize=(15,15)) scatter_matrix(rets,figsize=(12,12)) plt.show() !pip install mplcyberpunk import mplcyberpunk plt.style.use("cyberpunk") rets.plot(kind='density', subplots=True, layout=(4,4), sharex=True, legend=True, fontsize=1, figsize=(15,15)) plt.show() mplcyberpunk.add_glow_effects() rets = np.log(prices / prices.shift(1)) rets.cumsum().apply(np.exp).plot(figsize=(12, 13))