Skip to content

Instantly share code, notes, and snippets.

import yfinance as yf
import streamlit as st
import datetime
import talib
import ta
import pandas as pd
import requests
yf.pdr_override()
@shashankvemuri
shashankvemuri / all.py
Created July 6, 2020 03:33
all the code for the model
#import the libraries
import math
import warnings
import datetime
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from tensorflow.keras import Sequential
from pandas_datareader import DataReader
from sklearn.preprocessing import MinMaxScaler
@shashankvemuri
shashankvemuri / end.py
Created July 6, 2020 03:32
end of code
#get the root mean squared error (RMSE)
rmse = np.sqrt(np.mean((predictions-y_test)**2))
#plot the data
train = data[:train_data_len]
valid = data[train_data_len:]
valid['Predictions'] = predictions
plt.figure(figsize=(16,8))
plt.title('Model for {}'.format(stock.upper()))
plt.xlabel('Date', fontsize=16)
@shashankvemuri
shashankvemuri / train.py
Created July 6, 2020 03:32
train the model and get the predictions
#build LSTM model
model = Sequential()
model.add(LSTM(50, return_sequences=True, input_shape=(x_train.shape[1],1)))
model.add(LSTM(50,return_sequences=False))
model.add(Dense(25))
model.add(Dense(1))
#compile the model
model.compile(optimizer='adam', loss='mean_squared_error', metrics=['accuracy'])
@shashankvemuri
shashankvemuri / get_data.py
Created July 6, 2020 03:29
Get all the data, scale it, and make it usable by the LSTM model
df = DataReader(stock, "yahoo", start_date, end_date)
data = df.filter(['Close'])
dataset = data.values
train_data_len = math.ceil(len(dataset)*.8)
#scale the data
scaler = MinMaxScaler(feature_range=(0,1))
scaled_data = scaler.fit_transform(dataset)
#create the training dataset
@shashankvemuri
shashankvemuri / intro.py
Created July 6, 2020 03:27
imports and parameters
#import the libraries
import math
import warnings
import datetime
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from tensorflow.keras import Sequential
from pandas_datareader import DataReader
from sklearn.preprocessing import MinMaxScaler
@shashankvemuri
shashankvemuri / all.py
Created June 21, 2020 22:43
All the code!
import talib
import smtplib
import datetime
import numpy as np
import pandas as pd
from email.mime.text import MIMEText
from yahoo_fin import stock_info as si
from pandas_datareader import DataReader
from email.mime.multipart import MIMEMultipart
from bs4 import BeautifulSoup
@shashankvemuri
shashankvemuri / getData.py
Last active September 9, 2020 21:01
Create the function to get all the data
def getData(list_of_stocks):
for stock in list_of_stocks:
df = DataReader(stock, 'yahoo', start, end)
print (stock)
# Current Price
price = si.get_live_price('{}'.format(stock))
price = round(price, 2)
# Sharpe Ratio
@shashankvemuri
shashankvemuri / sendMessage.py
Created June 21, 2020 22:41
Create the function to send the message
def sendMessage(text):
message = text
email = ""
password = ""
sms_gateway = ''
smtp = "smtp.gmail.com"
port = 587
server = smtplib.SMTP(smtp,port)
@shashankvemuri
shashankvemuri / intro.py
Last active June 21, 2020 22:39
import the dependencies and set the parameters
import talib
import smtplib
import datetime
import numpy as np
import pandas as pd
from email.mime.text import MIMEText
from yahoo_fin import stock_info as si
from pandas_datareader import DataReader
from email.mime.multipart import MIMEMultipart
from bs4 import BeautifulSoup