-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPythonCode.py
More file actions
93 lines (69 loc) · 2.04 KB
/
Copy pathPythonCode.py
File metadata and controls
93 lines (69 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
# loading the dataset
dataset = pd.read_csv('Synthetic_UAE_Stock_Data.csv')
print(dataset)
# creating alias for convinience
A,B,C = dataset["EMIRATESNBD"],dataset["EMAAR"],dataset["MASQ"]
X,Y,Z = "EMIRATESNBD","EMAAR","MASQ"
# scatterplot 1
plt.scatter(A,B, c="orange")
# best_fit linear association for scatterplot 1
fit = np.polyfit(A,B,1)
best_fit = np.poly1d(fit)
plt.plot(A,best_fit(A),color="b")
# graph labeling
plt.title(f"Scatterplot of {Y} VS {X}")
plt.xlabel(f"{X}")
plt.ylabel(f"{Y}")
plt.show()
# scatterplot 2
plt.scatter(B,C, c="orange")
# best_fit linear association for scatterplot 2
fit = np.polyfit(B,C,1)
best_fit = np.poly1d(fit)
plt.plot(B,best_fit(B),color="b")
# graph labeling
plt.title(f"Scatterplot of {Z} VS {Y}")
plt.xlabel(f"{Y}")
plt.ylabel(f"{Z}")
plt.show()
# scatterplot 3
plt.scatter(C,A, c="orange")
# best_fit linear association for scatterplot 3
fit = np.polyfit(C,A,1)
best_fit = np.poly1d(fit)
plt.plot(C,best_fit(C),color="b")
# graph labeling
plt.title(f"Scatterplot of {X} VS {Z}")
plt.xlabel(f"{Z}")
plt.ylabel(f"{X}")
plt.show()
# Calculating co-variance matrix for each of the pair
dic1={X:[],Y:[],Z:[]}
for _ in [A,B,C]:
for __ in [A,B,C]:
if __.equals(A):
dic1[X].append(np.cov(_,__,ddof=1)[0,1])
elif __.equals(B):
dic1[Y].append(np.cov(_,__,ddof=1)[0,1])
elif __.equals(C):
dic1[Z].append(np.cov(_,__,ddof=1)[0,1])
co_var_matrix = pd.DataFrame(dic1,index=[X,Y,Z])
print(co_var_matrix)
# Calculating mean and standard-deviation matrix for each of the selected three companies
M,N="MEAN","STAND. DEVIA."
dic2={M:[],N:[]}
for _ in [A,B,C]:
if _.equals(A):
dic2[M].append(np.mean(_))
dic2[N].append(np.std(_))
elif _.equals(B):
dic2[M].append(np.mean(_))
dic2[N].append(np.std(_))
elif _.equals(C):
dic2[M].append(np.mean(_))
dic2[N].append(np.std(_))
mean_std_matrix = pd.DataFrame(dic2,index=[X,Y,Z])
print(mean_std_matrix)