This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pandas_datareader.nasdaq_trader import get_nasdaq_symbols | |
from pandas_datareader import data | |
import pandas as pd | |
import numpy as np | |
import matplotlib.pyplot as plt | |
import seaborn as sbn | |
import datetime | |
import math | |
symbols = get_nasdaq_symbols() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
list_of_traded_corps = symbols.loc[:, ['NASDAQ Symbol', 'Security Name', 'Listing Exchange']] | |
listing_exchange = { | |
'A': 'NYSE MKT', | |
'N': 'New York Stock Exchange (NYSE)', | |
'P': 'NYSE ARCA', | |
'Q': 'Q - NASDAQ?', # not sure about this one | |
'V': 'Investors\' Exchange, LLC (IEXG)', | |
'Z': 'BATS Global Markets (BATS)' | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tickers = ['AAPL', 'AMZN', 'GOOGL', 'IBM'] | |
data_source = 'yahoo' | |
date_2016 = (datetime.datetime(2016, 1, 1), datetime.datetime(2016, 12, 31)) | |
all_weekdays_2016 = pd.date_range(start = date_2016[0], end = date_2016[1], freq='B') # here we get all business days from 1.JAN.2016 to 31.DEC.2016 | |
data_2016 = data.DataReader(tickers, data_source, date_2016[0], date_2016[1]) | |
close_prices_2016 = data_2016.ix['Adj Close'].reindex(all_weekdays_2016).dropna() # here we take Adjusted Close Price, take business days and drop NA values | |
close_prices_2016.head() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
returns = close_prices_2016.pct_change(1) | |
returns.head() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
log_returns = np.log(close_prices_2016).diff() | |
log_returns.head() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
desc = close_prices_2016.describe() | |
desc.loc['min-max diff'] = desc.loc['max'] - desc.loc['min'] | |
desc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
aapl_amzn_dict = { 'AAPL': log_returns.AAPL, 'AMZN': log_returns.AMZN } | |
AAPL_AMZN_log_returns = pd.DataFrame.from_dict(aapl_amzn_dict) | |
fig = plt.figure(figsize=[16,9]) | |
ax = fig.add_subplot(2,1,2) | |
for c in AAPL_AMZN_log_returns: | |
ax.plot(AAPL_AMZN_log_returns.index, 100*(np.exp(AAPL_AMZN_log_returns[c].cumsum()) - 1), label=str(c)) | |
ax.set_ylabel('Total relative returns (%)') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
box = sbn.boxplot(x='AAPL', data=AAPL_AMZN_log_returns) | |
box.set_title('Box plot for Apple') | |
box.set_ylabel('Total relative returns (%)') | |
plt.show() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
box = sbn.boxplot(x='AMZN', data=AAPL_AMZN_log_returns) | |
box.set_title('Box plot for Amazon') | |
box.set_ylabel('Total relative returns (%)') | |
plt.show() |
OlderNewer