<jupyter_start><jupyter_text>Stock Regressions Dan Le 3/12/2019<jupyter_code>import numpy as np
import matplotlib
import matplotlib.pyplot as plt
import numpy.polynomial.polynomial as poly
from sklearn.model_selection import train_test_split

import pandas as pd
import datetime as dt
import requests
%matplotlib inline
matplotlib.rcParams['figure.figsize'] = [12.0, 8.0]
from pandas.plotting import register_matplotlib_converters
register_matplotlib_converters()
API_URL = 'https://api.iextrading.com/1.0'
API_URL
STOCK = 'AMZN'
STOCK

url = f'{API_URL}/stock/{STOCK}/chart/5y'
print(url)
res = requests.get(url)
data =res.json()
df = pd.DataFrame(data)

df['date'] = df['date'].apply((lambda x: pd.Timestamp(x)))

df.head(10)
df.info()
X_train, X_test,Y_train, Y_test = train_test_split(df['date'], df['close'], test_size=.2, random_state=42)
plt.figure(figsize=(15,10))
plt.plot(X_train,Y_train,'go', markersize=2)
plt.title('Amazon Stocks')
plt.figure(figsize=(15,10))
plt.plot(X_test, Y_test, 'co', markersize=2)
plt.title('Test set')
X_years = [matplotlib.dates.date2num(x) for x in X_train]
coefs_lin = poly.polyfit(X_years, Y_train, 1)
coefs_sq = poly.polyfit(X_years, Y_train, 2)
coefs_ten = poly.polyfit(X_years, Y_train, 3)
X_line = np.linspace(matplotlib.dates.date2num(X_train.min()), matplotlib.dates.date2num(X_train.max()), 100000)
ffit_ln = poly.polyval(X_line, coefs_lin)
ffit_sq = poly.polyval(X_line, coefs_sq)
ffit_ten = poly.polyval(X_line, coefs_ten)
plt.figure(figsize=(15,10))
plt.ylim(min(Y_train - 5), max(Y_train + 5))
plt.plot(X_line, ffit_ln, 'g')
plt.plot(X_line, ffit_sq, 'b')
plt.plot(X_line, ffit_ten, 'r')
plt.plot(X_train, Y_train, 'y.', markersize=5)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1537565521258008, 'fraction_numerical': 0.028538147932440302, 'mean_word_length': 7.14218009478673, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '78241', 'license': 'MIT', 'n_tokens_mistral': 766, 'n_tokens_neox': 709, 'n_words': 131, 'path': 'stock-regressions.ipynb', 'repo_name': 'danhuyle508/data_analysis', 'size': '1717'}