Deep Learning for Stock Price Prediction

Deep Learning for Stock Close Price Prediction based on Open Price:


For Instructions Follow the above Video then go For the Code Input:



import os
os.environ['TF_CPP_MIN_LOG']='2'
import requests 
import pandas as pd  
from datetime import datetime, timedelta 
import matplotlib.pyplot as plt 
#import tensorflow
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense

#get btcusd data from delta exchnage india
base_url="https://api.india.delta.exchange"
url=f"{base_url}/v2/history/candles"
end=int(datetime.now().timestamp())
start=int((datetime.now()-timedelta(days=1)).timestamp())
params={
    'symbol':'BTCUSD',
    'resolution':'15m',
    'start':start,
    'end':end
}
r=requests.get(url,params=params)
data=r.json().get('result',[])
df=pd.DataFrame(data,columns=['time','open','high','low','close','volume']).sort_values('time')
df['time']=pd.to_datetime(df['time'],unit='s')
df['time']=df['time'].dt.tz_localize('UTC').dt.tz_convert('Asia/Kolkata')
df.set_index('time',inplace=True)
#feature and target
X=df[['open']]
y=df['close']
#model
model=Sequential([Dense(64,activation='relu'),
    Dense(32,activation='relu'),
    Dense(1)
    ])
model.compile(optimizer='adam',loss='mse',metrics=['mae'])

model.fit(X,y,epochs=50)

#predict
predict=model.predict(X)

#plot
plt.plot(df.index,y,label='actual')
plt.plot(df.index,predict,label='predicted',linestyle='--')
plt.show()