-
Notifications
You must be signed in to change notification settings - Fork 0
/
DataPoints.py
178 lines (139 loc) · 5.03 KB
/
DataPoints.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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
import numpy
import math
"""A DataPoint is anything that has the power to fluctuate price of Bitcoin.
These include tweets, articles, reddit posts etc..
Each DataPoint should be classified into its subclasses such that all things inside each
class have similar attributes and have the potential to cause a change in price of BTC
of the same magnitude and direction
Each class can also choose to define the weightage of the sources as a function of time """
class DataPoint:
def __init__(self, timestamp, description):
self.timestamp = timestamp
self.description = description
self.type = -1
self.pos = False
def time_penalty(self, segment):
if self.timestamp > segment.endTime:
return 0
elif segment.startTime <= self.timestamp <= segment.endTime:
return 1
else:
return math.exp(-(((segment.startTime - self.timestamp)/8)**2))
@staticmethod
def weightage(wfreq):
return wfreq
def __str__(self):
return str(self.timestamp) + " " + str(self.__class__)
class TwitterHighPositive(DataPoint):
def __init__(self, timestamp, description):
super().__init__(timestamp, description)
self.type = 0
self.pos = True
def time_penalty(self, segment):
if self.timestamp > segment.endTime:
return 0
elif segment.startTime <= self.timestamp <= segment.endTime:
return 1
else:
return math.exp(-(((segment.startTime - self.timestamp)/4)**2))
@staticmethod
def weightage(wfreq):
return wfreq**0.5
class TwitterLowPositive(DataPoint):
def __init__(self, timestamp, description):
super().__init__(timestamp, description)
self.type = 1
self.pos = True
def time_penalty(self, segment):
if self.timestamp > segment.endTime:
return 0
elif segment.startTime <= self.timestamp <= segment.endTime:
return 1
else:
return math.exp(-(((segment.startTime - self.timestamp)/4)**2))
@staticmethod
def weightage(wfreq):
return wfreq ** 0.5
class TwitterHighNegative(DataPoint):
def __init__(self, timestamp, description):
super().__init__(timestamp, description)
self.type = 2
self.pos = False
def time_penalty(self, segment):
if self.timestamp > segment.endTime:
return 0
elif segment.startTime <= self.timestamp <= segment.endTime:
return 1
else:
return math.exp(-(((segment.startTime - self.timestamp)/4)**2))
@staticmethod
def weightage(wfreq):
return wfreq ** 0.5
class TwitterLowNegative(DataPoint):
def __init__(self, timestamp, description):
super().__init__(timestamp, description)
self.type = 3
self.pos = False
def time_penalty(self, segment):
if self.timestamp > segment.endTime:
return 0
elif segment.startTime <= self.timestamp <= segment.endTime:
return 1
else:
return math.exp(-(((segment.startTime - self.timestamp)/4)**2))
@staticmethod
def weightage(wfreq):
return wfreq ** 0.5
class DominantPositive(DataPoint): #9 days
def __init__(self, timestamp, description):
super().__init__(timestamp, description)
self.type = 4
self.pos = True
class DominantNegative(DataPoint):
def __init__(self, timestamp, description):
super().__init__(timestamp, description)
self.type = 5
self.pos = False
class GovernmentPositive(DataPoint):
def __init__(self, timestamp, description):
super().__init__(timestamp, description)
self.type = 6
self.pos = True
class GovernmentNegative(DataPoint):
def __init__(self, timestamp, description):
super().__init__(timestamp, description)
self.type = 7
self.pos = False
class WeakPositive(DataPoint):
def __init__(self, timestamp, description):
super().__init__(timestamp, description)
self.type = 8
self.pos = True
class WeakNegative(DataPoint):
def __init__(self, timestamp, description):
super().__init__(timestamp, description)
self.type = 9
self.pos = False
class OtherPositive(DataPoint):
def __init__(self, timestamp, description):
super().__init__(timestamp, description)
self.type = 10
self.pos = True
class OtherNegative(DataPoint):
def __init__(self, timestamp, description):
super().__init__(timestamp, description)
self.type = 11
self.pos = False
subclassList = {0: TwitterHighPositive,
1: TwitterLowPositive,
2: TwitterHighNegative,
3: TwitterLowNegative,
4: DominantPositive,
5: DominantNegative,
6: GovernmentPositive,
7: GovernmentNegative,
8: WeakPositive,
9: WeakNegative,
10: OtherPositive,
11: OtherNegative}
datatypes = 12