├── .gitattributes ├── LICENSE ├── build └── lib │ └── taew │ ├── __init__.py │ ├── ew.py │ └── taew.py ├── dist ├── taew-0.0.1-py3-none-any.whl ├── taew-0.0.1.tar.gz ├── taew-0.0.2-py3-none-any.whl ├── taew-0.0.2.tar.gz ├── taew-0.0.3-py3-none-any.whl └── taew-0.0.3.tar.gz ├── readme.md ├── setup.py ├── taew.egg-info ├── PKG-INFO ├── SOURCES.txt ├── dependency_links.txt └── top_level.txt └── taew ├── __init__.py └── ew.py /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Edward Wong 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /build/lib/taew/__init__.py: -------------------------------------------------------------------------------- 1 | from taew.ew import * -------------------------------------------------------------------------------- /build/lib/taew/ew.py: -------------------------------------------------------------------------------- 1 | import copy 2 | # numpy 3 | import numpy as np 4 | # pandas 5 | import pandas as pd 6 | 7 | 8 | def wave2_fibonacci_check(wave2_end, wave1_start, wave1_end): 9 | # Wave 2 is typically 50%, 61.8%, 76.4%, or 85.4% of wave 1 10 | wave2_endabs = abs(wave2_end) 11 | wave1_startabs = abs(wave1_start) 12 | wave1_endabs = abs(wave1_end) 13 | fibonacci_ratio = [0.146, 0.236, 0.382, 0.5, 0.618, 0.764, 0.854] 14 | for ratio in fibonacci_ratio: 15 | if wave2_endabs <= (wave1_endabs - (wave1_endabs - wave1_startabs) * ratio) * 1.001 and wave2_endabs >= ( 16 | wave1_endabs - (wave1_endabs - wave1_startabs) * ratio) * 0.995: 17 | return True 18 | # endif 19 | # endfor 20 | return False 21 | 22 | 23 | def wave3_fibonacci_check(wave3_end, wave2_start, wave2_end): 24 | # Wave 3 is typically 161.8% of wave 1 25 | wave3_endabs = abs(wave3_end) 26 | wave2_startabs = abs(wave2_start) 27 | wave2_endabs = abs(wave2_end) 28 | fibonacci_ratio = [1.236, 1.618, 2.00, 2.618, 3.236, 4.236] 29 | for ratio in fibonacci_ratio: 30 | if wave3_endabs <= (wave2_endabs - (wave2_endabs - wave2_startabs) * ratio) * 1.001 and wave3_endabs >= ( 31 | wave2_endabs - (wave2_endabs - wave2_startabs) * ratio) * 0.995: 32 | return True 33 | # endif 34 | # endfor 35 | return False 36 | 37 | 38 | def wave4_fibonacci_check(wave4_end, wave3_start, wave3_end): 39 | # Wave 3 is typically 161.8% of wave 1 40 | wave4_endabs = abs(wave4_end) 41 | wave3_startabs = abs(wave3_start) 42 | wave3_endabs = abs(wave3_end) 43 | fibonacci_ratio = [0.146, 0.236, 0.382, 0.5, 0.618, 0.764, 0.854] 44 | for ratio in fibonacci_ratio: 45 | if wave4_endabs <= (wave3_endabs - (wave3_endabs - wave3_startabs) * ratio) * 1.001 and wave3_endabs >= ( 46 | wave3_endabs - (wave3_endabs - wave3_startabs) * ratio) * 0.995: 47 | return True 48 | # endif 49 | # endfor 50 | return False 51 | 52 | 53 | def wave5_fibonacci_check(wave5_end, wave1_start, wave1_end, wave3_start, wave3_end, wave4_end): 54 | wave5_endabs = abs(wave5_end) 55 | wave1_startabs = abs(wave1_start) 56 | wave1_endabs = abs(wave1_end) 57 | wave3_startabs = abs(wave3_start) 58 | wave3_endabs = abs(wave3_end) 59 | wave4_endabs = abs(wave4_end) 60 | 61 | wave5_y = wave5_endabs - wave4_endabs 62 | wave1_y = wave1_endabs - wave1_startabs 63 | wave4_y = abs(wave4_endabs - wave3_endabs) 64 | wave1plus3_y = wave1_y + (wave3_endabs - wave3_startabs) 65 | if wave5_y >= wave4_y and wave5_y <= (wave4_y * 2): 66 | return True 67 | if wave5_y >= wave1_y * 0.95 and wave5_y <= wave1_y * 1.05: 68 | return True 69 | fibonacci_ratio = [0.382, 0.618, 0.764] 70 | for ratio in fibonacci_ratio: 71 | if wave5_y <= wave1plus3_y * ratio * 1.05 and wave5_y >= wave1plus3_y * ratio * 0.95: 72 | return True 73 | # end 74 | # end 75 | return False 76 | 77 | 78 | def diff(data): 79 | # accept list of any number 80 | output_diff = [] 81 | for i in range(1, len(data)): 82 | output_diff.append((data[i - 1] - data[i])) 83 | # return list of number 84 | return output_diff 85 | 86 | 87 | def otherThan(data, otherthan=0): 88 | # accept list and a anytype option 89 | output_otherthan = [] 90 | for i in range(len(data)): 91 | if data[i] != otherthan: 92 | output_otherthan.append(True) 93 | else: 94 | output_otherthan.append(False) 95 | # return list of boolean 96 | return output_otherthan 97 | 98 | 99 | def trimming(data, determineArray): 100 | # accept list of any type and list of boolean 101 | if len(data) != len(determineArray): 102 | raise Exception('array/list size not equal') 103 | filtered_data = [] 104 | for i in range(len(data)): 105 | if determineArray[i]: 106 | filtered_data.append(data[i]) 107 | return filtered_data 108 | 109 | 110 | ############################################## 111 | def Alternative_ElliottWave_label_upward(data): 112 | v = data 113 | j = range(len(data)) 114 | x = [] 115 | z = [] 116 | b = [] 117 | # finding the high point and low point 118 | for i in range(1, len(v) - 1): 119 | if (v[i] <= v[i + 1] and v[i - 1] >= v[i]) or (v[i] >= v[i + 1] and v[i - 1] <= v[i]): 120 | # finding peaks and valleys and then place in a new matrix 121 | x.append(v[i]) 122 | z.append(j[i]) 123 | 124 | diff4x = diff(x) 125 | diff4x.insert(0, 1) 126 | 127 | diff4z = diff(x) 128 | diff4z.insert(0, 1) 129 | 130 | x = trimming(x, otherThan(diff4x, otherthan=0)) 131 | z = trimming(z, otherThan(diff4z, otherthan=0)) 132 | 133 | b = [x, z] 134 | # end 135 | # end 136 | # for each point find the first wave 137 | listofCandidateWave = [] 138 | for i in range(len(x)): 139 | for j in range(len(x)): 140 | if x[i] < x[j]: 141 | wave = { 142 | 'x': [x[i], x[j]], 143 | 'z': [z[i], z[j]], 144 | 'searchIndex': j, 145 | } 146 | listofCandidateWave.append(wave) 147 | # end 148 | # end 149 | # end 150 | 151 | print(len(listofCandidateWave)) 152 | print('successfully filter out candidate wave') 153 | 154 | listofCandidateWave12 = [] 155 | 156 | for i in range(len(listofCandidateWave)): 157 | startSearchIndex = listofCandidateWave[i]['searchIndex'] 158 | # third point should be within 0.382+-5%? we take 0.382+*1.05=0.4011 159 | timeInterval = (listofCandidateWave[i]['z'][1] - listofCandidateWave[i]['z'][0]) * 0.4011 160 | for j in range(startSearchIndex, len(x)): 161 | # wave 2 is a drop and point should at around 0.382 and wave 2 drop destination is higher than start of wave 1 162 | if x[j] < listofCandidateWave[i]['x'][1] and z[j] - listofCandidateWave[i]['z'][1] <= timeInterval and x[ 163 | j] > listofCandidateWave[i]['x'][0] and wave2_fibonacci_check(x[j], listofCandidateWave[i]['x'][0], 164 | listofCandidateWave[i]['x'][1]): 165 | currWave = copy.deepcopy(listofCandidateWave[i]) 166 | currWave['x'].append(x[j]) 167 | currWave['z'].append(z[j]) 168 | currWave['searchIndex'] = j 169 | listofCandidateWave12.append(currWave) 170 | 171 | # end 172 | # end 173 | # end 174 | print(len(listofCandidateWave12)) 175 | print('successfully filter out candidate wave 12') 176 | listofCandidateWave123 = [] 177 | for i in range(len(listofCandidateWave12)): 178 | startSearchIndex = listofCandidateWave12[i]['searchIndex'] 179 | # forth point should be within 1.618+-5%? we take 1.618+*1.05=1.6989 180 | timeInterval = (listofCandidateWave12[i]['z'][1] - listofCandidateWave12[i]['z'][0]) * 1.6989 181 | for j in range(startSearchIndex, len(x)): 182 | # wave 3 is a rise and point should at around 1.618 and wave 3 must be the longest wave 183 | if x[j] > listofCandidateWave12[i]['x'][2] and z[j] - listofCandidateWave12[i]['z'][2] <= timeInterval and \ 184 | z[j] - listofCandidateWave12[i]['z'][2] >= listofCandidateWave12[i]['z'][1] - \ 185 | listofCandidateWave12[i]['z'][0] and z[j] - listofCandidateWave12[i]['z'][2] >= \ 186 | listofCandidateWave12[i]['z'][2] - listofCandidateWave12[i]['z'][1] and wave3_fibonacci_check(x[j], 187 | listofCandidateWave12[ 188 | i][ 189 | 'x'][ 190 | 1], 191 | listofCandidateWave12[ 192 | i][ 193 | 'x'][ 194 | 2]): 195 | currWave = copy.deepcopy(listofCandidateWave12[i]) 196 | currWave['x'].append(x[j]) 197 | currWave['z'].append(z[j]) 198 | currWave['searchIndex'] = j 199 | listofCandidateWave123.append(currWave) 200 | 201 | # end 202 | # end 203 | # end 204 | print(len(listofCandidateWave123)) 205 | print('successfully filter out candidate wave123') 206 | 207 | listofCandidateWave1234 = [] 208 | for i in range(len(listofCandidateWave123)): 209 | startSearchIndex = listofCandidateWave123[i]['searchIndex'] 210 | # forth point should be within 0.382+-5%? we take 0.382+*1.05=0.4011 211 | timeInterval = (listofCandidateWave123[i]['z'][1] - listofCandidateWave123[i]['z'][0]) * 0.4011 212 | wave3length = listofCandidateWave123[i]['z'][3] - listofCandidateWave123[i]['z'][2] 213 | for j in range(startSearchIndex, len(x)): 214 | # wave 4 is a fall and point should at around 1.618 and wave 4 must not fall below the end of wave 1 215 | if x[j] < listofCandidateWave123[i]['x'][3] and z[j] - listofCandidateWave123[i]['z'][3] <= timeInterval and \ 216 | x[j] > listofCandidateWave123[i]['x'][1] and z[j] - listofCandidateWave123[i]['z'][ 217 | 3] <= wave3length and wave4_fibonacci_check(x[j], listofCandidateWave123[i]['x'][2], 218 | listofCandidateWave123[i]['x'][3]): 219 | currWave = copy.deepcopy(listofCandidateWave123[i]) 220 | currWave['x'].append(x[j]) 221 | currWave['z'].append(z[j]) 222 | currWave['searchIndex'] = j 223 | listofCandidateWave1234.append(currWave) 224 | 225 | # end 226 | # end 227 | # end 228 | 229 | print(len(listofCandidateWave1234)) 230 | print('successfully filter out candidate wave1234') 231 | 232 | listofCandidateWave12345 = [] 233 | for i in range(len(listofCandidateWave1234)): 234 | startSearchIndex = listofCandidateWave1234[i]['searchIndex'] 235 | # forth point should be within 01.618+-5%? we take 1.618+*1.05=0.4011 236 | timeInterval = (listofCandidateWave1234[i]['z'][1] - listofCandidateWave1234[i]['z'][0]) * 1.6989 237 | wave3length = listofCandidateWave1234[i]['z'][3] - listofCandidateWave1234[i]['z'][2] 238 | for j in range(startSearchIndex, len(x)): 239 | # wave 4 is a fall and point should at around 1.618 and wave 4 must not fall below the end of wave 1 240 | if x[j] > listofCandidateWave1234[i]['x'][4] and z[j] - listofCandidateWave1234[i]['z'][ 241 | 4] <= timeInterval and z[j] - listofCandidateWave1234[i]['z'][ 242 | 4] <= wave3length and wave5_fibonacci_check(x[j], listofCandidateWave1234[i]['x'][0], 243 | listofCandidateWave1234[i]['x'][1], 244 | listofCandidateWave1234[i]['x'][2], 245 | listofCandidateWave1234[i]['x'][3], 246 | listofCandidateWave1234[i]['x'][4]): 247 | currWave = copy.deepcopy(listofCandidateWave1234[i]) 248 | currWave['x'].append(x[j]) 249 | currWave['z'].append(z[j]) 250 | currWave['searchIndex'] = j 251 | listofCandidateWave12345.append(currWave) 252 | 253 | # end 254 | # end 255 | # end 256 | print(len(listofCandidateWave12345)) 257 | print('successfully filter out candidate wave12345') 258 | return listofCandidateWave12345 259 | 260 | 261 | ######################################## 262 | ############################################## 263 | def Alternative_ElliottWave_label_downward(data): 264 | v = data 265 | j = range(len(data)) 266 | x = [] 267 | z = [] 268 | b = [] 269 | # finding the high point and low point 270 | for i in range(1, len(v) - 1): 271 | if (v[i] <= v[i + 1] and v[i - 1] >= v[i]) or (v[i] >= v[i + 1] and v[i - 1] <= v[i]): 272 | # finding peaks and valleys and then place in a new matrix 273 | x.append(v[i]) 274 | z.append(j[i]) 275 | 276 | diff4x = diff(x) 277 | diff4x.insert(0, 1) 278 | 279 | diff4z = diff(x) 280 | diff4z.insert(0, 1) 281 | 282 | x = trimming(x, otherThan(diff4x, otherthan=0)) 283 | z = trimming(z, otherThan(diff4z, otherthan=0)) 284 | 285 | b = [x, z] 286 | # end 287 | # end 288 | # for each point find the first wave 289 | listofCandidateWave = [] 290 | for i in range(len(x)): 291 | for j in range(len(x)): 292 | if x[i] > x[j]: 293 | wave = { 294 | 'x': [x[i], x[j]], 295 | 'z': [z[i], z[j]], 296 | 'searchIndex': j, 297 | } 298 | listofCandidateWave.append(wave) 299 | # end 300 | # end 301 | # end 302 | 303 | print(len(listofCandidateWave)) 304 | print('successfully filter out candidate wave') 305 | 306 | listofCandidateWave12 = [] 307 | 308 | for i in range(len(listofCandidateWave)): 309 | startSearchIndex = listofCandidateWave[i]['searchIndex'] 310 | # third point should be within 0.382+-5%? we take 0.382+*1.05=0.4011 311 | timeInterval = (listofCandidateWave[i]['z'][1] - listofCandidateWave[i]['z'][0]) * 0.4011 312 | for j in range(startSearchIndex, len(x)): 313 | # wave 2 is a drop and point should at around 0.382 and wave 2 drop destination is higher than start of wave 1 314 | if x[j] > listofCandidateWave[i]['x'][1] and z[j] - listofCandidateWave[i]['z'][1] <= timeInterval and x[ 315 | j] < listofCandidateWave[i]['x'][0] and wave2_fibonacci_check(x[j], listofCandidateWave[i]['x'][0], 316 | listofCandidateWave[i]['x'][1]): 317 | currWave = copy.deepcopy(listofCandidateWave[i]) 318 | currWave['x'].append(x[j]) 319 | currWave['z'].append(z[j]) 320 | currWave['searchIndex'] = j 321 | listofCandidateWave12.append(currWave) 322 | 323 | # end 324 | # end 325 | # end 326 | print(len(listofCandidateWave12)) 327 | print('successfully filter out candidate wave 12') 328 | listofCandidateWave123 = [] 329 | for i in range(len(listofCandidateWave12)): 330 | startSearchIndex = listofCandidateWave12[i]['searchIndex'] 331 | # forth point should be within 1.618+-5%? we take 1.618+*1.05=1.6989 332 | timeInterval = (listofCandidateWave12[i]['z'][1] - listofCandidateWave12[i]['z'][0]) * 1.6989 333 | for j in range(startSearchIndex, len(x)): 334 | # wave 3 is a rise and point should at around 1.618 and wave 3 must be the longest wave 335 | if x[j] < listofCandidateWave12[i]['x'][2] and z[j] - listofCandidateWave12[i]['z'][2] <= timeInterval and \ 336 | z[j] - listofCandidateWave12[i]['z'][2] >= listofCandidateWave12[i]['z'][1] - \ 337 | listofCandidateWave12[i]['z'][0] and z[j] - listofCandidateWave12[i]['z'][2] >= \ 338 | listofCandidateWave12[i]['z'][2] - listofCandidateWave12[i]['z'][1] and wave3_fibonacci_check(x[j], 339 | listofCandidateWave12[ 340 | i][ 341 | 'x'][ 342 | 1], 343 | listofCandidateWave12[ 344 | i][ 345 | 'x'][ 346 | 2]): 347 | currWave = copy.deepcopy(listofCandidateWave12[i]) 348 | currWave['x'].append(x[j]) 349 | currWave['z'].append(z[j]) 350 | currWave['searchIndex'] = j 351 | listofCandidateWave123.append(currWave) 352 | 353 | # end 354 | # end 355 | # end 356 | print(len(listofCandidateWave123)) 357 | print('successfully filter out candidate wave123') 358 | 359 | listofCandidateWave1234 = [] 360 | for i in range(len(listofCandidateWave123)): 361 | startSearchIndex = listofCandidateWave123[i]['searchIndex'] 362 | # forth point should be within 0.382+-5%? we take 0.382+*1.05=0.4011 363 | timeInterval = (listofCandidateWave123[i]['z'][1] - listofCandidateWave123[i]['z'][0]) * 0.4011 364 | wave3length = listofCandidateWave123[i]['z'][3] - listofCandidateWave123[i]['z'][2] 365 | for j in range(startSearchIndex, len(x)): 366 | # wave 4 is a fall and point should at around 1.618 and wave 4 must not fall below the end of wave 1 367 | if x[j] > listofCandidateWave123[i]['x'][3] and z[j] - listofCandidateWave123[i]['z'][3] <= timeInterval and \ 368 | x[j] < listofCandidateWave123[i]['x'][1] and z[j] - listofCandidateWave123[i]['z'][ 369 | 3] <= wave3length and wave4_fibonacci_check(x[j], listofCandidateWave123[i]['x'][2], 370 | listofCandidateWave123[i]['x'][3]): 371 | currWave = copy.deepcopy(listofCandidateWave123[i]) 372 | currWave['x'].append(x[j]) 373 | currWave['z'].append(z[j]) 374 | currWave['searchIndex'] = j 375 | listofCandidateWave1234.append(currWave) 376 | 377 | # end 378 | # end 379 | # end 380 | 381 | print(len(listofCandidateWave1234)) 382 | print('successfully filter out candidate wave1234') 383 | 384 | listofCandidateWave12345 = [] 385 | for i in range(len(listofCandidateWave1234)): 386 | startSearchIndex = listofCandidateWave1234[i]['searchIndex'] 387 | # forth point should be within 01.618+-5%? we take 1.618+*1.05=0.4011 388 | timeInterval = (listofCandidateWave1234[i]['z'][1] - listofCandidateWave1234[i]['z'][0]) * 1.6989 389 | wave3length = listofCandidateWave1234[i]['z'][3] - listofCandidateWave1234[i]['z'][2] 390 | for j in range(startSearchIndex, len(x)): 391 | # wave 4 is a fall and point should at around 1.618 and wave 4 must not fall below the end of wave 1 392 | if x[j] < listofCandidateWave1234[i]['x'][4] and z[j] - listofCandidateWave1234[i]['z'][ 393 | 4] <= timeInterval and z[j] - listofCandidateWave1234[i]['z'][ 394 | 4] <= wave3length and wave5_fibonacci_check(x[j], listofCandidateWave1234[i]['x'][0], 395 | listofCandidateWave1234[i]['x'][1], 396 | listofCandidateWave1234[i]['x'][2], 397 | listofCandidateWave1234[i]['x'][3], 398 | listofCandidateWave1234[i]['x'][4]): 399 | currWave = copy.deepcopy(listofCandidateWave1234[i]) 400 | currWave['x'].append(x[j]) 401 | currWave['z'].append(z[j]) 402 | currWave['searchIndex'] = j 403 | listofCandidateWave12345.append(currWave) 404 | 405 | # end 406 | # end 407 | # end 408 | print(len(listofCandidateWave12345)) 409 | print('successfully filter out candidate wave12345') 410 | return listofCandidateWave12345 411 | ######################################## 412 | # Traditional only make use of fibonacci retracement level, time interval does not necessary follow fibonacci series 413 | 414 | ############################################## 415 | def Traditional_ElliottWave_label_upward(data): 416 | v = data 417 | j = range(len(data)) 418 | x = [] 419 | z = [] 420 | b = [] 421 | # finding the high point and low point 422 | for i in range(1, len(v) - 1): 423 | if (v[i] <= v[i + 1] and v[i - 1] >= v[i]) or (v[i] >= v[i + 1] and v[i - 1] <= v[i]): 424 | # finding peaks and valleys and then place in a new matrix 425 | x.append(v[i]) 426 | z.append(j[i]) 427 | 428 | diff4x = diff(x) 429 | diff4x.insert(0, 1) 430 | 431 | diff4z = diff(x) 432 | diff4z.insert(0, 1) 433 | 434 | x = trimming(x, otherThan(diff4x, otherthan=0)) 435 | z = trimming(z, otherThan(diff4z, otherthan=0)) 436 | 437 | b = [x, z] 438 | # end 439 | # end 440 | # for each point find the first wave 441 | listofCandidateWave = [] 442 | for i in range(len(x)): 443 | for j in range(len(x)): 444 | if x[i] < x[j]: 445 | wave = { 446 | 'x': [x[i], x[j]], 447 | 'z': [z[i], z[j]], 448 | 'searchIndex': j, 449 | } 450 | listofCandidateWave.append(wave) 451 | # end 452 | # end 453 | # end 454 | 455 | print(len(listofCandidateWave)) 456 | print('successfully filter out candidate wave') 457 | 458 | listofCandidateWave12 = [] 459 | 460 | for i in range(len(listofCandidateWave)): 461 | startSearchIndex = listofCandidateWave[i]['searchIndex'] 462 | # third point should be within 0.382+-5%? we take 0.382+*1.05=0.4011 463 | # timeInterval=(listofCandidateWave[i]['z'][1]-listofCandidateWave[i]['z'][0])*0.4011 464 | for j in range(startSearchIndex, len(x)): 465 | # wave 2 is a drop and point should at around 0.382 and wave 2 drop destination is higher than start of wave 1 466 | if x[j] < listofCandidateWave[i]['x'][1] and x[j] > listofCandidateWave[i]['x'][ 467 | 0] and wave2_fibonacci_check(x[j], listofCandidateWave[i]['x'][0], listofCandidateWave[i]['x'][1]): 468 | currWave = copy.deepcopy(listofCandidateWave[i]) 469 | currWave['x'].append(x[j]) 470 | currWave['z'].append(z[j]) 471 | currWave['searchIndex'] = j 472 | listofCandidateWave12.append(currWave) 473 | 474 | # end 475 | # end 476 | # end 477 | print(len(listofCandidateWave12)) 478 | print('successfully filter out candidate wave 12') 479 | listofCandidateWave123 = [] 480 | for i in range(len(listofCandidateWave12)): 481 | startSearchIndex = listofCandidateWave12[i]['searchIndex'] 482 | # forth point should be within 1.618+-5%? we take 1.618+*1.05=1.6989 483 | # timeInterval=(listofCandidateWave12[i]['z'][1]-listofCandidateWave12[i]['z'][0])*1.6989 484 | for j in range(startSearchIndex, len(x)): 485 | # wave 3 is a rise and point should at around 1.618 and wave 3 must be the longest wave 486 | if x[j] > listofCandidateWave12[i]['x'][2] and z[j] - listofCandidateWave12[i]['z'][2] >= \ 487 | listofCandidateWave12[i]['z'][1] - listofCandidateWave12[i]['z'][0] and z[j] - \ 488 | listofCandidateWave12[i]['z'][2] >= listofCandidateWave12[i]['z'][2] - \ 489 | listofCandidateWave12[i]['z'][1] and wave3_fibonacci_check(x[j], listofCandidateWave12[i]['x'][1], 490 | listofCandidateWave12[i]['x'][2]): 491 | currWave = copy.deepcopy(listofCandidateWave12[i]) 492 | currWave['x'].append(x[j]) 493 | currWave['z'].append(z[j]) 494 | currWave['searchIndex'] = j 495 | listofCandidateWave123.append(currWave) 496 | 497 | # end 498 | # end 499 | # end 500 | print(len(listofCandidateWave123)) 501 | print('successfully filter out candidate wave123') 502 | 503 | listofCandidateWave1234 = [] 504 | for i in range(len(listofCandidateWave123)): 505 | startSearchIndex = listofCandidateWave123[i]['searchIndex'] 506 | # forth point should be within 0.382+-5%? we take 0.382+*1.05=0.4011 507 | timeInterval = (listofCandidateWave123[i]['z'][1] - listofCandidateWave123[i]['z'][0]) * 0.4011 508 | wave3length = listofCandidateWave123[i]['z'][3] - listofCandidateWave123[i]['z'][2] 509 | for j in range(startSearchIndex, len(x)): 510 | # wave 4 is a fall and point should at around 1.618 and wave 4 must not fall below the end of wave 1 511 | if x[j] < listofCandidateWave123[i]['x'][3] and z[j] - listofCandidateWave123[i]['z'][3] <= timeInterval and \ 512 | x[j] > listofCandidateWave123[i]['x'][1] and z[j] - listofCandidateWave123[i]['z'][ 513 | 3] <= wave3length and wave4_fibonacci_check(x[j], listofCandidateWave123[i]['x'][2], 514 | listofCandidateWave123[i]['x'][3]): 515 | currWave = copy.deepcopy(listofCandidateWave123[i]) 516 | currWave['x'].append(x[j]) 517 | currWave['z'].append(z[j]) 518 | currWave['searchIndex'] = j 519 | listofCandidateWave1234.append(currWave) 520 | 521 | # end 522 | # end 523 | # end 524 | 525 | print(len(listofCandidateWave1234)) 526 | print('successfully filter out candidate wave1234') 527 | 528 | listofCandidateWave12345 = [] 529 | for i in range(len(listofCandidateWave1234)): 530 | startSearchIndex = listofCandidateWave1234[i]['searchIndex'] 531 | # forth point should be within 01.618+-5%? we take 1.618+*1.05=0.4011 532 | timeInterval = (listofCandidateWave1234[i]['z'][1] - listofCandidateWave1234[i]['z'][0]) * 1.6989 533 | wave3length = listofCandidateWave1234[i]['z'][3] - listofCandidateWave1234[i]['z'][2] 534 | for j in range(startSearchIndex, len(x)): 535 | # wave 4 is a fall and point should at around 1.618 and wave 4 must not fall below the end of wave 1 536 | if x[j] > listofCandidateWave1234[i]['x'][4] and z[j] - listofCandidateWave1234[i]['z'][ 537 | 4] <= timeInterval and z[j] - listofCandidateWave1234[i]['z'][ 538 | 4] <= wave3length and wave5_fibonacci_check(x[j], listofCandidateWave1234[i]['x'][0], 539 | listofCandidateWave1234[i]['x'][1], 540 | listofCandidateWave1234[i]['x'][2], 541 | listofCandidateWave1234[i]['x'][3], 542 | listofCandidateWave1234[i]['x'][4]): 543 | currWave = copy.deepcopy(listofCandidateWave1234[i]) 544 | currWave['x'].append(x[j]) 545 | currWave['z'].append(z[j]) 546 | currWave['searchIndex'] = j 547 | listofCandidateWave12345.append(currWave) 548 | 549 | # end 550 | # end 551 | # end 552 | print(len(listofCandidateWave12345)) 553 | print('successfully filter out candidate wave12345') 554 | return listofCandidateWave12345 555 | 556 | 557 | ######################################## 558 | ############################################## 559 | def Traditional_ElliottWave_label_downward(data): 560 | v = data 561 | j = range(len(data)) 562 | x = [] 563 | z = [] 564 | b = [] 565 | # finding the high point and low point 566 | for i in range(1, len(v) - 1): 567 | if (v[i] <= v[i + 1] and v[i - 1] >= v[i]) or (v[i] >= v[i + 1] and v[i - 1] <= v[i]): 568 | # finding peaks and valleys and then place in a new matrix 569 | x.append(v[i]) 570 | z.append(j[i]) 571 | 572 | diff4x = diff(x) 573 | diff4x.insert(0, 1) 574 | 575 | diff4z = diff(x) 576 | diff4z.insert(0, 1) 577 | 578 | x = trimming(x, otherThan(diff4x, otherthan=0)) 579 | z = trimming(z, otherThan(diff4z, otherthan=0)) 580 | 581 | b = [x, z] 582 | # end 583 | # end 584 | # for each point find the first wave 585 | listofCandidateWave = [] 586 | for i in range(len(x)): 587 | for j in range(len(x)): 588 | if x[i] > x[j]: 589 | wave = { 590 | 'x': [x[i], x[j]], 591 | 'z': [z[i], z[j]], 592 | 'searchIndex': j, 593 | } 594 | listofCandidateWave.append(wave) 595 | # end 596 | # end 597 | # end 598 | 599 | print(len(listofCandidateWave)) 600 | print('successfully filter out candidate wave') 601 | 602 | listofCandidateWave12 = [] 603 | 604 | for i in range(len(listofCandidateWave)): 605 | startSearchIndex = listofCandidateWave[i]['searchIndex'] 606 | # third point should be within 0.382+-5%? we take 0.382+*1.05=0.4011 607 | # timeInterval=(listofCandidateWave[i]['z'][1]-listofCandidateWave[i]['z'][0])*0.4011 608 | for j in range(startSearchIndex, len(x)): 609 | # wave 2 is a drop and wave 2 drop destination is higher than start of wave 1 610 | if x[j] > listofCandidateWave[i]['x'][1] and x[j] < listofCandidateWave[i]['x'][ 611 | 0] and wave2_fibonacci_check(x[j], listofCandidateWave[i]['x'][0], listofCandidateWave[i]['x'][1]): 612 | currWave = copy.deepcopy(listofCandidateWave[i]) 613 | currWave['x'].append(x[j]) 614 | currWave['z'].append(z[j]) 615 | currWave['searchIndex'] = j 616 | listofCandidateWave12.append(currWave) 617 | 618 | # end 619 | # end 620 | # end 621 | print(len(listofCandidateWave12)) 622 | print('successfully filter out candidate wave 12') 623 | listofCandidateWave123 = [] 624 | for i in range(len(listofCandidateWave12)): 625 | startSearchIndex = listofCandidateWave12[i]['searchIndex'] 626 | # forth point should be within 1.618+-5%? we take 1.618+*1.05=1.6989 627 | # timeInterval=(listofCandidateWave12[i]['z'][1]-listofCandidateWave12[i]['z'][0])*1.6989 628 | for j in range(startSearchIndex, len(x)): 629 | # wave 3 is a rise and wave 3 must be the longest wave 630 | if x[j] < listofCandidateWave12[i]['x'][2] and z[j] - listofCandidateWave12[i]['z'][2] >= \ 631 | listofCandidateWave12[i]['z'][1] - listofCandidateWave12[i]['z'][0] and z[j] - \ 632 | listofCandidateWave12[i]['z'][2] >= listofCandidateWave12[i]['z'][2] - \ 633 | listofCandidateWave12[i]['z'][1] and wave3_fibonacci_check(x[j], listofCandidateWave12[i]['x'][1], 634 | listofCandidateWave12[i]['x'][2]): 635 | currWave = copy.deepcopy(listofCandidateWave12[i]) 636 | currWave['x'].append(x[j]) 637 | currWave['z'].append(z[j]) 638 | currWave['searchIndex'] = j 639 | listofCandidateWave123.append(currWave) 640 | 641 | # end 642 | # end 643 | # end 644 | print(len(listofCandidateWave123)) 645 | print('successfully filter out candidate wave123') 646 | 647 | listofCandidateWave1234 = [] 648 | for i in range(len(listofCandidateWave123)): 649 | startSearchIndex = listofCandidateWave123[i]['searchIndex'] 650 | # forth point should be within 0.382+-5%? we take 0.382+*1.05=0.4011 651 | timeInterval = (listofCandidateWave123[i]['z'][1] - listofCandidateWave123[i]['z'][0]) * 0.4011 652 | wave3length = listofCandidateWave123[i]['z'][3] - listofCandidateWave123[i]['z'][2] 653 | for j in range(startSearchIndex, len(x)): 654 | # wave 4 is a fall and wave 4 must not fall below the end of wave 1 655 | if x[j] > listofCandidateWave123[i]['x'][3] and z[j] - listofCandidateWave123[i]['z'][3] <= timeInterval and \ 656 | x[j] > listofCandidateWave123[i]['x'][1] and z[j] - listofCandidateWave123[i]['z'][ 657 | 3] <= wave3length and wave4_fibonacci_check(x[j], listofCandidateWave123[i]['x'][2], 658 | listofCandidateWave123[i]['x'][3]): 659 | currWave = copy.deepcopy(listofCandidateWave123[i]) 660 | currWave['x'].append(x[j]) 661 | currWave['z'].append(z[j]) 662 | currWave['searchIndex'] = j 663 | listofCandidateWave1234.append(currWave) 664 | 665 | # end 666 | # end 667 | # end 668 | 669 | print(len(listofCandidateWave1234)) 670 | print('successfully filter out candidate wave1234') 671 | 672 | listofCandidateWave12345 = [] 673 | for i in range(len(listofCandidateWave1234)): 674 | startSearchIndex = listofCandidateWave1234[i]['searchIndex'] 675 | # forth point should be within 01.618+-5%? we take 1.618+*1.05=0.4011 676 | timeInterval = (listofCandidateWave1234[i]['z'][1] - listofCandidateWave1234[i]['z'][0]) * 1.6989 677 | wave3length = listofCandidateWave1234[i]['z'][3] - listofCandidateWave1234[i]['z'][2] 678 | for j in range(startSearchIndex, len(x)): 679 | # wave 4 is a fall and point should at around 1.618 and wave 4 must not fall below the end of wave 1 680 | if x[j] < listofCandidateWave1234[i]['x'][4] and z[j] - listofCandidateWave1234[i]['z'][ 681 | 4] <= timeInterval and z[j] - listofCandidateWave1234[i]['z'][ 682 | 4] <= wave3length and wave5_fibonacci_check(x[j], listofCandidateWave1234[i]['x'][0], 683 | listofCandidateWave1234[i]['x'][1], 684 | listofCandidateWave1234[i]['x'][2], 685 | listofCandidateWave1234[i]['x'][3], 686 | listofCandidateWave1234[i]['x'][4]): 687 | currWave = copy.deepcopy(listofCandidateWave1234[i]) 688 | currWave['x'].append(x[j]) 689 | currWave['z'].append(z[j]) 690 | currWave['searchIndex'] = j 691 | listofCandidateWave12345.append(currWave) 692 | 693 | # end 694 | # end 695 | # end 696 | print(len(listofCandidateWave12345)) 697 | print('successfully filter out candidate wave12345') 698 | return listofCandidateWave12345 699 | ######################################## 700 | ############################################## 701 | def Practical_ElliottWave3_label_upward(data): 702 | v = data 703 | j = range(len(data)) 704 | x = [] 705 | z = [] 706 | b = [] 707 | # finding the high point and low point 708 | for i in range(1, len(v) - 1): 709 | if (v[i] <= v[i + 1] and v[i - 1] >= v[i]) or (v[i] >= v[i + 1] and v[i - 1] <= v[i]): 710 | # finding peaks and valleys and then place in a new matrix 711 | x.append(v[i]) 712 | z.append(j[i]) 713 | 714 | diff4x = diff(x) 715 | diff4x.insert(0, 1) 716 | 717 | diff4z = diff(x) 718 | diff4z.insert(0, 1) 719 | 720 | x = trimming(x, otherThan(diff4x, otherthan=0)) 721 | z = trimming(z, otherThan(diff4z, otherthan=0)) 722 | 723 | b = [x, z] 724 | # end 725 | # end 726 | # for each point find the first wave 727 | listofCandidateWave = [] 728 | for i in range(len(x)): 729 | for j in range(len(x)): 730 | if x[i] < x[j]: 731 | wave = { 732 | 'x': [x[i], x[j]], 733 | 'z': [z[i], z[j]], 734 | 'searchIndex': j, 735 | } 736 | listofCandidateWave.append(wave) 737 | # end 738 | # end 739 | # end 740 | 741 | print(len(listofCandidateWave)) 742 | print('successfully filter out candidate wave') 743 | 744 | listofCandidateWave12 = [] 745 | 746 | for i in range(len(listofCandidateWave)): 747 | startSearchIndex = listofCandidateWave[i]['searchIndex'] 748 | # third point should be within 0.382+-5%? we take 0.382+*1.05=0.4011 749 | timeInterval = (listofCandidateWave[i]['z'][1] - listofCandidateWave[i]['z'][0]) * 0.4011 750 | for j in range(startSearchIndex, len(x)): 751 | # wave 2 is a drop and point should at around 0.382 and wave 2 drop destination is higher than start of wave 1 752 | if x[j] < listofCandidateWave[i]['x'][1] and z[j] - listofCandidateWave[i]['z'][1] <= timeInterval and x[ 753 | j] > listofCandidateWave[i]['x'][0] and wave2_fibonacci_check(x[j], listofCandidateWave[i]['x'][0], 754 | listofCandidateWave[i]['x'][1]): 755 | currWave = copy.deepcopy(listofCandidateWave[i]) 756 | currWave['x'].append(x[j]) 757 | currWave['z'].append(z[j]) 758 | currWave['searchIndex'] = j 759 | listofCandidateWave12.append(currWave) 760 | 761 | # end 762 | # end 763 | # end 764 | print(len(listofCandidateWave12)) 765 | print('successfully filter out candidate wave 12') 766 | return listofCandidateWave12 767 | 768 | 769 | ######################################## 770 | ############################################## 771 | def Practical_ElliottWave4_label_downward(data): 772 | v = data 773 | j = range(len(data)) 774 | x = [] 775 | z = [] 776 | b = [] 777 | # finding the high point and low point 778 | for i in range(1, len(v) - 1): 779 | if (v[i] <= v[i + 1] and v[i - 1] >= v[i]) or (v[i] >= v[i + 1] and v[i - 1] <= v[i]): 780 | # finding peaks and valleys and then place in a new matrix 781 | x.append(v[i]) 782 | z.append(j[i]) 783 | 784 | diff4x = diff(x) 785 | diff4x.insert(0, 1) 786 | 787 | diff4z = diff(x) 788 | diff4z.insert(0, 1) 789 | 790 | x = trimming(x, otherThan(diff4x, otherthan=0)) 791 | z = trimming(z, otherThan(diff4z, otherthan=0)) 792 | 793 | b = [x, z] 794 | # end 795 | # end 796 | # for each point find the first wave 797 | listofCandidateWave = [] 798 | for i in range(len(x)): 799 | for j in range(len(x)): 800 | if x[i] > x[j]: 801 | wave = { 802 | 'x': [x[i], x[j]], 803 | 'z': [z[i], z[j]], 804 | 'searchIndex': j, 805 | } 806 | listofCandidateWave.append(wave) 807 | # end 808 | # end 809 | # end 810 | 811 | print(len(listofCandidateWave)) 812 | print('successfully filter out candidate wave') 813 | 814 | listofCandidateWave12 = [] 815 | 816 | for i in range(len(listofCandidateWave)): 817 | startSearchIndex = listofCandidateWave[i]['searchIndex'] 818 | # third point should be within 0.382+-5%? we take 0.382+*1.05=0.4011 819 | timeInterval = (listofCandidateWave[i]['z'][1] - listofCandidateWave[i]['z'][0]) * 0.4011 820 | for j in range(startSearchIndex, len(x)): 821 | # wave 2 is a drop and point should at around 0.382 and wave 2 drop destination is higher than start of wave 1 822 | if x[j] > listofCandidateWave[i]['x'][1] and z[j] - listofCandidateWave[i]['z'][1] <= timeInterval and x[ 823 | j] < listofCandidateWave[i]['x'][0] and wave2_fibonacci_check(x[j], listofCandidateWave[i]['x'][0], 824 | listofCandidateWave[i]['x'][1]): 825 | currWave = copy.deepcopy(listofCandidateWave[i]) 826 | currWave['x'].append(x[j]) 827 | currWave['z'].append(z[j]) 828 | currWave['searchIndex'] = j 829 | listofCandidateWave12.append(currWave) 830 | 831 | # end 832 | # end 833 | # end 834 | print(len(listofCandidateWave12)) 835 | print('successfully filter out candidate wave 12') 836 | listofCandidateWave123 = [] 837 | for i in range(len(listofCandidateWave12)): 838 | startSearchIndex = listofCandidateWave12[i]['searchIndex'] 839 | # forth point should be within 1.618+-5%? we take 1.618+*1.05=1.6989 840 | timeInterval = (listofCandidateWave12[i]['z'][1] - listofCandidateWave12[i]['z'][0]) * 1.6989 841 | for j in range(startSearchIndex, len(x)): 842 | # wave 3 is a rise and point should at around 1.618 and wave 3 must be the longest wave 843 | if x[j] < listofCandidateWave12[i]['x'][2] and z[j] - listofCandidateWave12[i]['z'][2] <= timeInterval and \ 844 | z[j] - listofCandidateWave12[i]['z'][2] >= listofCandidateWave12[i]['z'][1] - \ 845 | listofCandidateWave12[i]['z'][0] and z[j] - listofCandidateWave12[i]['z'][2] >= \ 846 | listofCandidateWave12[i]['z'][2] - listofCandidateWave12[i]['z'][1] and wave3_fibonacci_check(x[j], 847 | listofCandidateWave12[ 848 | i][ 849 | 'x'][ 850 | 1], 851 | listofCandidateWave12[ 852 | i][ 853 | 'x'][ 854 | 2]): 855 | currWave = copy.deepcopy(listofCandidateWave12[i]) 856 | currWave['x'].append(x[j]) 857 | currWave['z'].append(z[j]) 858 | currWave['searchIndex'] = j 859 | listofCandidateWave123.append(currWave) 860 | 861 | # end 862 | # end 863 | # end 864 | print(len(listofCandidateWave123)) 865 | print('successfully filter out candidate wave123') 866 | return listofCandidateWave123 867 | ######################################## 868 | ############################################## 869 | def Practical_ElliottWave5_label_upward(data): 870 | v = data 871 | j = range(len(data)) 872 | x = [] 873 | z = [] 874 | b = [] 875 | # finding the high point and low point 876 | for i in range(1, len(v) - 1): 877 | if (v[i] <= v[i + 1] and v[i - 1] >= v[i]) or (v[i] >= v[i + 1] and v[i - 1] <= v[i]): 878 | # finding peaks and valleys and then place in a new matrix 879 | x.append(v[i]) 880 | z.append(j[i]) 881 | 882 | diff4x = diff(x) 883 | diff4x.insert(0, 1) 884 | 885 | diff4z = diff(x) 886 | diff4z.insert(0, 1) 887 | 888 | x = trimming(x, otherThan(diff4x, otherthan=0)) 889 | z = trimming(z, otherThan(diff4z, otherthan=0)) 890 | 891 | b = [x, z] 892 | # end 893 | # end 894 | # for each point find the first wave 895 | listofCandidateWave = [] 896 | for i in range(len(x)): 897 | for j in range(len(x)): 898 | if x[i] < x[j]: 899 | wave = { 900 | 'x': [x[i], x[j]], 901 | 'z': [z[i], z[j]], 902 | 'searchIndex': j, 903 | } 904 | listofCandidateWave.append(wave) 905 | # end 906 | # end 907 | # end 908 | 909 | print(len(listofCandidateWave)) 910 | print('successfully filter out candidate wave') 911 | 912 | listofCandidateWave12 = [] 913 | 914 | for i in range(len(listofCandidateWave)): 915 | startSearchIndex = listofCandidateWave[i]['searchIndex'] 916 | # third point should be within 0.382+-5%? we take 0.382+*1.05=0.4011 917 | timeInterval = (listofCandidateWave[i]['z'][1] - listofCandidateWave[i]['z'][0]) * 0.4011 918 | for j in range(startSearchIndex, len(x)): 919 | # wave 2 is a drop and point should at around 0.382 and wave 2 drop destination is higher than start of wave 1 920 | if x[j] < listofCandidateWave[i]['x'][1] and z[j] - listofCandidateWave[i]['z'][1] <= timeInterval and x[ 921 | j] > listofCandidateWave[i]['x'][0] and wave2_fibonacci_check(x[j], listofCandidateWave[i]['x'][0], 922 | listofCandidateWave[i]['x'][1]): 923 | currWave = copy.deepcopy(listofCandidateWave[i]) 924 | currWave['x'].append(x[j]) 925 | currWave['z'].append(z[j]) 926 | currWave['searchIndex'] = j 927 | listofCandidateWave12.append(currWave) 928 | 929 | # end 930 | # end 931 | # end 932 | print(len(listofCandidateWave12)) 933 | print('successfully filter out candidate wave 12') 934 | listofCandidateWave123 = [] 935 | for i in range(len(listofCandidateWave12)): 936 | startSearchIndex = listofCandidateWave12[i]['searchIndex'] 937 | # forth point should be within 1.618+-5%? we take 1.618+*1.05=1.6989 938 | timeInterval = (listofCandidateWave12[i]['z'][1] - listofCandidateWave12[i]['z'][0]) * 1.6989 939 | for j in range(startSearchIndex, len(x)): 940 | # wave 3 is a rise and point should at around 1.618 and wave 3 must be the longest wave 941 | if x[j] > listofCandidateWave12[i]['x'][2] and z[j] - listofCandidateWave12[i]['z'][2] <= timeInterval and \ 942 | z[j] - listofCandidateWave12[i]['z'][2] >= listofCandidateWave12[i]['z'][1] - \ 943 | listofCandidateWave12[i]['z'][0] and z[j] - listofCandidateWave12[i]['z'][2] >= \ 944 | listofCandidateWave12[i]['z'][2] - listofCandidateWave12[i]['z'][1] and wave3_fibonacci_check(x[j], 945 | listofCandidateWave12[ 946 | i][ 947 | 'x'][ 948 | 1], 949 | listofCandidateWave12[ 950 | i][ 951 | 'x'][ 952 | 2]): 953 | currWave = copy.deepcopy(listofCandidateWave12[i]) 954 | currWave['x'].append(x[j]) 955 | currWave['z'].append(z[j]) 956 | currWave['searchIndex'] = j 957 | listofCandidateWave123.append(currWave) 958 | 959 | # end 960 | # end 961 | # end 962 | print(len(listofCandidateWave123)) 963 | print('successfully filter out candidate wave123') 964 | 965 | listofCandidateWave1234 = [] 966 | for i in range(len(listofCandidateWave123)): 967 | startSearchIndex = listofCandidateWave123[i]['searchIndex'] 968 | # forth point should be within 0.382+-5%? we take 0.382+*1.05=0.4011 969 | timeInterval = (listofCandidateWave123[i]['z'][1] - listofCandidateWave123[i]['z'][0]) * 0.4011 970 | wave3length = listofCandidateWave123[i]['z'][3] - listofCandidateWave123[i]['z'][2] 971 | for j in range(startSearchIndex, len(x)): 972 | # wave 4 is a fall and point should at around 1.618 and wave 4 must not fall below the end of wave 1 973 | if x[j] < listofCandidateWave123[i]['x'][3] and z[j] - listofCandidateWave123[i]['z'][3] <= timeInterval and \ 974 | x[j] > listofCandidateWave123[i]['x'][1] and z[j] - listofCandidateWave123[i]['z'][ 975 | 3] <= wave3length and wave4_fibonacci_check(x[j], listofCandidateWave123[i]['x'][2], 976 | listofCandidateWave123[i]['x'][3]): 977 | currWave = copy.deepcopy(listofCandidateWave123[i]) 978 | currWave['x'].append(x[j]) 979 | currWave['z'].append(z[j]) 980 | currWave['searchIndex'] = j 981 | listofCandidateWave1234.append(currWave) 982 | 983 | # end 984 | # end 985 | # end 986 | 987 | print(len(listofCandidateWave1234)) 988 | print('successfully filter out candidate wave1234') 989 | 990 | return listofCandidateWave1234 991 | ######################################## 992 | -------------------------------------------------------------------------------- /build/lib/taew/taew.py: -------------------------------------------------------------------------------- 1 | import copy 2 | # numpy 3 | import numpy as np 4 | # pandas 5 | import pandas as pd 6 | 7 | 8 | def wave2_fibonacci_check(wave2_end, wave1_start, wave1_end): 9 | # Wave 2 is typically 50%, 61.8%, 76.4%, or 85.4% of wave 1 10 | wave2_endabs = abs(wave2_end) 11 | wave1_startabs = abs(wave1_start) 12 | wave1_endabs = abs(wave1_end) 13 | fibonacci_ratio = [0.146, 0.236, 0.382, 0.5, 0.618, 0.764, 0.854] 14 | for ratio in fibonacci_ratio: 15 | if wave2_endabs <= (wave1_endabs - (wave1_endabs - wave1_startabs) * ratio) * 1.001 and wave2_endabs >= ( 16 | wave1_endabs - (wave1_endabs - wave1_startabs) * ratio) * 0.995: 17 | return True 18 | # endif 19 | # endfor 20 | return False 21 | 22 | 23 | def wave3_fibonacci_check(wave3_end, wave2_start, wave2_end): 24 | # Wave 3 is typically 161.8% of wave 1 25 | wave3_endabs = abs(wave3_end) 26 | wave2_startabs = abs(wave2_start) 27 | wave2_endabs = abs(wave2_end) 28 | fibonacci_ratio = [1.236, 1.618, 2.00, 2.618, 3.236, 4.236] 29 | for ratio in fibonacci_ratio: 30 | if wave3_endabs <= (wave2_endabs - (wave2_endabs - wave2_startabs) * ratio) * 1.001 and wave3_endabs >= ( 31 | wave2_endabs - (wave2_endabs - wave2_startabs) * ratio) * 0.995: 32 | return True 33 | # endif 34 | # endfor 35 | return False 36 | 37 | 38 | def wave4_fibonacci_check(wave4_end, wave3_start, wave3_end): 39 | # Wave 3 is typically 161.8% of wave 1 40 | wave4_endabs = abs(wave4_end) 41 | wave3_startabs = abs(wave3_start) 42 | wave3_endabs = abs(wave3_end) 43 | fibonacci_ratio = [0.146, 0.236, 0.382, 0.5, 0.618, 0.764, 0.854] 44 | for ratio in fibonacci_ratio: 45 | if wave4_endabs <= (wave3_endabs - (wave3_endabs - wave3_startabs) * ratio) * 1.001 and wave3_endabs >= ( 46 | wave3_endabs - (wave3_endabs - wave3_startabs) * ratio) * 0.995: 47 | return True 48 | # endif 49 | # endfor 50 | return False 51 | 52 | 53 | def wave5_fibonacci_check(wave5_end, wave1_start, wave1_end, wave3_start, wave3_end, wave4_end): 54 | wave5_endabs = abs(wave5_end) 55 | wave1_startabs = abs(wave1_start) 56 | wave1_endabs = abs(wave1_end) 57 | wave3_startabs = abs(wave3_start) 58 | wave3_endabs = abs(wave3_end) 59 | wave4_endabs = abs(wave4_end) 60 | 61 | wave5_y = wave5_endabs - wave4_endabs 62 | wave1_y = wave1_endabs - wave1_startabs 63 | wave4_y = abs(wave4_endabs - wave3_endabs) 64 | wave1plus3_y = wave1_y + (wave3_endabs - wave3_startabs) 65 | if wave5_y >= wave4_y and wave5_y <= (wave4_y * 2): 66 | return True 67 | if wave5_y >= wave1_y * 0.95 and wave5_y <= wave1_y * 1.05: 68 | return True 69 | fibonacci_ratio = [0.382, 0.618, 0.764] 70 | for ratio in fibonacci_ratio: 71 | if wave5_y <= wave1plus3_y * ratio * 1.05 and wave5_y >= wave1plus3_y * ratio * 0.95: 72 | return True 73 | # end 74 | # end 75 | return False 76 | 77 | 78 | def diff(data): 79 | # accept list of any number 80 | output_diff = [] 81 | for i in range(1, len(data)): 82 | output_diff.append((data[i - 1] - data[i])) 83 | # return list of number 84 | return output_diff 85 | 86 | 87 | def otherThan(data, otherthan=0): 88 | # accept list and a anytype option 89 | output_otherthan = [] 90 | for i in range(len(data)): 91 | if data[i] != otherthan: 92 | output_otherthan.append(True) 93 | else: 94 | output_otherthan.append(False) 95 | # return list of boolean 96 | return output_otherthan 97 | 98 | 99 | def trimming(data, determineArray): 100 | # accept list of any type and list of boolean 101 | if len(data) != len(determineArray): 102 | raise Exception('array/list size not equal') 103 | filtered_data = [] 104 | for i in range(len(data)): 105 | if determineArray[i]: 106 | filtered_data.append(data[i]) 107 | return filtered_data 108 | 109 | 110 | ############################################## 111 | def Alternative_ElliottWave_label_upward(data): 112 | v = data 113 | j = range(len(data)) 114 | x = [] 115 | z = [] 116 | b = [] 117 | # finding the high point and low point 118 | for i in range(1, len(v) - 1): 119 | if (v[i] <= v[i + 1] and v[i - 1] >= v[i]) or (v[i] >= v[i + 1] and v[i - 1] <= v[i]): 120 | # finding peaks and valleys and then place in a new matrix 121 | x.append(v[i]) 122 | z.append(j[i]) 123 | 124 | diff4x = diff(x) 125 | diff4x.insert(0, 1) 126 | 127 | diff4z = diff(x) 128 | diff4z.insert(0, 1) 129 | 130 | x = trimming(x, otherThan(diff4x, otherthan=0)) 131 | z = trimming(z, otherThan(diff4z, otherthan=0)) 132 | 133 | b = [x, z] 134 | # end 135 | # end 136 | # for each point find the first wave 137 | listofCandidateWave = [] 138 | for i in range(len(x)): 139 | for j in range(len(x)): 140 | if x[i] < x[j]: 141 | wave = { 142 | 'x': [x[i], x[j]], 143 | 'z': [z[i], z[j]], 144 | 'searchIndex': j, 145 | } 146 | listofCandidateWave.append(wave) 147 | # end 148 | # end 149 | # end 150 | 151 | print(len(listofCandidateWave)) 152 | print('successfully filter out candidate wave') 153 | 154 | listofCandidateWave12 = [] 155 | 156 | for i in range(len(listofCandidateWave)): 157 | startSearchIndex = listofCandidateWave[i]['searchIndex'] 158 | # third point should be within 0.382+-5%? we take 0.382+*1.05=0.4011 159 | timeInterval = (listofCandidateWave[i]['z'][1] - listofCandidateWave[i]['z'][0]) * 0.4011 160 | for j in range(startSearchIndex, len(x)): 161 | # wave 2 is a drop and point should at around 0.382 and wave 2 drop destination is higher than start of wave 1 162 | if x[j] < listofCandidateWave[i]['x'][1] and z[j] - listofCandidateWave[i]['z'][1] <= timeInterval and x[ 163 | j] > listofCandidateWave[i]['x'][0] and wave2_fibonacci_check(x[j], listofCandidateWave[i]['x'][0], 164 | listofCandidateWave[i]['x'][1]): 165 | currWave = copy.deepcopy(listofCandidateWave[i]) 166 | currWave['x'].append(x[j]) 167 | currWave['z'].append(z[j]) 168 | currWave['searchIndex'] = j 169 | listofCandidateWave12.append(currWave) 170 | 171 | # end 172 | # end 173 | # end 174 | print(len(listofCandidateWave12)) 175 | print('successfully filter out candidate wave 12') 176 | listofCandidateWave123 = [] 177 | for i in range(len(listofCandidateWave12)): 178 | startSearchIndex = listofCandidateWave12[i]['searchIndex'] 179 | # forth point should be within 1.618+-5%? we take 1.618+*1.05=1.6989 180 | timeInterval = (listofCandidateWave12[i]['z'][1] - listofCandidateWave12[i]['z'][0]) * 1.6989 181 | for j in range(startSearchIndex, len(x)): 182 | # wave 3 is a rise and point should at around 1.618 and wave 3 must be the longest wave 183 | if x[j] > listofCandidateWave12[i]['x'][2] and z[j] - listofCandidateWave12[i]['z'][2] <= timeInterval and \ 184 | z[j] - listofCandidateWave12[i]['z'][2] >= listofCandidateWave12[i]['z'][1] - \ 185 | listofCandidateWave12[i]['z'][0] and z[j] - listofCandidateWave12[i]['z'][2] >= \ 186 | listofCandidateWave12[i]['z'][2] - listofCandidateWave12[i]['z'][1] and wave3_fibonacci_check(x[j], 187 | listofCandidateWave12[ 188 | i][ 189 | 'x'][ 190 | 1], 191 | listofCandidateWave12[ 192 | i][ 193 | 'x'][ 194 | 2]): 195 | currWave = copy.deepcopy(listofCandidateWave12[i]) 196 | currWave['x'].append(x[j]) 197 | currWave['z'].append(z[j]) 198 | currWave['searchIndex'] = j 199 | listofCandidateWave123.append(currWave) 200 | 201 | # end 202 | # end 203 | # end 204 | print(len(listofCandidateWave123)) 205 | print('successfully filter out candidate wave123') 206 | 207 | listofCandidateWave1234 = [] 208 | for i in range(len(listofCandidateWave123)): 209 | startSearchIndex = listofCandidateWave123[i]['searchIndex'] 210 | # forth point should be within 0.382+-5%? we take 0.382+*1.05=0.4011 211 | timeInterval = (listofCandidateWave123[i]['z'][1] - listofCandidateWave123[i]['z'][0]) * 0.4011 212 | wave3length = listofCandidateWave123[i]['z'][3] - listofCandidateWave123[i]['z'][2] 213 | for j in range(startSearchIndex, len(x)): 214 | # wave 4 is a fall and point should at around 1.618 and wave 4 must not fall below the end of wave 1 215 | if x[j] < listofCandidateWave123[i]['x'][3] and z[j] - listofCandidateWave123[i]['z'][3] <= timeInterval and \ 216 | x[j] > listofCandidateWave123[i]['x'][1] and z[j] - listofCandidateWave123[i]['z'][ 217 | 3] <= wave3length and wave4_fibonacci_check(x[j], listofCandidateWave123[i]['x'][2], 218 | listofCandidateWave123[i]['x'][3]): 219 | currWave = copy.deepcopy(listofCandidateWave123[i]) 220 | currWave['x'].append(x[j]) 221 | currWave['z'].append(z[j]) 222 | currWave['searchIndex'] = j 223 | listofCandidateWave1234.append(currWave) 224 | 225 | # end 226 | # end 227 | # end 228 | 229 | print(len(listofCandidateWave1234)) 230 | print('successfully filter out candidate wave1234') 231 | 232 | listofCandidateWave12345 = [] 233 | for i in range(len(listofCandidateWave1234)): 234 | startSearchIndex = listofCandidateWave1234[i]['searchIndex'] 235 | # forth point should be within 01.618+-5%? we take 1.618+*1.05=0.4011 236 | timeInterval = (listofCandidateWave1234[i]['z'][1] - listofCandidateWave1234[i]['z'][0]) * 1.6989 237 | wave3length = listofCandidateWave1234[i]['z'][3] - listofCandidateWave1234[i]['z'][2] 238 | for j in range(startSearchIndex, len(x)): 239 | # wave 4 is a fall and point should at around 1.618 and wave 4 must not fall below the end of wave 1 240 | if x[j] > listofCandidateWave1234[i]['x'][4] and z[j] - listofCandidateWave1234[i]['z'][ 241 | 4] <= timeInterval and z[j] - listofCandidateWave1234[i]['z'][ 242 | 4] <= wave3length and wave5_fibonacci_check(x[j], listofCandidateWave1234[i]['x'][0], 243 | listofCandidateWave1234[i]['x'][1], 244 | listofCandidateWave1234[i]['x'][2], 245 | listofCandidateWave1234[i]['x'][3], 246 | listofCandidateWave1234[i]['x'][4]): 247 | currWave = copy.deepcopy(listofCandidateWave1234[i]) 248 | currWave['x'].append(x[j]) 249 | currWave['z'].append(z[j]) 250 | currWave['searchIndex'] = j 251 | listofCandidateWave12345.append(currWave) 252 | 253 | # end 254 | # end 255 | # end 256 | print(len(listofCandidateWave12345)) 257 | print('successfully filter out candidate wave12345') 258 | return listofCandidateWave12345 259 | 260 | 261 | ######################################## 262 | ############################################## 263 | def Alternative_ElliottWave_label_downward(data): 264 | v = data 265 | j = range(len(data)) 266 | x = [] 267 | z = [] 268 | b = [] 269 | # finding the high point and low point 270 | for i in range(1, len(v) - 1): 271 | if (v[i] <= v[i + 1] and v[i - 1] >= v[i]) or (v[i] >= v[i + 1] and v[i - 1] <= v[i]): 272 | # finding peaks and valleys and then place in a new matrix 273 | x.append(v[i]) 274 | z.append(j[i]) 275 | 276 | diff4x = diff(x) 277 | diff4x.insert(0, 1) 278 | 279 | diff4z = diff(x) 280 | diff4z.insert(0, 1) 281 | 282 | x = trimming(x, otherThan(diff4x, otherthan=0)) 283 | z = trimming(z, otherThan(diff4z, otherthan=0)) 284 | 285 | b = [x, z] 286 | # end 287 | # end 288 | # for each point find the first wave 289 | listofCandidateWave = [] 290 | for i in range(len(x)): 291 | for j in range(len(x)): 292 | if x[i] > x[j]: 293 | wave = { 294 | 'x': [x[i], x[j]], 295 | 'z': [z[i], z[j]], 296 | 'searchIndex': j, 297 | } 298 | listofCandidateWave.append(wave) 299 | # end 300 | # end 301 | # end 302 | 303 | print(len(listofCandidateWave)) 304 | print('successfully filter out candidate wave') 305 | 306 | listofCandidateWave12 = [] 307 | 308 | for i in range(len(listofCandidateWave)): 309 | startSearchIndex = listofCandidateWave[i]['searchIndex'] 310 | # third point should be within 0.382+-5%? we take 0.382+*1.05=0.4011 311 | timeInterval = (listofCandidateWave[i]['z'][1] - listofCandidateWave[i]['z'][0]) * 0.4011 312 | for j in range(startSearchIndex, len(x)): 313 | # wave 2 is a drop and point should at around 0.382 and wave 2 drop destination is higher than start of wave 1 314 | if x[j] > listofCandidateWave[i]['x'][1] and z[j] - listofCandidateWave[i]['z'][1] <= timeInterval and x[ 315 | j] < listofCandidateWave[i]['x'][0] and wave2_fibonacci_check(x[j], listofCandidateWave[i]['x'][0], 316 | listofCandidateWave[i]['x'][1]): 317 | currWave = copy.deepcopy(listofCandidateWave[i]) 318 | currWave['x'].append(x[j]) 319 | currWave['z'].append(z[j]) 320 | currWave['searchIndex'] = j 321 | listofCandidateWave12.append(currWave) 322 | 323 | # end 324 | # end 325 | # end 326 | print(len(listofCandidateWave12)) 327 | print('successfully filter out candidate wave 12') 328 | listofCandidateWave123 = [] 329 | for i in range(len(listofCandidateWave12)): 330 | startSearchIndex = listofCandidateWave12[i]['searchIndex'] 331 | # forth point should be within 1.618+-5%? we take 1.618+*1.05=1.6989 332 | timeInterval = (listofCandidateWave12[i]['z'][1] - listofCandidateWave12[i]['z'][0]) * 1.6989 333 | for j in range(startSearchIndex, len(x)): 334 | # wave 3 is a rise and point should at around 1.618 and wave 3 must be the longest wave 335 | if x[j] < listofCandidateWave12[i]['x'][2] and z[j] - listofCandidateWave12[i]['z'][2] <= timeInterval and \ 336 | z[j] - listofCandidateWave12[i]['z'][2] >= listofCandidateWave12[i]['z'][1] - \ 337 | listofCandidateWave12[i]['z'][0] and z[j] - listofCandidateWave12[i]['z'][2] >= \ 338 | listofCandidateWave12[i]['z'][2] - listofCandidateWave12[i]['z'][1] and wave3_fibonacci_check(x[j], 339 | listofCandidateWave12[ 340 | i][ 341 | 'x'][ 342 | 1], 343 | listofCandidateWave12[ 344 | i][ 345 | 'x'][ 346 | 2]): 347 | currWave = copy.deepcopy(listofCandidateWave12[i]) 348 | currWave['x'].append(x[j]) 349 | currWave['z'].append(z[j]) 350 | currWave['searchIndex'] = j 351 | listofCandidateWave123.append(currWave) 352 | 353 | # end 354 | # end 355 | # end 356 | print(len(listofCandidateWave123)) 357 | print('successfully filter out candidate wave123') 358 | 359 | listofCandidateWave1234 = [] 360 | for i in range(len(listofCandidateWave123)): 361 | startSearchIndex = listofCandidateWave123[i]['searchIndex'] 362 | # forth point should be within 0.382+-5%? we take 0.382+*1.05=0.4011 363 | timeInterval = (listofCandidateWave123[i]['z'][1] - listofCandidateWave123[i]['z'][0]) * 0.4011 364 | wave3length = listofCandidateWave123[i]['z'][3] - listofCandidateWave123[i]['z'][2] 365 | for j in range(startSearchIndex, len(x)): 366 | # wave 4 is a fall and point should at around 1.618 and wave 4 must not fall below the end of wave 1 367 | if x[j] > listofCandidateWave123[i]['x'][3] and z[j] - listofCandidateWave123[i]['z'][3] <= timeInterval and \ 368 | x[j] < listofCandidateWave123[i]['x'][1] and z[j] - listofCandidateWave123[i]['z'][ 369 | 3] <= wave3length and wave4_fibonacci_check(x[j], listofCandidateWave123[i]['x'][2], 370 | listofCandidateWave123[i]['x'][3]): 371 | currWave = copy.deepcopy(listofCandidateWave123[i]) 372 | currWave['x'].append(x[j]) 373 | currWave['z'].append(z[j]) 374 | currWave['searchIndex'] = j 375 | listofCandidateWave1234.append(currWave) 376 | 377 | # end 378 | # end 379 | # end 380 | 381 | print(len(listofCandidateWave1234)) 382 | print('successfully filter out candidate wave1234') 383 | 384 | listofCandidateWave12345 = [] 385 | for i in range(len(listofCandidateWave1234)): 386 | startSearchIndex = listofCandidateWave1234[i]['searchIndex'] 387 | # forth point should be within 01.618+-5%? we take 1.618+*1.05=0.4011 388 | timeInterval = (listofCandidateWave1234[i]['z'][1] - listofCandidateWave1234[i]['z'][0]) * 1.6989 389 | wave3length = listofCandidateWave1234[i]['z'][3] - listofCandidateWave1234[i]['z'][2] 390 | for j in range(startSearchIndex, len(x)): 391 | # wave 4 is a fall and point should at around 1.618 and wave 4 must not fall below the end of wave 1 392 | if x[j] < listofCandidateWave1234[i]['x'][4] and z[j] - listofCandidateWave1234[i]['z'][ 393 | 4] <= timeInterval and z[j] - listofCandidateWave1234[i]['z'][ 394 | 4] <= wave3length and wave5_fibonacci_check(x[j], listofCandidateWave1234[i]['x'][0], 395 | listofCandidateWave1234[i]['x'][1], 396 | listofCandidateWave1234[i]['x'][2], 397 | listofCandidateWave1234[i]['x'][3], 398 | listofCandidateWave1234[i]['x'][4]): 399 | currWave = copy.deepcopy(listofCandidateWave1234[i]) 400 | currWave['x'].append(x[j]) 401 | currWave['z'].append(z[j]) 402 | currWave['searchIndex'] = j 403 | listofCandidateWave12345.append(currWave) 404 | 405 | # end 406 | # end 407 | # end 408 | print(len(listofCandidateWave12345)) 409 | print('successfully filter out candidate wave12345') 410 | return listofCandidateWave12345 411 | ######################################## 412 | # Traditional only make use of fibonacci retracement level, time interval does not necessary follow fibonacci series 413 | 414 | ############################################## 415 | def Traditional_ElliottWave_label_upward(data): 416 | v = data 417 | j = range(len(data)) 418 | x = [] 419 | z = [] 420 | b = [] 421 | # finding the high point and low point 422 | for i in range(1, len(v) - 1): 423 | if (v[i] <= v[i + 1] and v[i - 1] >= v[i]) or (v[i] >= v[i + 1] and v[i - 1] <= v[i]): 424 | # finding peaks and valleys and then place in a new matrix 425 | x.append(v[i]) 426 | z.append(j[i]) 427 | 428 | diff4x = diff(x) 429 | diff4x.insert(0, 1) 430 | 431 | diff4z = diff(x) 432 | diff4z.insert(0, 1) 433 | 434 | x = trimming(x, otherThan(diff4x, otherthan=0)) 435 | z = trimming(z, otherThan(diff4z, otherthan=0)) 436 | 437 | b = [x, z] 438 | # end 439 | # end 440 | # for each point find the first wave 441 | listofCandidateWave = [] 442 | for i in range(len(x)): 443 | for j in range(len(x)): 444 | if x[i] < x[j]: 445 | wave = { 446 | 'x': [x[i], x[j]], 447 | 'z': [z[i], z[j]], 448 | 'searchIndex': j, 449 | } 450 | listofCandidateWave.append(wave) 451 | # end 452 | # end 453 | # end 454 | 455 | print(len(listofCandidateWave)) 456 | print('successfully filter out candidate wave') 457 | 458 | listofCandidateWave12 = [] 459 | 460 | for i in range(len(listofCandidateWave)): 461 | startSearchIndex = listofCandidateWave[i]['searchIndex'] 462 | # third point should be within 0.382+-5%? we take 0.382+*1.05=0.4011 463 | # timeInterval=(listofCandidateWave[i]['z'][1]-listofCandidateWave[i]['z'][0])*0.4011 464 | for j in range(startSearchIndex, len(x)): 465 | # wave 2 is a drop and point should at around 0.382 and wave 2 drop destination is higher than start of wave 1 466 | if x[j] < listofCandidateWave[i]['x'][1] and x[j] > listofCandidateWave[i]['x'][ 467 | 0] and wave2_fibonacci_check(x[j], listofCandidateWave[i]['x'][0], listofCandidateWave[i]['x'][1]): 468 | currWave = copy.deepcopy(listofCandidateWave[i]) 469 | currWave['x'].append(x[j]) 470 | currWave['z'].append(z[j]) 471 | currWave['searchIndex'] = j 472 | listofCandidateWave12.append(currWave) 473 | 474 | # end 475 | # end 476 | # end 477 | print(len(listofCandidateWave12)) 478 | print('successfully filter out candidate wave 12') 479 | listofCandidateWave123 = [] 480 | for i in range(len(listofCandidateWave12)): 481 | startSearchIndex = listofCandidateWave12[i]['searchIndex'] 482 | # forth point should be within 1.618+-5%? we take 1.618+*1.05=1.6989 483 | # timeInterval=(listofCandidateWave12[i]['z'][1]-listofCandidateWave12[i]['z'][0])*1.6989 484 | for j in range(startSearchIndex, len(x)): 485 | # wave 3 is a rise and point should at around 1.618 and wave 3 must be the longest wave 486 | if x[j] > listofCandidateWave12[i]['x'][2] and z[j] - listofCandidateWave12[i]['z'][2] >= \ 487 | listofCandidateWave12[i]['z'][1] - listofCandidateWave12[i]['z'][0] and z[j] - \ 488 | listofCandidateWave12[i]['z'][2] >= listofCandidateWave12[i]['z'][2] - \ 489 | listofCandidateWave12[i]['z'][1] and wave3_fibonacci_check(x[j], listofCandidateWave12[i]['x'][1], 490 | listofCandidateWave12[i]['x'][2]): 491 | currWave = copy.deepcopy(listofCandidateWave12[i]) 492 | currWave['x'].append(x[j]) 493 | currWave['z'].append(z[j]) 494 | currWave['searchIndex'] = j 495 | listofCandidateWave123.append(currWave) 496 | 497 | # end 498 | # end 499 | # end 500 | print(len(listofCandidateWave123)) 501 | print('successfully filter out candidate wave123') 502 | 503 | listofCandidateWave1234 = [] 504 | for i in range(len(listofCandidateWave123)): 505 | startSearchIndex = listofCandidateWave123[i]['searchIndex'] 506 | # forth point should be within 0.382+-5%? we take 0.382+*1.05=0.4011 507 | timeInterval = (listofCandidateWave123[i]['z'][1] - listofCandidateWave123[i]['z'][0]) * 0.4011 508 | wave3length = listofCandidateWave123[i]['z'][3] - listofCandidateWave123[i]['z'][2] 509 | for j in range(startSearchIndex, len(x)): 510 | # wave 4 is a fall and point should at around 1.618 and wave 4 must not fall below the end of wave 1 511 | if x[j] < listofCandidateWave123[i]['x'][3] and z[j] - listofCandidateWave123[i]['z'][3] <= timeInterval and \ 512 | x[j] > listofCandidateWave123[i]['x'][1] and z[j] - listofCandidateWave123[i]['z'][ 513 | 3] <= wave3length and wave4_fibonacci_check(x[j], listofCandidateWave123[i]['x'][2], 514 | listofCandidateWave123[i]['x'][3]): 515 | currWave = copy.deepcopy(listofCandidateWave123[i]) 516 | currWave['x'].append(x[j]) 517 | currWave['z'].append(z[j]) 518 | currWave['searchIndex'] = j 519 | listofCandidateWave1234.append(currWave) 520 | 521 | # end 522 | # end 523 | # end 524 | 525 | print(len(listofCandidateWave1234)) 526 | print('successfully filter out candidate wave1234') 527 | 528 | listofCandidateWave12345 = [] 529 | for i in range(len(listofCandidateWave1234)): 530 | startSearchIndex = listofCandidateWave1234[i]['searchIndex'] 531 | # forth point should be within 01.618+-5%? we take 1.618+*1.05=0.4011 532 | timeInterval = (listofCandidateWave1234[i]['z'][1] - listofCandidateWave1234[i]['z'][0]) * 1.6989 533 | wave3length = listofCandidateWave1234[i]['z'][3] - listofCandidateWave1234[i]['z'][2] 534 | for j in range(startSearchIndex, len(x)): 535 | # wave 4 is a fall and point should at around 1.618 and wave 4 must not fall below the end of wave 1 536 | if x[j] > listofCandidateWave1234[i]['x'][4] and z[j] - listofCandidateWave1234[i]['z'][ 537 | 4] <= timeInterval and z[j] - listofCandidateWave1234[i]['z'][ 538 | 4] <= wave3length and wave5_fibonacci_check(x[j], listofCandidateWave1234[i]['x'][0], 539 | listofCandidateWave1234[i]['x'][1], 540 | listofCandidateWave1234[i]['x'][2], 541 | listofCandidateWave1234[i]['x'][3], 542 | listofCandidateWave1234[i]['x'][4]): 543 | currWave = copy.deepcopy(listofCandidateWave1234[i]) 544 | currWave['x'].append(x[j]) 545 | currWave['z'].append(z[j]) 546 | currWave['searchIndex'] = j 547 | listofCandidateWave12345.append(currWave) 548 | 549 | # end 550 | # end 551 | # end 552 | print(len(listofCandidateWave12345)) 553 | print('successfully filter out candidate wave12345') 554 | return listofCandidateWave12345 555 | 556 | 557 | ######################################## 558 | ############################################## 559 | def Traditional_ElliottWave_label_downward(data): 560 | v = data 561 | j = range(len(data)) 562 | x = [] 563 | z = [] 564 | b = [] 565 | # finding the high point and low point 566 | for i in range(1, len(v) - 1): 567 | if (v[i] <= v[i + 1] and v[i - 1] >= v[i]) or (v[i] >= v[i + 1] and v[i - 1] <= v[i]): 568 | # finding peaks and valleys and then place in a new matrix 569 | x.append(v[i]) 570 | z.append(j[i]) 571 | 572 | diff4x = diff(x) 573 | diff4x.insert(0, 1) 574 | 575 | diff4z = diff(x) 576 | diff4z.insert(0, 1) 577 | 578 | x = trimming(x, otherThan(diff4x, otherthan=0)) 579 | z = trimming(z, otherThan(diff4z, otherthan=0)) 580 | 581 | b = [x, z] 582 | # end 583 | # end 584 | # for each point find the first wave 585 | listofCandidateWave = [] 586 | for i in range(len(x)): 587 | for j in range(len(x)): 588 | if x[i] > x[j]: 589 | wave = { 590 | 'x': [x[i], x[j]], 591 | 'z': [z[i], z[j]], 592 | 'searchIndex': j, 593 | } 594 | listofCandidateWave.append(wave) 595 | # end 596 | # end 597 | # end 598 | 599 | print(len(listofCandidateWave)) 600 | print('successfully filter out candidate wave') 601 | 602 | listofCandidateWave12 = [] 603 | 604 | for i in range(len(listofCandidateWave)): 605 | startSearchIndex = listofCandidateWave[i]['searchIndex'] 606 | # third point should be within 0.382+-5%? we take 0.382+*1.05=0.4011 607 | # timeInterval=(listofCandidateWave[i]['z'][1]-listofCandidateWave[i]['z'][0])*0.4011 608 | for j in range(startSearchIndex, len(x)): 609 | # wave 2 is a drop and wave 2 drop destination is higher than start of wave 1 610 | if x[j] > listofCandidateWave[i]['x'][1] and x[j] < listofCandidateWave[i]['x'][ 611 | 0] and wave2_fibonacci_check(x[j], listofCandidateWave[i]['x'][0], listofCandidateWave[i]['x'][1]): 612 | currWave = copy.deepcopy(listofCandidateWave[i]) 613 | currWave['x'].append(x[j]) 614 | currWave['z'].append(z[j]) 615 | currWave['searchIndex'] = j 616 | listofCandidateWave12.append(currWave) 617 | 618 | # end 619 | # end 620 | # end 621 | print(len(listofCandidateWave12)) 622 | print('successfully filter out candidate wave 12') 623 | listofCandidateWave123 = [] 624 | for i in range(len(listofCandidateWave12)): 625 | startSearchIndex = listofCandidateWave12[i]['searchIndex'] 626 | # forth point should be within 1.618+-5%? we take 1.618+*1.05=1.6989 627 | # timeInterval=(listofCandidateWave12[i]['z'][1]-listofCandidateWave12[i]['z'][0])*1.6989 628 | for j in range(startSearchIndex, len(x)): 629 | # wave 3 is a rise and wave 3 must be the longest wave 630 | if x[j] < listofCandidateWave12[i]['x'][2] and z[j] - listofCandidateWave12[i]['z'][2] >= \ 631 | listofCandidateWave12[i]['z'][1] - listofCandidateWave12[i]['z'][0] and z[j] - \ 632 | listofCandidateWave12[i]['z'][2] >= listofCandidateWave12[i]['z'][2] - \ 633 | listofCandidateWave12[i]['z'][1] and wave3_fibonacci_check(x[j], listofCandidateWave12[i]['x'][1], 634 | listofCandidateWave12[i]['x'][2]): 635 | currWave = copy.deepcopy(listofCandidateWave12[i]) 636 | currWave['x'].append(x[j]) 637 | currWave['z'].append(z[j]) 638 | currWave['searchIndex'] = j 639 | listofCandidateWave123.append(currWave) 640 | 641 | # end 642 | # end 643 | # end 644 | print(len(listofCandidateWave123)) 645 | print('successfully filter out candidate wave123') 646 | 647 | listofCandidateWave1234 = [] 648 | for i in range(len(listofCandidateWave123)): 649 | startSearchIndex = listofCandidateWave123[i]['searchIndex'] 650 | # forth point should be within 0.382+-5%? we take 0.382+*1.05=0.4011 651 | timeInterval = (listofCandidateWave123[i]['z'][1] - listofCandidateWave123[i]['z'][0]) * 0.4011 652 | wave3length = listofCandidateWave123[i]['z'][3] - listofCandidateWave123[i]['z'][2] 653 | for j in range(startSearchIndex, len(x)): 654 | # wave 4 is a fall and wave 4 must not fall below the end of wave 1 655 | if x[j] > listofCandidateWave123[i]['x'][3] and z[j] - listofCandidateWave123[i]['z'][3] <= timeInterval and \ 656 | x[j] > listofCandidateWave123[i]['x'][1] and z[j] - listofCandidateWave123[i]['z'][ 657 | 3] <= wave3length and wave4_fibonacci_check(x[j], listofCandidateWave123[i]['x'][2], 658 | listofCandidateWave123[i]['x'][3]): 659 | currWave = copy.deepcopy(listofCandidateWave123[i]) 660 | currWave['x'].append(x[j]) 661 | currWave['z'].append(z[j]) 662 | currWave['searchIndex'] = j 663 | listofCandidateWave1234.append(currWave) 664 | 665 | # end 666 | # end 667 | # end 668 | 669 | print(len(listofCandidateWave1234)) 670 | print('successfully filter out candidate wave1234') 671 | 672 | listofCandidateWave12345 = [] 673 | for i in range(len(listofCandidateWave1234)): 674 | startSearchIndex = listofCandidateWave1234[i]['searchIndex'] 675 | # forth point should be within 01.618+-5%? we take 1.618+*1.05=0.4011 676 | timeInterval = (listofCandidateWave1234[i]['z'][1] - listofCandidateWave1234[i]['z'][0]) * 1.6989 677 | wave3length = listofCandidateWave1234[i]['z'][3] - listofCandidateWave1234[i]['z'][2] 678 | for j in range(startSearchIndex, len(x)): 679 | # wave 4 is a fall and point should at around 1.618 and wave 4 must not fall below the end of wave 1 680 | if x[j] < listofCandidateWave1234[i]['x'][4] and z[j] - listofCandidateWave1234[i]['z'][ 681 | 4] <= timeInterval and z[j] - listofCandidateWave1234[i]['z'][ 682 | 4] <= wave3length and wave5_fibonacci_check(x[j], listofCandidateWave1234[i]['x'][0], 683 | listofCandidateWave1234[i]['x'][1], 684 | listofCandidateWave1234[i]['x'][2], 685 | listofCandidateWave1234[i]['x'][3], 686 | listofCandidateWave1234[i]['x'][4]): 687 | currWave = copy.deepcopy(listofCandidateWave1234[i]) 688 | currWave['x'].append(x[j]) 689 | currWave['z'].append(z[j]) 690 | currWave['searchIndex'] = j 691 | listofCandidateWave12345.append(currWave) 692 | 693 | # end 694 | # end 695 | # end 696 | print(len(listofCandidateWave12345)) 697 | print('successfully filter out candidate wave12345') 698 | return listofCandidateWave12345 699 | ######################################## 700 | ############################################## 701 | def Practical_ElliottWave3_label_upward(data): 702 | v = data 703 | j = range(len(data)) 704 | x = [] 705 | z = [] 706 | b = [] 707 | # finding the high point and low point 708 | for i in range(1, len(v) - 1): 709 | if (v[i] <= v[i + 1] and v[i - 1] >= v[i]) or (v[i] >= v[i + 1] and v[i - 1] <= v[i]): 710 | # finding peaks and valleys and then place in a new matrix 711 | x.append(v[i]) 712 | z.append(j[i]) 713 | 714 | diff4x = diff(x) 715 | diff4x.insert(0, 1) 716 | 717 | diff4z = diff(x) 718 | diff4z.insert(0, 1) 719 | 720 | x = trimming(x, otherThan(diff4x, otherthan=0)) 721 | z = trimming(z, otherThan(diff4z, otherthan=0)) 722 | 723 | b = [x, z] 724 | # end 725 | # end 726 | # for each point find the first wave 727 | listofCandidateWave = [] 728 | for i in range(len(x)): 729 | for j in range(len(x)): 730 | if x[i] < x[j]: 731 | wave = { 732 | 'x': [x[i], x[j]], 733 | 'z': [z[i], z[j]], 734 | 'searchIndex': j, 735 | } 736 | listofCandidateWave.append(wave) 737 | # end 738 | # end 739 | # end 740 | 741 | print(len(listofCandidateWave)) 742 | print('successfully filter out candidate wave') 743 | 744 | listofCandidateWave12 = [] 745 | 746 | for i in range(len(listofCandidateWave)): 747 | startSearchIndex = listofCandidateWave[i]['searchIndex'] 748 | # third point should be within 0.382+-5%? we take 0.382+*1.05=0.4011 749 | timeInterval = (listofCandidateWave[i]['z'][1] - listofCandidateWave[i]['z'][0]) * 0.4011 750 | for j in range(startSearchIndex, len(x)): 751 | # wave 2 is a drop and point should at around 0.382 and wave 2 drop destination is higher than start of wave 1 752 | if x[j] < listofCandidateWave[i]['x'][1] and z[j] - listofCandidateWave[i]['z'][1] <= timeInterval and x[ 753 | j] > listofCandidateWave[i]['x'][0] and wave2_fibonacci_check(x[j], listofCandidateWave[i]['x'][0], 754 | listofCandidateWave[i]['x'][1]): 755 | currWave = copy.deepcopy(listofCandidateWave[i]) 756 | currWave['x'].append(x[j]) 757 | currWave['z'].append(z[j]) 758 | currWave['searchIndex'] = j 759 | listofCandidateWave12.append(currWave) 760 | 761 | # end 762 | # end 763 | # end 764 | print(len(listofCandidateWave12)) 765 | print('successfully filter out candidate wave 12') 766 | return listofCandidateWave12 767 | 768 | 769 | ######################################## 770 | ############################################## 771 | def Practical_ElliottWave4_label_downward(data): 772 | v = data 773 | j = range(len(data)) 774 | x = [] 775 | z = [] 776 | b = [] 777 | # finding the high point and low point 778 | for i in range(1, len(v) - 1): 779 | if (v[i] <= v[i + 1] and v[i - 1] >= v[i]) or (v[i] >= v[i + 1] and v[i - 1] <= v[i]): 780 | # finding peaks and valleys and then place in a new matrix 781 | x.append(v[i]) 782 | z.append(j[i]) 783 | 784 | diff4x = diff(x) 785 | diff4x.insert(0, 1) 786 | 787 | diff4z = diff(x) 788 | diff4z.insert(0, 1) 789 | 790 | x = trimming(x, otherThan(diff4x, otherthan=0)) 791 | z = trimming(z, otherThan(diff4z, otherthan=0)) 792 | 793 | b = [x, z] 794 | # end 795 | # end 796 | # for each point find the first wave 797 | listofCandidateWave = [] 798 | for i in range(len(x)): 799 | for j in range(len(x)): 800 | if x[i] > x[j]: 801 | wave = { 802 | 'x': [x[i], x[j]], 803 | 'z': [z[i], z[j]], 804 | 'searchIndex': j, 805 | } 806 | listofCandidateWave.append(wave) 807 | # end 808 | # end 809 | # end 810 | 811 | print(len(listofCandidateWave)) 812 | print('successfully filter out candidate wave') 813 | 814 | listofCandidateWave12 = [] 815 | 816 | for i in range(len(listofCandidateWave)): 817 | startSearchIndex = listofCandidateWave[i]['searchIndex'] 818 | # third point should be within 0.382+-5%? we take 0.382+*1.05=0.4011 819 | timeInterval = (listofCandidateWave[i]['z'][1] - listofCandidateWave[i]['z'][0]) * 0.4011 820 | for j in range(startSearchIndex, len(x)): 821 | # wave 2 is a drop and point should at around 0.382 and wave 2 drop destination is higher than start of wave 1 822 | if x[j] > listofCandidateWave[i]['x'][1] and z[j] - listofCandidateWave[i]['z'][1] <= timeInterval and x[ 823 | j] < listofCandidateWave[i]['x'][0] and wave2_fibonacci_check(x[j], listofCandidateWave[i]['x'][0], 824 | listofCandidateWave[i]['x'][1]): 825 | currWave = copy.deepcopy(listofCandidateWave[i]) 826 | currWave['x'].append(x[j]) 827 | currWave['z'].append(z[j]) 828 | currWave['searchIndex'] = j 829 | listofCandidateWave12.append(currWave) 830 | 831 | # end 832 | # end 833 | # end 834 | print(len(listofCandidateWave12)) 835 | print('successfully filter out candidate wave 12') 836 | listofCandidateWave123 = [] 837 | for i in range(len(listofCandidateWave12)): 838 | startSearchIndex = listofCandidateWave12[i]['searchIndex'] 839 | # forth point should be within 1.618+-5%? we take 1.618+*1.05=1.6989 840 | timeInterval = (listofCandidateWave12[i]['z'][1] - listofCandidateWave12[i]['z'][0]) * 1.6989 841 | for j in range(startSearchIndex, len(x)): 842 | # wave 3 is a rise and point should at around 1.618 and wave 3 must be the longest wave 843 | if x[j] < listofCandidateWave12[i]['x'][2] and z[j] - listofCandidateWave12[i]['z'][2] <= timeInterval and \ 844 | z[j] - listofCandidateWave12[i]['z'][2] >= listofCandidateWave12[i]['z'][1] - \ 845 | listofCandidateWave12[i]['z'][0] and z[j] - listofCandidateWave12[i]['z'][2] >= \ 846 | listofCandidateWave12[i]['z'][2] - listofCandidateWave12[i]['z'][1] and wave3_fibonacci_check(x[j], 847 | listofCandidateWave12[ 848 | i][ 849 | 'x'][ 850 | 1], 851 | listofCandidateWave12[ 852 | i][ 853 | 'x'][ 854 | 2]): 855 | currWave = copy.deepcopy(listofCandidateWave12[i]) 856 | currWave['x'].append(x[j]) 857 | currWave['z'].append(z[j]) 858 | currWave['searchIndex'] = j 859 | listofCandidateWave123.append(currWave) 860 | 861 | # end 862 | # end 863 | # end 864 | print(len(listofCandidateWave123)) 865 | print('successfully filter out candidate wave123') 866 | return listofCandidateWave123 867 | ######################################## 868 | ############################################## 869 | def Practical_ElliottWave5_label_upward(data): 870 | v = data 871 | j = range(len(data)) 872 | x = [] 873 | z = [] 874 | b = [] 875 | # finding the high point and low point 876 | for i in range(1, len(v) - 1): 877 | if (v[i] <= v[i + 1] and v[i - 1] >= v[i]) or (v[i] >= v[i + 1] and v[i - 1] <= v[i]): 878 | # finding peaks and valleys and then place in a new matrix 879 | x.append(v[i]) 880 | z.append(j[i]) 881 | 882 | diff4x = diff(x) 883 | diff4x.insert(0, 1) 884 | 885 | diff4z = diff(x) 886 | diff4z.insert(0, 1) 887 | 888 | x = trimming(x, otherThan(diff4x, otherthan=0)) 889 | z = trimming(z, otherThan(diff4z, otherthan=0)) 890 | 891 | b = [x, z] 892 | # end 893 | # end 894 | # for each point find the first wave 895 | listofCandidateWave = [] 896 | for i in range(len(x)): 897 | for j in range(len(x)): 898 | if x[i] < x[j]: 899 | wave = { 900 | 'x': [x[i], x[j]], 901 | 'z': [z[i], z[j]], 902 | 'searchIndex': j, 903 | } 904 | listofCandidateWave.append(wave) 905 | # end 906 | # end 907 | # end 908 | 909 | print(len(listofCandidateWave)) 910 | print('successfully filter out candidate wave') 911 | 912 | listofCandidateWave12 = [] 913 | 914 | for i in range(len(listofCandidateWave)): 915 | startSearchIndex = listofCandidateWave[i]['searchIndex'] 916 | # third point should be within 0.382+-5%? we take 0.382+*1.05=0.4011 917 | timeInterval = (listofCandidateWave[i]['z'][1] - listofCandidateWave[i]['z'][0]) * 0.4011 918 | for j in range(startSearchIndex, len(x)): 919 | # wave 2 is a drop and point should at around 0.382 and wave 2 drop destination is higher than start of wave 1 920 | if x[j] < listofCandidateWave[i]['x'][1] and z[j] - listofCandidateWave[i]['z'][1] <= timeInterval and x[ 921 | j] > listofCandidateWave[i]['x'][0] and wave2_fibonacci_check(x[j], listofCandidateWave[i]['x'][0], 922 | listofCandidateWave[i]['x'][1]): 923 | currWave = copy.deepcopy(listofCandidateWave[i]) 924 | currWave['x'].append(x[j]) 925 | currWave['z'].append(z[j]) 926 | currWave['searchIndex'] = j 927 | listofCandidateWave12.append(currWave) 928 | 929 | # end 930 | # end 931 | # end 932 | print(len(listofCandidateWave12)) 933 | print('successfully filter out candidate wave 12') 934 | listofCandidateWave123 = [] 935 | for i in range(len(listofCandidateWave12)): 936 | startSearchIndex = listofCandidateWave12[i]['searchIndex'] 937 | # forth point should be within 1.618+-5%? we take 1.618+*1.05=1.6989 938 | timeInterval = (listofCandidateWave12[i]['z'][1] - listofCandidateWave12[i]['z'][0]) * 1.6989 939 | for j in range(startSearchIndex, len(x)): 940 | # wave 3 is a rise and point should at around 1.618 and wave 3 must be the longest wave 941 | if x[j] > listofCandidateWave12[i]['x'][2] and z[j] - listofCandidateWave12[i]['z'][2] <= timeInterval and \ 942 | z[j] - listofCandidateWave12[i]['z'][2] >= listofCandidateWave12[i]['z'][1] - \ 943 | listofCandidateWave12[i]['z'][0] and z[j] - listofCandidateWave12[i]['z'][2] >= \ 944 | listofCandidateWave12[i]['z'][2] - listofCandidateWave12[i]['z'][1] and wave3_fibonacci_check(x[j], 945 | listofCandidateWave12[ 946 | i][ 947 | 'x'][ 948 | 1], 949 | listofCandidateWave12[ 950 | i][ 951 | 'x'][ 952 | 2]): 953 | currWave = copy.deepcopy(listofCandidateWave12[i]) 954 | currWave['x'].append(x[j]) 955 | currWave['z'].append(z[j]) 956 | currWave['searchIndex'] = j 957 | listofCandidateWave123.append(currWave) 958 | 959 | # end 960 | # end 961 | # end 962 | print(len(listofCandidateWave123)) 963 | print('successfully filter out candidate wave123') 964 | 965 | listofCandidateWave1234 = [] 966 | for i in range(len(listofCandidateWave123)): 967 | startSearchIndex = listofCandidateWave123[i]['searchIndex'] 968 | # forth point should be within 0.382+-5%? we take 0.382+*1.05=0.4011 969 | timeInterval = (listofCandidateWave123[i]['z'][1] - listofCandidateWave123[i]['z'][0]) * 0.4011 970 | wave3length = listofCandidateWave123[i]['z'][3] - listofCandidateWave123[i]['z'][2] 971 | for j in range(startSearchIndex, len(x)): 972 | # wave 4 is a fall and point should at around 1.618 and wave 4 must not fall below the end of wave 1 973 | if x[j] < listofCandidateWave123[i]['x'][3] and z[j] - listofCandidateWave123[i]['z'][3] <= timeInterval and \ 974 | x[j] > listofCandidateWave123[i]['x'][1] and z[j] - listofCandidateWave123[i]['z'][ 975 | 3] <= wave3length and wave4_fibonacci_check(x[j], listofCandidateWave123[i]['x'][2], 976 | listofCandidateWave123[i]['x'][3]): 977 | currWave = copy.deepcopy(listofCandidateWave123[i]) 978 | currWave['x'].append(x[j]) 979 | currWave['z'].append(z[j]) 980 | currWave['searchIndex'] = j 981 | listofCandidateWave1234.append(currWave) 982 | 983 | # end 984 | # end 985 | # end 986 | 987 | print(len(listofCandidateWave1234)) 988 | print('successfully filter out candidate wave1234') 989 | 990 | return listofCandidateWave1234 991 | ######################################## 992 | -------------------------------------------------------------------------------- /dist/taew-0.0.1-py3-none-any.whl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrEdwardPCB/python-taew/e94d044684d8c628cd9b0dd246e162ead1ca025d/dist/taew-0.0.1-py3-none-any.whl -------------------------------------------------------------------------------- /dist/taew-0.0.1.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrEdwardPCB/python-taew/e94d044684d8c628cd9b0dd246e162ead1ca025d/dist/taew-0.0.1.tar.gz -------------------------------------------------------------------------------- /dist/taew-0.0.2-py3-none-any.whl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrEdwardPCB/python-taew/e94d044684d8c628cd9b0dd246e162ead1ca025d/dist/taew-0.0.2-py3-none-any.whl -------------------------------------------------------------------------------- /dist/taew-0.0.2.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrEdwardPCB/python-taew/e94d044684d8c628cd9b0dd246e162ead1ca025d/dist/taew-0.0.2.tar.gz -------------------------------------------------------------------------------- /dist/taew-0.0.3-py3-none-any.whl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrEdwardPCB/python-taew/e94d044684d8c628cd9b0dd246e162ead1ca025d/dist/taew-0.0.3-py3-none-any.whl -------------------------------------------------------------------------------- /dist/taew-0.0.3.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrEdwardPCB/python-taew/e94d044684d8c628cd9b0dd246e162ead1ca025d/dist/taew-0.0.3.tar.gz -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | ## taew 2 | 3 | this is a package that targets at technical analysis using Elliott wave. 4 | currently providing python implementation for back tracking elliott wave 5 | base on the method and Matlab code on the paper [ **Profitability of Elliott Waves and Fibonacci Retracement Levels in the Foreign Exchange Market 6 | ** ](http://arno.uvt.nl/show.cgi?fid=131569) 7 | 8 | ### motivation 9 | since there are no opensource elliott wave labelling package. to facilitate the private project that me and my friend currently working on, this library is created. 10 | 11 | ### installation 12 | ``` 13 | pip install taew 14 | ``` 15 | 16 | ### list of main method 17 | 18 | listed methods are for the labelling of elliott wave 19 | 20 | ```python 21 | def Alternative_ElliottWave_label_upward(data:list[number])->list[dict]: 22 | #identify full elliott impulse wave from a list of price, the wave will fits the fibonacci retracement and also fibonacci timezone for upward impulse wave 23 | 24 | def Alternative_ElliottWave_label_downward(data:list[number])->list[dict]: 25 | #identify full elliott impulse wave from a list of price, the wave will fits the fibonacci retracement and also fibonacci timezone for downward impulse wave 26 | 27 | def Traditional_ElliottWave_label_upward(data:list[number])->list[dict]: 28 | #identify full elliott impulse wave from a list of price, the wave will fits the fibonacci retracement for upward impulse wave 29 | 30 | def Traditional_ElliottWave_label_downward(data:list[number])->list[dict]: 31 | #identify full elliott impulse wave from a list of price, the wave will fits the fibonacci retracement for downward impulse wave 32 | 33 | def Practical_ElliottWave3_label_upward(data:list[number])->list[dict]: 34 | #identify the first 2 wave of all the candidate upward elliott wave from the data, good predictor of 3rd upward impulse wave 35 | 36 | def Practical_ElliottWave3_label_downward(data:list[number])->list[dict]: 37 | #identify the first 3 wave of all the candidate downward elliott wave from the data, good predictor of 4th upward impulse wave 38 | 39 | def Practical_ElliottWave5_label_upward(data:list[number])->list[dict]: 40 | #identify the first 4 wave of all the candidate upward elliott wave from the data, good predictor of 5tth upward impulse wave 41 | 42 | ``` 43 | ### list of helper method 44 | listed methods are for helping the identification of the labelling, if you try to create your own application of elliott wave labelling, this may help you 45 | 46 | ```python 47 | def wave2_fibonacci_check(wave2_end, wave1_start, wave1_end): 48 | # check whether wave 2 satisfy principal of fibonacci retracement 49 | def wave3_fibonacci_check(wave3_end, wave2_start, wave2_end): 50 | # check whether wave 3 satisfy principal of fibonacci retracement 51 | def wave4_fibonacci_check(wave4_end, wave3_start, wave3_end): 52 | # check whether wave 4 satisfy principal of fibonacci retracement 53 | def wave5_fibonacci_check(wave5_end, wave1_start, wave1_end, wave3_start, wave3_end, wave4_end): 54 | #check whether wave 5 satisfy principal of fibonacci retracement 55 | def diff(data:list[number])->list[number]: 56 | #similar to diff in matlab, for nth num in list return nth - n-1th 57 | def otherThan(data:list[any], otherthan=any)->list[bool]: 58 | #similar to ~= in matlab means if list item=otherthan, output list on that pos will be false otherwise will be true 59 | def trimming(data:list[number], determineArray:list[bool])->list[number]: 60 | #trim out data base on the determine array 61 | ``` 62 | ### example usage 63 | 64 | #### demo code 65 | ```python 66 | import pandas as pd 67 | import numpy as np 68 | import taew 69 | import pandas_datareader.data as web 70 | import datetime 71 | 72 | start = datetime.datetime(2019, 1, 1) 73 | end = datetime.datetime(2020, 1, 27) 74 | 75 | SP500 = web.DataReader(['sp500'], 'fred', start, end) 76 | 77 | haha=taew.Alternative_ElliottWave_label_upward(np.array(SP500[['sp500']].values , dtype=np.double).flatten(order='C')) 78 | print(haha) 79 | ``` 80 | #### expected output 81 | ```python 82 | ''' 83 | 6555 84 | successfully filter out candidate wave 85 | 6519 86 | successfully filter out candidate wave 12 87 | 11210 88 | successfully filter out candidate wave123 89 | 8566 90 | successfully filter out candidate wave1234 91 | 70380 92 | successfully filter out candidate wave12345 93 | 94 | [{'x': [2447.89, 2796.11, 2743.07, 2917.52, 2870.72, 2954.18], 95 | 'z': [2, 39, 48, 87, 92, 122], 96 | 'searchIndex': 48}, 97 | {'x': [2447.89, 2796.11, 2743.07, 2917.52, 2811.87, 2954.18], 98 | 'z': [2, 39, 48, 87, 94, 122], 99 | 'searchIndex': 48},...] 100 | ''' 101 | ``` 102 | ####explaination of output 103 | 104 | from the matlab code of original paper it first extract the high point and low point of the price curve. after that performing pattern recognization. However it makes an assumption that the array of high and low point that resemble elliott wave are all in a row. This is not the case in actual market. therefore his code fails to recognize Elliott wave in real markets. Even it can, it requires denoise or filterring with SMA or EMA. 105 | 106 | this code does not use his approach. it uses a iterative approach to first identify all possible wave 1 in the graph then find valid wave 2 and repeatedly until wave 5 has found.although the computation time is long, it can shows elliott wave of different sizes. Denoise and filter are not required. 107 | 108 | for each main method, it returns a list of dict, each dict is an Elliott wave identified. 109 | 110 | * 'x' : price level of all elliot wave point 111 | * 'z' : position(a.k.a. index) of price level in the list of data 112 | * searchIndex: maynot be useful for user, but useful for the stepwise algorithm to keep track of what to search next in its internal list 113 | 114 | 115 | ### disclaimer 116 | this library does not guarentee correct identification of all elliott wave, user use this to earn money from any market should bear their own risk. Author will not bear any risk(s) or benefit(s) if user of this library lose any money or earn any money respectively -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | import setuptools 2 | 3 | with open("README.md",'r') as fh: 4 | long_description=fh.read() 5 | setuptools.setup( 6 | name="taew", 7 | version="0.0.3", 8 | author="Edward Wong", 9 | author_email="eternal.edward1997@gmail.com", 10 | long_description=long_description, 11 | long_description_content_type='text/markdown', 12 | url='', 13 | packages=setuptools.find_packages(), 14 | classifier=[ 15 | "Programming Language :: Python :: 3", 16 | "License :: OSI Approved :: MIT License", 17 | "Operating System :: OS Independent" 18 | ], 19 | python_requires='>= 3.7' 20 | ) -------------------------------------------------------------------------------- /taew.egg-info/PKG-INFO: -------------------------------------------------------------------------------- 1 | Metadata-Version: 2.1 2 | Name: taew 3 | Version: 0.0.3 4 | Summary: UNKNOWN 5 | Home-page: UNKNOWN 6 | Author: Edward Wong 7 | Author-email: eternal.edward1997@gmail.com 8 | License: UNKNOWN 9 | Description: ## taew 10 | 11 | this is a package that targets at technical analysis using Elliott wave. 12 | currently providing python implementation for back tracking elliott wave 13 | base on the method and Matlab code on the paper [ **Profitability of Elliott Waves and Fibonacci Retracement Levels in the Foreign Exchange Market 14 | ** ](http://arno.uvt.nl/show.cgi?fid=131569) 15 | 16 | ### motivation 17 | since there are no opensource elliott wave labelling package. to facilitate the private project that me and my friend currently working on, this library is created. 18 | 19 | ### installation 20 | ``` 21 | pip install taew 22 | ``` 23 | 24 | ### list of main method 25 | 26 | listed methods are for the labelling of elliott wave 27 | 28 | ```python 29 | def Alternative_ElliottWave_label_upward(data:list[number])->list[dict]: 30 | #identify full elliott impulse wave from a list of price, the wave will fits the fibonacci retracement and also fibonacci timezone for upward impulse wave 31 | 32 | def Alternative_ElliottWave_label_downward(data:list[number])->list[dict]: 33 | #identify full elliott impulse wave from a list of price, the wave will fits the fibonacci retracement and also fibonacci timezone for downward impulse wave 34 | 35 | def Traditional_ElliottWave_label_upward(data:list[number])->list[dict]: 36 | #identify full elliott impulse wave from a list of price, the wave will fits the fibonacci retracement for upward impulse wave 37 | 38 | def Traditional_ElliottWave_label_downward(data:list[number])->list[dict]: 39 | #identify full elliott impulse wave from a list of price, the wave will fits the fibonacci retracement for downward impulse wave 40 | 41 | def Practical_ElliottWave3_label_upward(data:list[number])->list[dict]: 42 | #identify the first 2 wave of all the candidate upward elliott wave from the data, good predictor of 3rd upward impulse wave 43 | 44 | def Practical_ElliottWave3_label_downward(data:list[number])->list[dict]: 45 | #identify the first 3 wave of all the candidate downward elliott wave from the data, good predictor of 4th upward impulse wave 46 | 47 | def Practical_ElliottWave5_label_upward(data:list[number])->list[dict]: 48 | #identify the first 4 wave of all the candidate upward elliott wave from the data, good predictor of 5tth upward impulse wave 49 | 50 | ``` 51 | ### list of helper method 52 | listed methods are for helping the identification of the labelling, if you try to create your own application of elliott wave labelling, this may help you 53 | 54 | ```python 55 | def wave2_fibonacci_check(wave2_end, wave1_start, wave1_end): 56 | # check whether wave 2 satisfy principal of fibonacci retracement 57 | def wave3_fibonacci_check(wave3_end, wave2_start, wave2_end): 58 | # check whether wave 3 satisfy principal of fibonacci retracement 59 | def wave4_fibonacci_check(wave4_end, wave3_start, wave3_end): 60 | # check whether wave 4 satisfy principal of fibonacci retracement 61 | def wave5_fibonacci_check(wave5_end, wave1_start, wave1_end, wave3_start, wave3_end, wave4_end): 62 | #check whether wave 5 satisfy principal of fibonacci retracement 63 | def diff(data:list[number])->list[number]: 64 | #similar to diff in matlab, for nth num in list return nth - n-1th 65 | def otherThan(data:list[any], otherthan=any)->list[bool]: 66 | #similar to ~= in matlab means if list item=otherthan, output list on that pos will be false otherwise will be true 67 | def trimming(data:list[number], determineArray:list[bool])->list[number]: 68 | #trim out data base on the determine array 69 | ``` 70 | ### example usage 71 | 72 | #### demo code 73 | ```python 74 | import pandas as pd 75 | import numpy as np 76 | import taew 77 | import pandas_datareader.data as web 78 | import datetime 79 | 80 | start = datetime.datetime(2019, 1, 1) 81 | end = datetime.datetime(2020, 1, 27) 82 | 83 | SP500 = web.DataReader(['sp500'], 'fred', start, end) 84 | 85 | haha=taew.Alternative_ElliottWave_label_upward(np.array(SP500[['sp500']].values , dtype=np.double).flatten(order='C')) 86 | print(haha) 87 | ``` 88 | #### expected output 89 | ```python 90 | ''' 91 | 6555 92 | successfully filter out candidate wave 93 | 6519 94 | successfully filter out candidate wave 12 95 | 11210 96 | successfully filter out candidate wave123 97 | 8566 98 | successfully filter out candidate wave1234 99 | 70380 100 | successfully filter out candidate wave12345 101 | 102 | [{'x': [2447.89, 2796.11, 2743.07, 2917.52, 2870.72, 2954.18], 103 | 'z': [2, 39, 48, 87, 92, 122], 104 | 'searchIndex': 48}, 105 | {'x': [2447.89, 2796.11, 2743.07, 2917.52, 2811.87, 2954.18], 106 | 'z': [2, 39, 48, 87, 94, 122], 107 | 'searchIndex': 48},...] 108 | ''' 109 | ``` 110 | ####explaination of output 111 | 112 | from the matlab code of original paper it first extract the high point and low point of the price curve. after that performing pattern recognization. However it makes an assumption that the array of high and low point that resemble elliott wave are all in a row. This is not the case in actual market. therefore his code fails to recognize Elliott wave in real markets. Even it can, it requires denoise or filterring with SMA or EMA. 113 | 114 | this code does not use his approach. it uses a iterative approach to first identify all possible wave 1 in the graph then find valid wave 2 and repeatedly until wave 5 has found.although the computation time is long, it can shows elliott wave of different sizes. Denoise and filter are not required. 115 | 116 | for each main method, it returns a list of dict, each dict is an Elliott wave identified. 117 | 118 | * 'x' : price level of all elliot wave point 119 | * 'z' : position(a.k.a. index) of price level in the list of data 120 | * searchIndex: maynot be useful for user, but useful for the stepwise algorithm to keep track of what to search next in its internal list 121 | 122 | 123 | ### disclaimer 124 | this library does not guarentee correct identification of all elliott wave, user use this to earn money from any market should bear their own risk. Author will not bear any risk(s) or benefit(s) if user of this library lose any money or earn any money respectively 125 | Platform: UNKNOWN 126 | Requires-Python: >= 3.7 127 | Description-Content-Type: text/markdown 128 | -------------------------------------------------------------------------------- /taew.egg-info/SOURCES.txt: -------------------------------------------------------------------------------- 1 | LICENSE 2 | setup.py 3 | taew/__init__.py 4 | taew/ew.py 5 | taew.egg-info/PKG-INFO 6 | taew.egg-info/SOURCES.txt 7 | taew.egg-info/dependency_links.txt 8 | taew.egg-info/top_level.txt -------------------------------------------------------------------------------- /taew.egg-info/dependency_links.txt: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /taew.egg-info/top_level.txt: -------------------------------------------------------------------------------- 1 | taew 2 | -------------------------------------------------------------------------------- /taew/__init__.py: -------------------------------------------------------------------------------- 1 | from taew.ew import * -------------------------------------------------------------------------------- /taew/ew.py: -------------------------------------------------------------------------------- 1 | import copy 2 | # numpy 3 | import numpy as np 4 | # pandas 5 | import pandas as pd 6 | 7 | 8 | def wave2_fibonacci_check(wave2_end, wave1_start, wave1_end): 9 | # Wave 2 is typically 50%, 61.8%, 76.4%, or 85.4% of wave 1 10 | wave2_endabs = abs(wave2_end) 11 | wave1_startabs = abs(wave1_start) 12 | wave1_endabs = abs(wave1_end) 13 | fibonacci_ratio = [0.146, 0.236, 0.382, 0.5, 0.618, 0.764, 0.854] 14 | for ratio in fibonacci_ratio: 15 | if wave2_endabs <= (wave1_endabs - (wave1_endabs - wave1_startabs) * ratio) * 1.001 and wave2_endabs >= ( 16 | wave1_endabs - (wave1_endabs - wave1_startabs) * ratio) * 0.995: 17 | return True 18 | # endif 19 | # endfor 20 | return False 21 | 22 | 23 | def wave3_fibonacci_check(wave3_end, wave2_start, wave2_end): 24 | # Wave 3 is typically 161.8% of wave 1 25 | wave3_endabs = abs(wave3_end) 26 | wave2_startabs = abs(wave2_start) 27 | wave2_endabs = abs(wave2_end) 28 | fibonacci_ratio = [1.236, 1.618, 2.00, 2.618, 3.236, 4.236] 29 | for ratio in fibonacci_ratio: 30 | if wave3_endabs <= (wave2_endabs - (wave2_endabs - wave2_startabs) * ratio) * 1.001 and wave3_endabs >= ( 31 | wave2_endabs - (wave2_endabs - wave2_startabs) * ratio) * 0.995: 32 | return True 33 | # endif 34 | # endfor 35 | return False 36 | 37 | 38 | def wave4_fibonacci_check(wave4_end, wave3_start, wave3_end): 39 | # Wave 3 is typically 161.8% of wave 1 40 | wave4_endabs = abs(wave4_end) 41 | wave3_startabs = abs(wave3_start) 42 | wave3_endabs = abs(wave3_end) 43 | fibonacci_ratio = [0.146, 0.236, 0.382, 0.5, 0.618, 0.764, 0.854] 44 | for ratio in fibonacci_ratio: 45 | if wave4_endabs <= (wave3_endabs - (wave3_endabs - wave3_startabs) * ratio) * 1.001 and wave3_endabs >= ( 46 | wave3_endabs - (wave3_endabs - wave3_startabs) * ratio) * 0.995: 47 | return True 48 | # endif 49 | # endfor 50 | return False 51 | 52 | 53 | def wave5_fibonacci_check(wave5_end, wave1_start, wave1_end, wave3_start, wave3_end, wave4_end): 54 | wave5_endabs = abs(wave5_end) 55 | wave1_startabs = abs(wave1_start) 56 | wave1_endabs = abs(wave1_end) 57 | wave3_startabs = abs(wave3_start) 58 | wave3_endabs = abs(wave3_end) 59 | wave4_endabs = abs(wave4_end) 60 | 61 | wave5_y = wave5_endabs - wave4_endabs 62 | wave1_y = wave1_endabs - wave1_startabs 63 | wave4_y = abs(wave4_endabs - wave3_endabs) 64 | wave1plus3_y = wave1_y + (wave3_endabs - wave3_startabs) 65 | if wave5_y >= wave4_y and wave5_y <= (wave4_y * 2): 66 | return True 67 | if wave5_y >= wave1_y * 0.95 and wave5_y <= wave1_y * 1.05: 68 | return True 69 | fibonacci_ratio = [0.382, 0.618, 0.764] 70 | for ratio in fibonacci_ratio: 71 | if wave5_y <= wave1plus3_y * ratio * 1.05 and wave5_y >= wave1plus3_y * ratio * 0.95: 72 | return True 73 | # end 74 | # end 75 | return False 76 | 77 | 78 | def diff(data): 79 | # accept list of any number 80 | output_diff = [] 81 | for i in range(1, len(data)): 82 | output_diff.append((data[i - 1] - data[i])) 83 | # return list of number 84 | return output_diff 85 | 86 | 87 | def otherThan(data, otherthan=0): 88 | # accept list and a anytype option 89 | output_otherthan = [] 90 | for i in range(len(data)): 91 | if data[i] != otherthan: 92 | output_otherthan.append(True) 93 | else: 94 | output_otherthan.append(False) 95 | # return list of boolean 96 | return output_otherthan 97 | 98 | 99 | def trimming(data, determineArray): 100 | # accept list of any type and list of boolean 101 | if len(data) != len(determineArray): 102 | raise Exception('array/list size not equal') 103 | filtered_data = [] 104 | for i in range(len(data)): 105 | if determineArray[i]: 106 | filtered_data.append(data[i]) 107 | return filtered_data 108 | 109 | 110 | ############################################## 111 | def Alternative_ElliottWave_label_upward(data): 112 | v = data 113 | j = range(len(data)) 114 | x = [] 115 | z = [] 116 | b = [] 117 | # finding the high point and low point 118 | for i in range(1, len(v) - 1): 119 | if (v[i] <= v[i + 1] and v[i - 1] >= v[i]) or (v[i] >= v[i + 1] and v[i - 1] <= v[i]): 120 | # finding peaks and valleys and then place in a new matrix 121 | x.append(v[i]) 122 | z.append(j[i]) 123 | 124 | diff4x = diff(x) 125 | diff4x.insert(0, 1) 126 | 127 | diff4z = diff(x) 128 | diff4z.insert(0, 1) 129 | 130 | x = trimming(x, otherThan(diff4x, otherthan=0)) 131 | z = trimming(z, otherThan(diff4z, otherthan=0)) 132 | 133 | b = [x, z] 134 | # end 135 | # end 136 | # for each point find the first wave 137 | listofCandidateWave = [] 138 | for i in range(len(x)): 139 | for j in range(len(x)): 140 | if x[i] < x[j]: 141 | wave = { 142 | 'x': [x[i], x[j]], 143 | 'z': [z[i], z[j]], 144 | 'searchIndex': j, 145 | } 146 | listofCandidateWave.append(wave) 147 | # end 148 | # end 149 | # end 150 | 151 | print(len(listofCandidateWave)) 152 | print('successfully filter out candidate wave') 153 | 154 | listofCandidateWave12 = [] 155 | 156 | for i in range(len(listofCandidateWave)): 157 | startSearchIndex = listofCandidateWave[i]['searchIndex'] 158 | # third point should be within 0.382+-5%? we take 0.382+*1.05=0.4011 159 | timeInterval = (listofCandidateWave[i]['z'][1] - listofCandidateWave[i]['z'][0]) * 0.4011 160 | for j in range(startSearchIndex, len(x)): 161 | # wave 2 is a drop and point should at around 0.382 and wave 2 drop destination is higher than start of wave 1 162 | if x[j] < listofCandidateWave[i]['x'][1] and z[j] - listofCandidateWave[i]['z'][1] <= timeInterval and x[ 163 | j] > listofCandidateWave[i]['x'][0] and wave2_fibonacci_check(x[j], listofCandidateWave[i]['x'][0], 164 | listofCandidateWave[i]['x'][1]): 165 | currWave = copy.deepcopy(listofCandidateWave[i]) 166 | currWave['x'].append(x[j]) 167 | currWave['z'].append(z[j]) 168 | currWave['searchIndex'] = j 169 | listofCandidateWave12.append(currWave) 170 | 171 | # end 172 | # end 173 | # end 174 | print(len(listofCandidateWave12)) 175 | print('successfully filter out candidate wave 12') 176 | listofCandidateWave123 = [] 177 | for i in range(len(listofCandidateWave12)): 178 | startSearchIndex = listofCandidateWave12[i]['searchIndex'] 179 | # forth point should be within 1.618+-5%? we take 1.618+*1.05=1.6989 180 | timeInterval = (listofCandidateWave12[i]['z'][1] - listofCandidateWave12[i]['z'][0]) * 1.6989 181 | for j in range(startSearchIndex, len(x)): 182 | # wave 3 is a rise and point should at around 1.618 and wave 3 must be the longest wave 183 | if x[j] > listofCandidateWave12[i]['x'][2] and z[j] - listofCandidateWave12[i]['z'][2] <= timeInterval and \ 184 | z[j] - listofCandidateWave12[i]['z'][2] >= listofCandidateWave12[i]['z'][1] - \ 185 | listofCandidateWave12[i]['z'][0] and z[j] - listofCandidateWave12[i]['z'][2] >= \ 186 | listofCandidateWave12[i]['z'][2] - listofCandidateWave12[i]['z'][1] and wave3_fibonacci_check(x[j], 187 | listofCandidateWave12[ 188 | i][ 189 | 'x'][ 190 | 1], 191 | listofCandidateWave12[ 192 | i][ 193 | 'x'][ 194 | 2]): 195 | currWave = copy.deepcopy(listofCandidateWave12[i]) 196 | currWave['x'].append(x[j]) 197 | currWave['z'].append(z[j]) 198 | currWave['searchIndex'] = j 199 | listofCandidateWave123.append(currWave) 200 | 201 | # end 202 | # end 203 | # end 204 | print(len(listofCandidateWave123)) 205 | print('successfully filter out candidate wave123') 206 | 207 | listofCandidateWave1234 = [] 208 | for i in range(len(listofCandidateWave123)): 209 | startSearchIndex = listofCandidateWave123[i]['searchIndex'] 210 | # forth point should be within 0.382+-5%? we take 0.382+*1.05=0.4011 211 | timeInterval = (listofCandidateWave123[i]['z'][1] - listofCandidateWave123[i]['z'][0]) * 0.4011 212 | wave3length = listofCandidateWave123[i]['z'][3] - listofCandidateWave123[i]['z'][2] 213 | for j in range(startSearchIndex, len(x)): 214 | # wave 4 is a fall and point should at around 1.618 and wave 4 must not fall below the end of wave 1 215 | if x[j] < listofCandidateWave123[i]['x'][3] and z[j] - listofCandidateWave123[i]['z'][3] <= timeInterval and \ 216 | x[j] > listofCandidateWave123[i]['x'][1] and z[j] - listofCandidateWave123[i]['z'][ 217 | 3] <= wave3length and wave4_fibonacci_check(x[j], listofCandidateWave123[i]['x'][2], 218 | listofCandidateWave123[i]['x'][3]): 219 | currWave = copy.deepcopy(listofCandidateWave123[i]) 220 | currWave['x'].append(x[j]) 221 | currWave['z'].append(z[j]) 222 | currWave['searchIndex'] = j 223 | listofCandidateWave1234.append(currWave) 224 | 225 | # end 226 | # end 227 | # end 228 | 229 | print(len(listofCandidateWave1234)) 230 | print('successfully filter out candidate wave1234') 231 | 232 | listofCandidateWave12345 = [] 233 | for i in range(len(listofCandidateWave1234)): 234 | startSearchIndex = listofCandidateWave1234[i]['searchIndex'] 235 | # forth point should be within 01.618+-5%? we take 1.618+*1.05=0.4011 236 | timeInterval = (listofCandidateWave1234[i]['z'][1] - listofCandidateWave1234[i]['z'][0]) * 1.6989 237 | wave3length = listofCandidateWave1234[i]['z'][3] - listofCandidateWave1234[i]['z'][2] 238 | for j in range(startSearchIndex, len(x)): 239 | # wave 4 is a fall and point should at around 1.618 and wave 4 must not fall below the end of wave 1 240 | if x[j] > listofCandidateWave1234[i]['x'][4] and z[j] - listofCandidateWave1234[i]['z'][ 241 | 4] <= timeInterval and z[j] - listofCandidateWave1234[i]['z'][ 242 | 4] <= wave3length and wave5_fibonacci_check(x[j], listofCandidateWave1234[i]['x'][0], 243 | listofCandidateWave1234[i]['x'][1], 244 | listofCandidateWave1234[i]['x'][2], 245 | listofCandidateWave1234[i]['x'][3], 246 | listofCandidateWave1234[i]['x'][4]): 247 | currWave = copy.deepcopy(listofCandidateWave1234[i]) 248 | currWave['x'].append(x[j]) 249 | currWave['z'].append(z[j]) 250 | currWave['searchIndex'] = j 251 | listofCandidateWave12345.append(currWave) 252 | 253 | # end 254 | # end 255 | # end 256 | print(len(listofCandidateWave12345)) 257 | print('successfully filter out candidate wave12345') 258 | return listofCandidateWave12345 259 | 260 | 261 | ######################################## 262 | ############################################## 263 | def Alternative_ElliottWave_label_downward(data): 264 | v = data 265 | j = range(len(data)) 266 | x = [] 267 | z = [] 268 | b = [] 269 | # finding the high point and low point 270 | for i in range(1, len(v) - 1): 271 | if (v[i] <= v[i + 1] and v[i - 1] >= v[i]) or (v[i] >= v[i + 1] and v[i - 1] <= v[i]): 272 | # finding peaks and valleys and then place in a new matrix 273 | x.append(v[i]) 274 | z.append(j[i]) 275 | 276 | diff4x = diff(x) 277 | diff4x.insert(0, 1) 278 | 279 | diff4z = diff(x) 280 | diff4z.insert(0, 1) 281 | 282 | x = trimming(x, otherThan(diff4x, otherthan=0)) 283 | z = trimming(z, otherThan(diff4z, otherthan=0)) 284 | 285 | b = [x, z] 286 | # end 287 | # end 288 | # for each point find the first wave 289 | listofCandidateWave = [] 290 | for i in range(len(x)): 291 | for j in range(len(x)): 292 | if x[i] > x[j]: 293 | wave = { 294 | 'x': [x[i], x[j]], 295 | 'z': [z[i], z[j]], 296 | 'searchIndex': j, 297 | } 298 | listofCandidateWave.append(wave) 299 | # end 300 | # end 301 | # end 302 | 303 | print(len(listofCandidateWave)) 304 | print('successfully filter out candidate wave') 305 | 306 | listofCandidateWave12 = [] 307 | 308 | for i in range(len(listofCandidateWave)): 309 | startSearchIndex = listofCandidateWave[i]['searchIndex'] 310 | # third point should be within 0.382+-5%? we take 0.382+*1.05=0.4011 311 | timeInterval = (listofCandidateWave[i]['z'][1] - listofCandidateWave[i]['z'][0]) * 0.4011 312 | for j in range(startSearchIndex, len(x)): 313 | # wave 2 is a drop and point should at around 0.382 and wave 2 drop destination is higher than start of wave 1 314 | if x[j] > listofCandidateWave[i]['x'][1] and z[j] - listofCandidateWave[i]['z'][1] <= timeInterval and x[ 315 | j] < listofCandidateWave[i]['x'][0] and wave2_fibonacci_check(x[j], listofCandidateWave[i]['x'][0], 316 | listofCandidateWave[i]['x'][1]): 317 | currWave = copy.deepcopy(listofCandidateWave[i]) 318 | currWave['x'].append(x[j]) 319 | currWave['z'].append(z[j]) 320 | currWave['searchIndex'] = j 321 | listofCandidateWave12.append(currWave) 322 | 323 | # end 324 | # end 325 | # end 326 | print(len(listofCandidateWave12)) 327 | print('successfully filter out candidate wave 12') 328 | listofCandidateWave123 = [] 329 | for i in range(len(listofCandidateWave12)): 330 | startSearchIndex = listofCandidateWave12[i]['searchIndex'] 331 | # forth point should be within 1.618+-5%? we take 1.618+*1.05=1.6989 332 | timeInterval = (listofCandidateWave12[i]['z'][1] - listofCandidateWave12[i]['z'][0]) * 1.6989 333 | for j in range(startSearchIndex, len(x)): 334 | # wave 3 is a rise and point should at around 1.618 and wave 3 must be the longest wave 335 | if x[j] < listofCandidateWave12[i]['x'][2] and z[j] - listofCandidateWave12[i]['z'][2] <= timeInterval and \ 336 | z[j] - listofCandidateWave12[i]['z'][2] >= listofCandidateWave12[i]['z'][1] - \ 337 | listofCandidateWave12[i]['z'][0] and z[j] - listofCandidateWave12[i]['z'][2] >= \ 338 | listofCandidateWave12[i]['z'][2] - listofCandidateWave12[i]['z'][1] and wave3_fibonacci_check(x[j], 339 | listofCandidateWave12[ 340 | i][ 341 | 'x'][ 342 | 1], 343 | listofCandidateWave12[ 344 | i][ 345 | 'x'][ 346 | 2]): 347 | currWave = copy.deepcopy(listofCandidateWave12[i]) 348 | currWave['x'].append(x[j]) 349 | currWave['z'].append(z[j]) 350 | currWave['searchIndex'] = j 351 | listofCandidateWave123.append(currWave) 352 | 353 | # end 354 | # end 355 | # end 356 | print(len(listofCandidateWave123)) 357 | print('successfully filter out candidate wave123') 358 | 359 | listofCandidateWave1234 = [] 360 | for i in range(len(listofCandidateWave123)): 361 | startSearchIndex = listofCandidateWave123[i]['searchIndex'] 362 | # forth point should be within 0.382+-5%? we take 0.382+*1.05=0.4011 363 | timeInterval = (listofCandidateWave123[i]['z'][1] - listofCandidateWave123[i]['z'][0]) * 0.4011 364 | wave3length = listofCandidateWave123[i]['z'][3] - listofCandidateWave123[i]['z'][2] 365 | for j in range(startSearchIndex, len(x)): 366 | # wave 4 is a fall and point should at around 1.618 and wave 4 must not fall below the end of wave 1 367 | if x[j] > listofCandidateWave123[i]['x'][3] and z[j] - listofCandidateWave123[i]['z'][3] <= timeInterval and \ 368 | x[j] < listofCandidateWave123[i]['x'][1] and z[j] - listofCandidateWave123[i]['z'][ 369 | 3] <= wave3length and wave4_fibonacci_check(x[j], listofCandidateWave123[i]['x'][2], 370 | listofCandidateWave123[i]['x'][3]): 371 | currWave = copy.deepcopy(listofCandidateWave123[i]) 372 | currWave['x'].append(x[j]) 373 | currWave['z'].append(z[j]) 374 | currWave['searchIndex'] = j 375 | listofCandidateWave1234.append(currWave) 376 | 377 | # end 378 | # end 379 | # end 380 | 381 | print(len(listofCandidateWave1234)) 382 | print('successfully filter out candidate wave1234') 383 | 384 | listofCandidateWave12345 = [] 385 | for i in range(len(listofCandidateWave1234)): 386 | startSearchIndex = listofCandidateWave1234[i]['searchIndex'] 387 | # forth point should be within 01.618+-5%? we take 1.618+*1.05=0.4011 388 | timeInterval = (listofCandidateWave1234[i]['z'][1] - listofCandidateWave1234[i]['z'][0]) * 1.6989 389 | wave3length = listofCandidateWave1234[i]['z'][3] - listofCandidateWave1234[i]['z'][2] 390 | for j in range(startSearchIndex, len(x)): 391 | # wave 4 is a fall and point should at around 1.618 and wave 4 must not fall below the end of wave 1 392 | if x[j] < listofCandidateWave1234[i]['x'][4] and z[j] - listofCandidateWave1234[i]['z'][ 393 | 4] <= timeInterval and z[j] - listofCandidateWave1234[i]['z'][ 394 | 4] <= wave3length and wave5_fibonacci_check(x[j], listofCandidateWave1234[i]['x'][0], 395 | listofCandidateWave1234[i]['x'][1], 396 | listofCandidateWave1234[i]['x'][2], 397 | listofCandidateWave1234[i]['x'][3], 398 | listofCandidateWave1234[i]['x'][4]): 399 | currWave = copy.deepcopy(listofCandidateWave1234[i]) 400 | currWave['x'].append(x[j]) 401 | currWave['z'].append(z[j]) 402 | currWave['searchIndex'] = j 403 | listofCandidateWave12345.append(currWave) 404 | 405 | # end 406 | # end 407 | # end 408 | print(len(listofCandidateWave12345)) 409 | print('successfully filter out candidate wave12345') 410 | return listofCandidateWave12345 411 | ######################################## 412 | # Traditional only make use of fibonacci retracement level, time interval does not necessary follow fibonacci series 413 | 414 | ############################################## 415 | def Traditional_ElliottWave_label_upward(data): 416 | v = data 417 | j = range(len(data)) 418 | x = [] 419 | z = [] 420 | b = [] 421 | # finding the high point and low point 422 | for i in range(1, len(v) - 1): 423 | if (v[i] <= v[i + 1] and v[i - 1] >= v[i]) or (v[i] >= v[i + 1] and v[i - 1] <= v[i]): 424 | # finding peaks and valleys and then place in a new matrix 425 | x.append(v[i]) 426 | z.append(j[i]) 427 | 428 | diff4x = diff(x) 429 | diff4x.insert(0, 1) 430 | 431 | diff4z = diff(x) 432 | diff4z.insert(0, 1) 433 | 434 | x = trimming(x, otherThan(diff4x, otherthan=0)) 435 | z = trimming(z, otherThan(diff4z, otherthan=0)) 436 | 437 | b = [x, z] 438 | # end 439 | # end 440 | # for each point find the first wave 441 | listofCandidateWave = [] 442 | for i in range(len(x)): 443 | for j in range(len(x)): 444 | if x[i] < x[j]: 445 | wave = { 446 | 'x': [x[i], x[j]], 447 | 'z': [z[i], z[j]], 448 | 'searchIndex': j, 449 | } 450 | listofCandidateWave.append(wave) 451 | # end 452 | # end 453 | # end 454 | 455 | print(len(listofCandidateWave)) 456 | print('successfully filter out candidate wave') 457 | 458 | listofCandidateWave12 = [] 459 | 460 | for i in range(len(listofCandidateWave)): 461 | startSearchIndex = listofCandidateWave[i]['searchIndex'] 462 | # third point should be within 0.382+-5%? we take 0.382+*1.05=0.4011 463 | # timeInterval=(listofCandidateWave[i]['z'][1]-listofCandidateWave[i]['z'][0])*0.4011 464 | for j in range(startSearchIndex, len(x)): 465 | # wave 2 is a drop and point should at around 0.382 and wave 2 drop destination is higher than start of wave 1 466 | if x[j] < listofCandidateWave[i]['x'][1] and x[j] > listofCandidateWave[i]['x'][ 467 | 0] and wave2_fibonacci_check(x[j], listofCandidateWave[i]['x'][0], listofCandidateWave[i]['x'][1]): 468 | currWave = copy.deepcopy(listofCandidateWave[i]) 469 | currWave['x'].append(x[j]) 470 | currWave['z'].append(z[j]) 471 | currWave['searchIndex'] = j 472 | listofCandidateWave12.append(currWave) 473 | 474 | # end 475 | # end 476 | # end 477 | print(len(listofCandidateWave12)) 478 | print('successfully filter out candidate wave 12') 479 | listofCandidateWave123 = [] 480 | for i in range(len(listofCandidateWave12)): 481 | startSearchIndex = listofCandidateWave12[i]['searchIndex'] 482 | # forth point should be within 1.618+-5%? we take 1.618+*1.05=1.6989 483 | # timeInterval=(listofCandidateWave12[i]['z'][1]-listofCandidateWave12[i]['z'][0])*1.6989 484 | for j in range(startSearchIndex, len(x)): 485 | # wave 3 is a rise and point should at around 1.618 and wave 3 must be the longest wave 486 | if x[j] > listofCandidateWave12[i]['x'][2] and z[j] - listofCandidateWave12[i]['z'][2] >= \ 487 | listofCandidateWave12[i]['z'][1] - listofCandidateWave12[i]['z'][0] and z[j] - \ 488 | listofCandidateWave12[i]['z'][2] >= listofCandidateWave12[i]['z'][2] - \ 489 | listofCandidateWave12[i]['z'][1] and wave3_fibonacci_check(x[j], listofCandidateWave12[i]['x'][1], 490 | listofCandidateWave12[i]['x'][2]): 491 | currWave = copy.deepcopy(listofCandidateWave12[i]) 492 | currWave['x'].append(x[j]) 493 | currWave['z'].append(z[j]) 494 | currWave['searchIndex'] = j 495 | listofCandidateWave123.append(currWave) 496 | 497 | # end 498 | # end 499 | # end 500 | print(len(listofCandidateWave123)) 501 | print('successfully filter out candidate wave123') 502 | 503 | listofCandidateWave1234 = [] 504 | for i in range(len(listofCandidateWave123)): 505 | startSearchIndex = listofCandidateWave123[i]['searchIndex'] 506 | # forth point should be within 0.382+-5%? we take 0.382+*1.05=0.4011 507 | timeInterval = (listofCandidateWave123[i]['z'][1] - listofCandidateWave123[i]['z'][0]) * 0.4011 508 | wave3length = listofCandidateWave123[i]['z'][3] - listofCandidateWave123[i]['z'][2] 509 | for j in range(startSearchIndex, len(x)): 510 | # wave 4 is a fall and point should at around 1.618 and wave 4 must not fall below the end of wave 1 511 | if x[j] < listofCandidateWave123[i]['x'][3] and z[j] - listofCandidateWave123[i]['z'][3] <= timeInterval and \ 512 | x[j] > listofCandidateWave123[i]['x'][1] and z[j] - listofCandidateWave123[i]['z'][ 513 | 3] <= wave3length and wave4_fibonacci_check(x[j], listofCandidateWave123[i]['x'][2], 514 | listofCandidateWave123[i]['x'][3]): 515 | currWave = copy.deepcopy(listofCandidateWave123[i]) 516 | currWave['x'].append(x[j]) 517 | currWave['z'].append(z[j]) 518 | currWave['searchIndex'] = j 519 | listofCandidateWave1234.append(currWave) 520 | 521 | # end 522 | # end 523 | # end 524 | 525 | print(len(listofCandidateWave1234)) 526 | print('successfully filter out candidate wave1234') 527 | 528 | listofCandidateWave12345 = [] 529 | for i in range(len(listofCandidateWave1234)): 530 | startSearchIndex = listofCandidateWave1234[i]['searchIndex'] 531 | # forth point should be within 01.618+-5%? we take 1.618+*1.05=0.4011 532 | timeInterval = (listofCandidateWave1234[i]['z'][1] - listofCandidateWave1234[i]['z'][0]) * 1.6989 533 | wave3length = listofCandidateWave1234[i]['z'][3] - listofCandidateWave1234[i]['z'][2] 534 | for j in range(startSearchIndex, len(x)): 535 | # wave 4 is a fall and point should at around 1.618 and wave 4 must not fall below the end of wave 1 536 | if x[j] > listofCandidateWave1234[i]['x'][4] and z[j] - listofCandidateWave1234[i]['z'][ 537 | 4] <= timeInterval and z[j] - listofCandidateWave1234[i]['z'][ 538 | 4] <= wave3length and wave5_fibonacci_check(x[j], listofCandidateWave1234[i]['x'][0], 539 | listofCandidateWave1234[i]['x'][1], 540 | listofCandidateWave1234[i]['x'][2], 541 | listofCandidateWave1234[i]['x'][3], 542 | listofCandidateWave1234[i]['x'][4]): 543 | currWave = copy.deepcopy(listofCandidateWave1234[i]) 544 | currWave['x'].append(x[j]) 545 | currWave['z'].append(z[j]) 546 | currWave['searchIndex'] = j 547 | listofCandidateWave12345.append(currWave) 548 | 549 | # end 550 | # end 551 | # end 552 | print(len(listofCandidateWave12345)) 553 | print('successfully filter out candidate wave12345') 554 | return listofCandidateWave12345 555 | 556 | 557 | ######################################## 558 | ############################################## 559 | def Traditional_ElliottWave_label_downward(data): 560 | v = data 561 | j = range(len(data)) 562 | x = [] 563 | z = [] 564 | b = [] 565 | # finding the high point and low point 566 | for i in range(1, len(v) - 1): 567 | if (v[i] <= v[i + 1] and v[i - 1] >= v[i]) or (v[i] >= v[i + 1] and v[i - 1] <= v[i]): 568 | # finding peaks and valleys and then place in a new matrix 569 | x.append(v[i]) 570 | z.append(j[i]) 571 | 572 | diff4x = diff(x) 573 | diff4x.insert(0, 1) 574 | 575 | diff4z = diff(x) 576 | diff4z.insert(0, 1) 577 | 578 | x = trimming(x, otherThan(diff4x, otherthan=0)) 579 | z = trimming(z, otherThan(diff4z, otherthan=0)) 580 | 581 | b = [x, z] 582 | # end 583 | # end 584 | # for each point find the first wave 585 | listofCandidateWave = [] 586 | for i in range(len(x)): 587 | for j in range(len(x)): 588 | if x[i] > x[j]: 589 | wave = { 590 | 'x': [x[i], x[j]], 591 | 'z': [z[i], z[j]], 592 | 'searchIndex': j, 593 | } 594 | listofCandidateWave.append(wave) 595 | # end 596 | # end 597 | # end 598 | 599 | print(len(listofCandidateWave)) 600 | print('successfully filter out candidate wave') 601 | 602 | listofCandidateWave12 = [] 603 | 604 | for i in range(len(listofCandidateWave)): 605 | startSearchIndex = listofCandidateWave[i]['searchIndex'] 606 | # third point should be within 0.382+-5%? we take 0.382+*1.05=0.4011 607 | # timeInterval=(listofCandidateWave[i]['z'][1]-listofCandidateWave[i]['z'][0])*0.4011 608 | for j in range(startSearchIndex, len(x)): 609 | # wave 2 is a drop and wave 2 drop destination is higher than start of wave 1 610 | if x[j] > listofCandidateWave[i]['x'][1] and x[j] < listofCandidateWave[i]['x'][ 611 | 0] and wave2_fibonacci_check(x[j], listofCandidateWave[i]['x'][0], listofCandidateWave[i]['x'][1]): 612 | currWave = copy.deepcopy(listofCandidateWave[i]) 613 | currWave['x'].append(x[j]) 614 | currWave['z'].append(z[j]) 615 | currWave['searchIndex'] = j 616 | listofCandidateWave12.append(currWave) 617 | 618 | # end 619 | # end 620 | # end 621 | print(len(listofCandidateWave12)) 622 | print('successfully filter out candidate wave 12') 623 | listofCandidateWave123 = [] 624 | for i in range(len(listofCandidateWave12)): 625 | startSearchIndex = listofCandidateWave12[i]['searchIndex'] 626 | # forth point should be within 1.618+-5%? we take 1.618+*1.05=1.6989 627 | # timeInterval=(listofCandidateWave12[i]['z'][1]-listofCandidateWave12[i]['z'][0])*1.6989 628 | for j in range(startSearchIndex, len(x)): 629 | # wave 3 is a rise and wave 3 must be the longest wave 630 | if x[j] < listofCandidateWave12[i]['x'][2] and z[j] - listofCandidateWave12[i]['z'][2] >= \ 631 | listofCandidateWave12[i]['z'][1] - listofCandidateWave12[i]['z'][0] and z[j] - \ 632 | listofCandidateWave12[i]['z'][2] >= listofCandidateWave12[i]['z'][2] - \ 633 | listofCandidateWave12[i]['z'][1] and wave3_fibonacci_check(x[j], listofCandidateWave12[i]['x'][1], 634 | listofCandidateWave12[i]['x'][2]): 635 | currWave = copy.deepcopy(listofCandidateWave12[i]) 636 | currWave['x'].append(x[j]) 637 | currWave['z'].append(z[j]) 638 | currWave['searchIndex'] = j 639 | listofCandidateWave123.append(currWave) 640 | 641 | # end 642 | # end 643 | # end 644 | print(len(listofCandidateWave123)) 645 | print('successfully filter out candidate wave123') 646 | 647 | listofCandidateWave1234 = [] 648 | for i in range(len(listofCandidateWave123)): 649 | startSearchIndex = listofCandidateWave123[i]['searchIndex'] 650 | # forth point should be within 0.382+-5%? we take 0.382+*1.05=0.4011 651 | timeInterval = (listofCandidateWave123[i]['z'][1] - listofCandidateWave123[i]['z'][0]) * 0.4011 652 | wave3length = listofCandidateWave123[i]['z'][3] - listofCandidateWave123[i]['z'][2] 653 | for j in range(startSearchIndex, len(x)): 654 | # wave 4 is a fall and wave 4 must not fall below the end of wave 1 655 | if x[j] > listofCandidateWave123[i]['x'][3] and z[j] - listofCandidateWave123[i]['z'][3] <= timeInterval and \ 656 | x[j] > listofCandidateWave123[i]['x'][1] and z[j] - listofCandidateWave123[i]['z'][ 657 | 3] <= wave3length and wave4_fibonacci_check(x[j], listofCandidateWave123[i]['x'][2], 658 | listofCandidateWave123[i]['x'][3]): 659 | currWave = copy.deepcopy(listofCandidateWave123[i]) 660 | currWave['x'].append(x[j]) 661 | currWave['z'].append(z[j]) 662 | currWave['searchIndex'] = j 663 | listofCandidateWave1234.append(currWave) 664 | 665 | # end 666 | # end 667 | # end 668 | 669 | print(len(listofCandidateWave1234)) 670 | print('successfully filter out candidate wave1234') 671 | 672 | listofCandidateWave12345 = [] 673 | for i in range(len(listofCandidateWave1234)): 674 | startSearchIndex = listofCandidateWave1234[i]['searchIndex'] 675 | # forth point should be within 01.618+-5%? we take 1.618+*1.05=0.4011 676 | timeInterval = (listofCandidateWave1234[i]['z'][1] - listofCandidateWave1234[i]['z'][0]) * 1.6989 677 | wave3length = listofCandidateWave1234[i]['z'][3] - listofCandidateWave1234[i]['z'][2] 678 | for j in range(startSearchIndex, len(x)): 679 | # wave 4 is a fall and point should at around 1.618 and wave 4 must not fall below the end of wave 1 680 | if x[j] < listofCandidateWave1234[i]['x'][4] and z[j] - listofCandidateWave1234[i]['z'][ 681 | 4] <= timeInterval and z[j] - listofCandidateWave1234[i]['z'][ 682 | 4] <= wave3length and wave5_fibonacci_check(x[j], listofCandidateWave1234[i]['x'][0], 683 | listofCandidateWave1234[i]['x'][1], 684 | listofCandidateWave1234[i]['x'][2], 685 | listofCandidateWave1234[i]['x'][3], 686 | listofCandidateWave1234[i]['x'][4]): 687 | currWave = copy.deepcopy(listofCandidateWave1234[i]) 688 | currWave['x'].append(x[j]) 689 | currWave['z'].append(z[j]) 690 | currWave['searchIndex'] = j 691 | listofCandidateWave12345.append(currWave) 692 | 693 | # end 694 | # end 695 | # end 696 | print(len(listofCandidateWave12345)) 697 | print('successfully filter out candidate wave12345') 698 | return listofCandidateWave12345 699 | ######################################## 700 | ############################################## 701 | def Practical_ElliottWave3_label_upward(data): 702 | v = data 703 | j = range(len(data)) 704 | x = [] 705 | z = [] 706 | b = [] 707 | # finding the high point and low point 708 | for i in range(1, len(v) - 1): 709 | if (v[i] <= v[i + 1] and v[i - 1] >= v[i]) or (v[i] >= v[i + 1] and v[i - 1] <= v[i]): 710 | # finding peaks and valleys and then place in a new matrix 711 | x.append(v[i]) 712 | z.append(j[i]) 713 | 714 | diff4x = diff(x) 715 | diff4x.insert(0, 1) 716 | 717 | diff4z = diff(x) 718 | diff4z.insert(0, 1) 719 | 720 | x = trimming(x, otherThan(diff4x, otherthan=0)) 721 | z = trimming(z, otherThan(diff4z, otherthan=0)) 722 | 723 | b = [x, z] 724 | # end 725 | # end 726 | # for each point find the first wave 727 | listofCandidateWave = [] 728 | for i in range(len(x)): 729 | for j in range(len(x)): 730 | if x[i] < x[j]: 731 | wave = { 732 | 'x': [x[i], x[j]], 733 | 'z': [z[i], z[j]], 734 | 'searchIndex': j, 735 | } 736 | listofCandidateWave.append(wave) 737 | # end 738 | # end 739 | # end 740 | 741 | print(len(listofCandidateWave)) 742 | print('successfully filter out candidate wave') 743 | 744 | listofCandidateWave12 = [] 745 | 746 | for i in range(len(listofCandidateWave)): 747 | startSearchIndex = listofCandidateWave[i]['searchIndex'] 748 | # third point should be within 0.382+-5%? we take 0.382+*1.05=0.4011 749 | timeInterval = (listofCandidateWave[i]['z'][1] - listofCandidateWave[i]['z'][0]) * 0.4011 750 | for j in range(startSearchIndex, len(x)): 751 | # wave 2 is a drop and point should at around 0.382 and wave 2 drop destination is higher than start of wave 1 752 | if x[j] < listofCandidateWave[i]['x'][1] and z[j] - listofCandidateWave[i]['z'][1] <= timeInterval and x[ 753 | j] > listofCandidateWave[i]['x'][0] and wave2_fibonacci_check(x[j], listofCandidateWave[i]['x'][0], 754 | listofCandidateWave[i]['x'][1]): 755 | currWave = copy.deepcopy(listofCandidateWave[i]) 756 | currWave['x'].append(x[j]) 757 | currWave['z'].append(z[j]) 758 | currWave['searchIndex'] = j 759 | listofCandidateWave12.append(currWave) 760 | 761 | # end 762 | # end 763 | # end 764 | print(len(listofCandidateWave12)) 765 | print('successfully filter out candidate wave 12') 766 | return listofCandidateWave12 767 | 768 | 769 | ######################################## 770 | ############################################## 771 | def Practical_ElliottWave4_label_downward(data): 772 | v = data 773 | j = range(len(data)) 774 | x = [] 775 | z = [] 776 | b = [] 777 | # finding the high point and low point 778 | for i in range(1, len(v) - 1): 779 | if (v[i] <= v[i + 1] and v[i - 1] >= v[i]) or (v[i] >= v[i + 1] and v[i - 1] <= v[i]): 780 | # finding peaks and valleys and then place in a new matrix 781 | x.append(v[i]) 782 | z.append(j[i]) 783 | 784 | diff4x = diff(x) 785 | diff4x.insert(0, 1) 786 | 787 | diff4z = diff(x) 788 | diff4z.insert(0, 1) 789 | 790 | x = trimming(x, otherThan(diff4x, otherthan=0)) 791 | z = trimming(z, otherThan(diff4z, otherthan=0)) 792 | 793 | b = [x, z] 794 | # end 795 | # end 796 | # for each point find the first wave 797 | listofCandidateWave = [] 798 | for i in range(len(x)): 799 | for j in range(len(x)): 800 | if x[i] > x[j]: 801 | wave = { 802 | 'x': [x[i], x[j]], 803 | 'z': [z[i], z[j]], 804 | 'searchIndex': j, 805 | } 806 | listofCandidateWave.append(wave) 807 | # end 808 | # end 809 | # end 810 | 811 | print(len(listofCandidateWave)) 812 | print('successfully filter out candidate wave') 813 | 814 | listofCandidateWave12 = [] 815 | 816 | for i in range(len(listofCandidateWave)): 817 | startSearchIndex = listofCandidateWave[i]['searchIndex'] 818 | # third point should be within 0.382+-5%? we take 0.382+*1.05=0.4011 819 | timeInterval = (listofCandidateWave[i]['z'][1] - listofCandidateWave[i]['z'][0]) * 0.4011 820 | for j in range(startSearchIndex, len(x)): 821 | # wave 2 is a drop and point should at around 0.382 and wave 2 drop destination is higher than start of wave 1 822 | if x[j] > listofCandidateWave[i]['x'][1] and z[j] - listofCandidateWave[i]['z'][1] <= timeInterval and x[ 823 | j] < listofCandidateWave[i]['x'][0] and wave2_fibonacci_check(x[j], listofCandidateWave[i]['x'][0], 824 | listofCandidateWave[i]['x'][1]): 825 | currWave = copy.deepcopy(listofCandidateWave[i]) 826 | currWave['x'].append(x[j]) 827 | currWave['z'].append(z[j]) 828 | currWave['searchIndex'] = j 829 | listofCandidateWave12.append(currWave) 830 | 831 | # end 832 | # end 833 | # end 834 | print(len(listofCandidateWave12)) 835 | print('successfully filter out candidate wave 12') 836 | listofCandidateWave123 = [] 837 | for i in range(len(listofCandidateWave12)): 838 | startSearchIndex = listofCandidateWave12[i]['searchIndex'] 839 | # forth point should be within 1.618+-5%? we take 1.618+*1.05=1.6989 840 | timeInterval = (listofCandidateWave12[i]['z'][1] - listofCandidateWave12[i]['z'][0]) * 1.6989 841 | for j in range(startSearchIndex, len(x)): 842 | # wave 3 is a rise and point should at around 1.618 and wave 3 must be the longest wave 843 | if x[j] < listofCandidateWave12[i]['x'][2] and z[j] - listofCandidateWave12[i]['z'][2] <= timeInterval and \ 844 | z[j] - listofCandidateWave12[i]['z'][2] >= listofCandidateWave12[i]['z'][1] - \ 845 | listofCandidateWave12[i]['z'][0] and z[j] - listofCandidateWave12[i]['z'][2] >= \ 846 | listofCandidateWave12[i]['z'][2] - listofCandidateWave12[i]['z'][1] and wave3_fibonacci_check(x[j], 847 | listofCandidateWave12[ 848 | i][ 849 | 'x'][ 850 | 1], 851 | listofCandidateWave12[ 852 | i][ 853 | 'x'][ 854 | 2]): 855 | currWave = copy.deepcopy(listofCandidateWave12[i]) 856 | currWave['x'].append(x[j]) 857 | currWave['z'].append(z[j]) 858 | currWave['searchIndex'] = j 859 | listofCandidateWave123.append(currWave) 860 | 861 | # end 862 | # end 863 | # end 864 | print(len(listofCandidateWave123)) 865 | print('successfully filter out candidate wave123') 866 | return listofCandidateWave123 867 | ######################################## 868 | ############################################## 869 | def Practical_ElliottWave5_label_upward(data): 870 | v = data 871 | j = range(len(data)) 872 | x = [] 873 | z = [] 874 | b = [] 875 | # finding the high point and low point 876 | for i in range(1, len(v) - 1): 877 | if (v[i] <= v[i + 1] and v[i - 1] >= v[i]) or (v[i] >= v[i + 1] and v[i - 1] <= v[i]): 878 | # finding peaks and valleys and then place in a new matrix 879 | x.append(v[i]) 880 | z.append(j[i]) 881 | 882 | diff4x = diff(x) 883 | diff4x.insert(0, 1) 884 | 885 | diff4z = diff(x) 886 | diff4z.insert(0, 1) 887 | 888 | x = trimming(x, otherThan(diff4x, otherthan=0)) 889 | z = trimming(z, otherThan(diff4z, otherthan=0)) 890 | 891 | b = [x, z] 892 | # end 893 | # end 894 | # for each point find the first wave 895 | listofCandidateWave = [] 896 | for i in range(len(x)): 897 | for j in range(len(x)): 898 | if x[i] < x[j]: 899 | wave = { 900 | 'x': [x[i], x[j]], 901 | 'z': [z[i], z[j]], 902 | 'searchIndex': j, 903 | } 904 | listofCandidateWave.append(wave) 905 | # end 906 | # end 907 | # end 908 | 909 | print(len(listofCandidateWave)) 910 | print('successfully filter out candidate wave') 911 | 912 | listofCandidateWave12 = [] 913 | 914 | for i in range(len(listofCandidateWave)): 915 | startSearchIndex = listofCandidateWave[i]['searchIndex'] 916 | # third point should be within 0.382+-5%? we take 0.382+*1.05=0.4011 917 | timeInterval = (listofCandidateWave[i]['z'][1] - listofCandidateWave[i]['z'][0]) * 0.4011 918 | for j in range(startSearchIndex, len(x)): 919 | # wave 2 is a drop and point should at around 0.382 and wave 2 drop destination is higher than start of wave 1 920 | if x[j] < listofCandidateWave[i]['x'][1] and z[j] - listofCandidateWave[i]['z'][1] <= timeInterval and x[ 921 | j] > listofCandidateWave[i]['x'][0] and wave2_fibonacci_check(x[j], listofCandidateWave[i]['x'][0], 922 | listofCandidateWave[i]['x'][1]): 923 | currWave = copy.deepcopy(listofCandidateWave[i]) 924 | currWave['x'].append(x[j]) 925 | currWave['z'].append(z[j]) 926 | currWave['searchIndex'] = j 927 | listofCandidateWave12.append(currWave) 928 | 929 | # end 930 | # end 931 | # end 932 | print(len(listofCandidateWave12)) 933 | print('successfully filter out candidate wave 12') 934 | listofCandidateWave123 = [] 935 | for i in range(len(listofCandidateWave12)): 936 | startSearchIndex = listofCandidateWave12[i]['searchIndex'] 937 | # forth point should be within 1.618+-5%? we take 1.618+*1.05=1.6989 938 | timeInterval = (listofCandidateWave12[i]['z'][1] - listofCandidateWave12[i]['z'][0]) * 1.6989 939 | for j in range(startSearchIndex, len(x)): 940 | # wave 3 is a rise and point should at around 1.618 and wave 3 must be the longest wave 941 | if x[j] > listofCandidateWave12[i]['x'][2] and z[j] - listofCandidateWave12[i]['z'][2] <= timeInterval and \ 942 | z[j] - listofCandidateWave12[i]['z'][2] >= listofCandidateWave12[i]['z'][1] - \ 943 | listofCandidateWave12[i]['z'][0] and z[j] - listofCandidateWave12[i]['z'][2] >= \ 944 | listofCandidateWave12[i]['z'][2] - listofCandidateWave12[i]['z'][1] and wave3_fibonacci_check(x[j], 945 | listofCandidateWave12[ 946 | i][ 947 | 'x'][ 948 | 1], 949 | listofCandidateWave12[ 950 | i][ 951 | 'x'][ 952 | 2]): 953 | currWave = copy.deepcopy(listofCandidateWave12[i]) 954 | currWave['x'].append(x[j]) 955 | currWave['z'].append(z[j]) 956 | currWave['searchIndex'] = j 957 | listofCandidateWave123.append(currWave) 958 | 959 | # end 960 | # end 961 | # end 962 | print(len(listofCandidateWave123)) 963 | print('successfully filter out candidate wave123') 964 | 965 | listofCandidateWave1234 = [] 966 | for i in range(len(listofCandidateWave123)): 967 | startSearchIndex = listofCandidateWave123[i]['searchIndex'] 968 | # forth point should be within 0.382+-5%? we take 0.382+*1.05=0.4011 969 | timeInterval = (listofCandidateWave123[i]['z'][1] - listofCandidateWave123[i]['z'][0]) * 0.4011 970 | wave3length = listofCandidateWave123[i]['z'][3] - listofCandidateWave123[i]['z'][2] 971 | for j in range(startSearchIndex, len(x)): 972 | # wave 4 is a fall and point should at around 1.618 and wave 4 must not fall below the end of wave 1 973 | if x[j] < listofCandidateWave123[i]['x'][3] and z[j] - listofCandidateWave123[i]['z'][3] <= timeInterval and \ 974 | x[j] > listofCandidateWave123[i]['x'][1] and z[j] - listofCandidateWave123[i]['z'][ 975 | 3] <= wave3length and wave4_fibonacci_check(x[j], listofCandidateWave123[i]['x'][2], 976 | listofCandidateWave123[i]['x'][3]): 977 | currWave = copy.deepcopy(listofCandidateWave123[i]) 978 | currWave['x'].append(x[j]) 979 | currWave['z'].append(z[j]) 980 | currWave['searchIndex'] = j 981 | listofCandidateWave1234.append(currWave) 982 | 983 | # end 984 | # end 985 | # end 986 | 987 | print(len(listofCandidateWave1234)) 988 | print('successfully filter out candidate wave1234') 989 | 990 | return listofCandidateWave1234 991 | ######################################## 992 | --------------------------------------------------------------------------------