Created by Achyut Ghosh and Soumik Bose
Time: Time is almost an inevitable dimension in data warehouse formation. For the share market Time could be represented in many formats: Hour, Day, Week, Month, Quarter, Year etc. as required for the analysis.
Closing Price: “Closing price” generally refers to the last price at which a stock trades during a regular trading session. For Indian share market regular trading sessions run from 9:00 a.m. to 3:00 p.m.(GMT).
Company Group: This could be represented in different ways, however, they are generally grouped to represent a specific industry (such as Banking, IT, Auto etc.) or based on market capitalization (such as Large Cap, Mid Cap, Small Cap).
This is the scatter plot of sample dataset of TCS from Aug 2004 to Feb 2019.
This is Linear Regression (TCS Month based) with R-squared value= 0.5234588
This is Polynomial Regression of degree 2 (TCS Month based) with R-squared value= 0.6379988
This is Polynomial Regression of degree 3 (TCS Month based) with R-squared value= 0.6126444
This is Randomforest Regression (TCS Month based) with R-Squared value=0.9909316
#Converting date into equivalent timeframe
timestamp=[]
import datetime
import time
for d in x:
t=datetime.datetime.strptime(d[0],'%Y/%m/%d').date()
ti=time.mktime(datetime.datetime
.strptime(d[0], '%Y/%m/%d')
.timetuple())
timestamp.append([ti])
#Fitting random forest regression for training set
from sklearn.ensemble import RandomForestRegressor
regressor =
RandomForestRegressor(n_estimators = 80, random_state=0)
regressor.fit(x_train,y_train)
#Predicting the test set result
y_pred=regressor.predict(x_test)
#Deviation
DeviationT=[]
for i in range(0,174):
Dev= Yt[i]-Y_pred_TCS[i]
DeviationT.append(Dev)
P_T=len(Yt)
#compute Yi
#formula 1
m_Yi_T=[]
Q=P_T
#Weight Calculation
Wt_T=1/(P_T * (P_T+1)/2)
i=0
while (i<244):
Yi=Wt_T*Q
m_Yi_T.append(Yi)
i=i+1
#compute Yi
#formula 2
for i in range(0,174):
Yi= Wt_T*Q
m_Yi_T.append(Yi)
Q=Q-1
######Step 3########
Gr_T=[]
G=0.0
#for first growth is 0
Gr_T.append(G)
#Compute Growth(Gr)
for i in range(1,174):
G=(Yt[i]-Yt[i-1])/Yt[i-1] * 100
Gr_T.append(G)
#Company net growth Rate
#CNGR
CNGR_T=[]
for i in range(0,174):
CN=Gr_T[i]*m_Yi_T[i]
CNGR_T.append(CN)
We have considered 3 IT Companies and Stock price started from January 2000 to Jan 2019
Corelation coefficient of TCS & Infosys is -0.15566157 (Left) where as Corelation coefficient of TCS & ITC it is 0.08431221 (Right).