-
Notifications
You must be signed in to change notification settings - Fork 0
/
analyse.py
149 lines (118 loc) · 4.16 KB
/
analyse.py
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# library imports
from datetime import date
import matplotlib.pyplot as plt
# linking imports
import similarity
import dataselect
import testcollection
import parameters as para
import grouping
import display
import testalgos
import weightoptimisation
import util
import constants as const
def main():
choice = 1
options = {
0:runTests,
1:runDataSelect,
2:runVisualise,
3:weightoptimisation.optimise,
4:findDoubleTops,
5:viewGraph,
}
options[choice]()
def runTests():
#grouping.redefineGroupingConditions(dataselect.conditionBreakHigh, dataselect.conditionDoubleTops, dataselect.conditionDoubleTopsFiltered)
#grouping.redefineGroupingConditions(dataselect.conditionBreakHigh)
#grouping.redefineGroupingConditions(dataselect.conditionDoubleTopsFiltered)
#grouping.changeToShiftedMonthsGroups()
testCases = testcollection.readTests()
testalgos.compareAlgorithmsWithData(testCases)
#compareAlgorithms('table.csv')
""" REGION: DATA SELECT - START """
def runDataSelect():
dataFiles = util.listDataFiles('data_454111')
#dataFiles = util.getRandomSublist(dataFiles, 20)
for f in dataFiles:
runDataSelectOn(f)
#dataselect.run('data_/ABERDEEN_ASIA_PACIFIC_INCOME_FD.csv')
def runDataSelectOn(fileName):
data, headers = para.readFile(fileName)
dates = data['Date']
if (len(dates) == 0):
#print('Empty File')
return
groups = grouping.groupUp(data, data['Close'])
matches = dataselect.findMatches(data, groups)
#print('Found ' + str(len(matches)) + 'matches')
if (len(matches) <= 0): return #print only when there is at least one match.
print(util.getNameOnly(fileName))
for group in matches:
display.printgroupattrs(group, dates)
""" REGION: DATA SELECT - END """
def findDoubleTops():
dataFiles = util.listDataFiles()
for f in dataFiles:
data, headers = para.readFile(f)
intervals = dataselect.findDoubleTops(data)
if (len(intervals) > 0):
print(util.getNameOnly(f))
print(intervals)
def viewGraph():
fileName = 'data_/F_5_NETWORKS_INC.csv'
start, end = 200,1000
data, headers = para.readFile(fileName)
dates = data['Date']
#lines = ['High', 'Low', 'Close', 'Open']
lines = ['Running', 'DiffClose', 'DiffCloseSign']
for line in lines:
#plt.plot(data[line][start:end])
plt.plot(similarity.byMean(data[line][start:end]))
plt.show()
def runVisualise():
fileName = 'data_/AMERICAN_MANAGEMENT_SYSTEMS_INC.csv'
#fileName = 'table.csv'
targetGroup = 89
#global data, headers
data, headers = para.readFile(fileName)
dates = data['Date']
close = data['Close']
groups = grouping.groupUp(data, data['Close'])
target = targetGroup
targetNext = target+const.ma
results = testalgos.compareAllGroupsBefore(groups, target)
results2 = testalgos.compareAllGroupsBefore(groups, targetNext)
#results2 = compareAllGroupsTo(groups, targetNext)
results.reverse()
results.sort(key=lambda x : x[2])
results2.sort(key=lambda x : x[2])
print('Target ' + str(target))
display.plotgroup(data, groups[target])
plt.show()
for v in results[0:10]:
print(v)
totalRank = 0
ranks = []
for v in results[0:10]:
rank = testalgos.getRank(results2, v[0]+const.ma)
totalRank += rank
ranks.append(rank)
print('Total Rank = ' + str(totalRank))
print(ranks)
display.plotAverageHighLow(groups, results[0:10], groups[targetNext][2])
return
for v in results[0:10]:
print()
print('Chosen group:')
print('Number ' + str(v[0]) + ', SimilarityScore = ' + str(v[2]))
print('Matching Group:')
print('Number ' + str(v[0]+const.ma) + ', Rank = ' + str(testalgos.getRank(results2, v[0]+const.ma)))
print('Plotting Target Next Group (blue)')
display.plotnormalizedWith(data, groups[targetNext], [similarity.byFirst])
print('Plotting Predicted Next Group (green)')
display.plotnormalizedWith(data, groups[v[0]+const.ma], [similarity.byFirst])
plt.show()
if __name__ == '__main__':
main()