From 6824be93bfb47690403e2e4674079cd6fba6e2ef Mon Sep 17 00:00:00 2001 From: Sebastien Trudel Date: Thu, 17 Dec 2020 06:50:21 -0500 Subject: [PATCH] test --- .vscode/settings.json | 4 +++ GetDaily.py | 29 +++++++++++++++++++++ test.py | 59 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 92 insertions(+) create mode 100644 .vscode/settings.json create mode 100644 GetDaily.py create mode 100644 test.py diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..73fcbb0 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,4 @@ +{ + "python.pythonPath": "C:\\Users\\Seb\\AppData\\Local\\Programs\\Python\\Python39\\python.exe", + "jupyter.jupyterServerType": "remote" +} \ No newline at end of file diff --git a/GetDaily.py b/GetDaily.py new file mode 100644 index 0000000..052c9af --- /dev/null +++ b/GetDaily.py @@ -0,0 +1,29 @@ +#Get stock symbols in a file +#Get daily quote at end of day +#Send email, see Jupyter thing on other laptop for sending email + +#Quandl no more data after 2018 for some reason + +import quandl +import numpy as np +import yfinance as yf +import plotly.graph_objects as go + +#Quandl test +quandl.ApiConfig.api_key = "sEj_5XNt1kyxi27p5nre" +amazon = quandl.get("WIKI/AMZN") +print(amazon.head()) +print(amazon.tail(10)) + +#Yfinance tests +df = yf.download("TSLA", start="2018-11-01", end="2020-10-18", interval="1d") +fig = go.Figure( + data=go.Ohlc( + x=df.index, + open=df["Open"], + high=df["High"], + low=df["Low"], + close=df["Close"], + ) +) +fig.show() \ No newline at end of file diff --git a/test.py b/test.py new file mode 100644 index 0000000..67c4c6e --- /dev/null +++ b/test.py @@ -0,0 +1,59 @@ +#DataFlair - Make necessary imports +import quandl +import numpy as np +from sklearn.linear_model import LinearRegression +from sklearn.svm import SVR +from sklearn.model_selection import train_test_split + + +#DataFlair - Get Amazon stock data +amazon = quandl.get("WIKI/AMZN") +print(amazon.head()) + + +#DataFlair - Get only the data for the Adjusted Close column +amazon = amazon[['Adj. Close']] +print(amazon.head()) + + +#DataFlair - Predict for 30 days; Predicted has the data of Adj. Close shifted up by 30 rows +forecast_len=30 +amazon['Predicted'] = amazon[['Adj. Close']].shift(-forecast_len) +print(amazon.tail()) + +#DataFlair - Drop the Predicted column, turn it into a NumPy array to create dataset +x=np.array(amazon.drop(['Predicted'],1)) +#DataFlair - Remove last 30 rows +x=x[:-forecast_len] +print(x) + + +#DataFlair - Create dependent dataset for predicted values, remove the last 30 rows +y=np.array(amazon['Predicted']) +y=y[:-forecast_len] +print(y) + + +#DataFlair - Split datasets into training and test sets (80% and 20%) +x_train,x_test,y_train,y_test=train_test_split(x,y,test_size=0.2) + + +#DataFlair - Create SVR model and train it +svr_rbf=SVR(kernel='rbf',C=1e3,gamma=0.1) +svr_rbf.fit(x_train,y_train) + + +#DataFlair - Get score +svr_rbf_confidence=svr_rbf.score(x_test,y_test) +print(f"SVR Confidence: {round(svr_rbf_confidence*100,2)}%") + + +#DataFlair - Create Linear Regression model and train it +lr=LinearRegression() +lr.fit(x_train,y_train) + + +#DataFlair - Get score for Linear Regression +lr_confidence=lr.score(x_test,y_test) +print(f"Linear Regression Confidence: {round(lr_confidence*100,2)}%") +