None
This notebook contains material from nbpages by Jeffrey Kantor (jeff at nd.edu). The text is released under the CC-BY-NC-ND-4.0 license. The code is released under the MIT license.
# IMPORT DATA FILES USED BY THIS NOTEBOOK
import os, requests
file_links = [("data/Stock_Data.csv", "https://jckantor.github.io/nbpages/data/Stock_Data.csv")]
# This cell has been added by nbpages. Run this cell to download data files required for this notebook.
for filepath, fileurl in file_links:
stem, filename = os.path.split(filepath)
if stem:
if not os.path.exists(stem):
os.mkdir(stem)
if not os.path.isfile(filepath):
with open(filepath, 'wb') as f:
response = requests.get(fileurl)
f.write(response.content)
The following cell reads the data file Stock_Data.csv
from the data
subdirectory. The name of this file will appear in the data index.
import pandas as pd
df = pd.read_csv("data/Stock_Data.csv")
df.head()
DJI | GSPC | IXIC | RUT | VIX | |
---|---|---|---|---|---|
0 | 14447.75000 | 1551.689941 | 3235.300049 | 945.849976 | 13.74 |
1 | 14559.65039 | 1563.770020 | 3252.479980 | 949.820007 | 12.77 |
2 | 14526.16016 | 1562.849976 | 3256.520020 | 950.239990 | 13.15 |
3 | 14578.54004 | 1569.189941 | 3267.520020 | 951.539978 | 12.70 |
4 | 14572.84961 | 1562.170044 | 3239.169922 | 938.789978 | 13.58 |
The following cell creates a figure Stock_Data.png
in the figures
subdirectory. The name of this file will appear in the figures index.
%matplotlib inline
import os
import matplotlib.pyplot as plt
import seaborn as sns
sns.set_style("darkgrid")
fig, ax = plt.subplots(2, 1, figsize=(8, 5))
(df/df.iloc[0]).drop('VIX', axis=1).plot(ax=ax[0])
df['VIX'].plot(ax=ax[1])
ax[0].set_title('Normalized Indices')
ax[1].set_title('Volatility VIX')
ax[1].set_xlabel('Days')
fig.tight_layout()
if not os.path.exists("figures"):
os.mkdir("figures")
plt.savefig("figures/Stock_Data.png")