test
This commit is contained in:
parent
fb289f4dee
commit
6824be93bf
|
|
@ -0,0 +1,4 @@
|
||||||
|
{
|
||||||
|
"python.pythonPath": "C:\\Users\\Seb\\AppData\\Local\\Programs\\Python\\Python39\\python.exe",
|
||||||
|
"jupyter.jupyterServerType": "remote"
|
||||||
|
}
|
||||||
|
|
@ -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()
|
||||||
|
|
@ -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)}%")
|
||||||
|
|
||||||
Loading…
Reference in New Issue