Skip to content

Instantly share code, notes, and snippets.

@PyDataBlog
Last active September 24, 2017 15:20
Show Gist options
  • Select an option

  • Save PyDataBlog/3badd3f8d7faab12e8fbff3dfd60a9a5 to your computer and use it in GitHub Desktop.

Select an option

Save PyDataBlog/3badd3f8d7faab12e8fbff3dfd60a9a5 to your computer and use it in GitHub Desktop.
A script to help visualize the volatility of assets with a histogram
import pandas as pd
from pandas_datareader import data as web
import matplotlib.pyplot as plt
from datetime import datetime
start = datetime(2016,1,1)
end = datetime(2017,1,1)
assets = ['AAPL', 'FB', 'TSLA']
df = pd.DataFrame()
for stock in assets:
df[stock] = web.DataReader(stock, data_source='yahoo', start=start, end=end)['Adj Close']
asset_returns_daily = df.pct_change()
asset_volatility_daily = asset_returns_daily.std()
asset_returns_daily.plot.hist(bins=50, figsize=(10,6));
plt.xlabel('Daily Returns')
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment