-
Notifications
You must be signed in to change notification settings - Fork 1
/
weeklyLineJudge0206.py
1325 lines (1179 loc) · 74.4 KB
/
weeklyLineJudge0206.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# -*- coding: utf-8 -*-
"""
Created on Wed Dec 6 09:40:13 2017
@author: Administrator
"""
import numpy as np
import copy
import matplotlib.pyplot as plt
#import sys
from matplotlib.dates import DateFormatter
from matplotlib.dates import DayLocator
from matplotlib.dates import MonthLocator
from matplotlib.dates import date2num
from matplotlib.finance import candlestick_ohlc
from datetime import datetime
#import tushare as ts
def datestr2num(s):
date1 = datetime.strptime(s.decode('ascii'), "%Y/%m/%d").date()
date = date2num(date1)
return date
###############################################################################
############################ 一、画出峰谷折线图 ################################
# 1、提取数据并绘FG0图 #########################################################
alldays = DayLocator()
months = MonthLocator()
month_formatter = DateFormatter("%b %Y")
#quotes的内容(time, open, high, low, close)
#quotes_pre = np.loadtxt('RU1801WeeklyData.csv', delimiter=',', usecols=(0,1,2,3,4,), converters={0:datestr2num}, unpack=True)
#quotes_pre = np.loadtxt('RU1709WeeklyData.csv', delimiter=',', usecols=(0,1,2,3,4,), converters={0:datestr2num}, unpack=True)
#quotes_pre = np.loadtxt('Y1801WeeklyData.csv', delimiter=',', usecols=(0,1,2,3,4,), converters={0:datestr2num}, unpack=True)
quotes_pre = np.loadtxt('RM801WeeklyData.csv', delimiter=',', usecols=(0,1,2,3,4,), converters={0:datestr2num}, unpack=True)
#quotes_pre = np.loadtxt('RB1801WeeklyData.csv', delimiter=',', usecols=(0,1,2,3,4,), converters={0:datestr2num}, unpack=True)
#quotes_pre = np.loadtxt('J1801WeeklyData.csv', delimiter=',', usecols=(0,1,2,3,4,), converters={0:datestr2num}, unpack=True)
quotes = []
tick = 5 #期货橡胶ru的刻度,即一手价格变动的最低价
global g_resistanceList_wk #[0] W(N)中的 周数N 列表
global g_resistanceList #[1] W(N)的 resistanceList 列表
global g_resceAbateList #[0] W(N)失效阻力的周序数及类型,结构为[[weekNo0,resceType0],[weekNo1,resceType1],[weekNo2,resceType2]]
global g_selfAdjustTrend_wk #[0] W(N)中的 周数N 列表
global g_selfAdjustTrend #[1] W(N)的 selfAdjustTrend 列表
global g_synthesizeTrend_wk #[0] W(N)中的 synthesizeTrend 列表
global g_synthesizeTrend #[1] W(N)的 synthesizeTrend 列表
global g_week_trend_wk #[0] W(N)中的 周数N 列表
global g_week_trend #[1] W(N)的 FinalTrend 列表
g_resistanceList_wk = []
g_resistanceList = []
g_resceAbateList = []
g_selfAdjustTrend_wk = []
g_selfAdjustTrend = []
g_synthesizeTrend_wk = []
g_synthesizeTrend = []
g_week_trend_wk = []
g_week_trend = []
for i in range( len(quotes_pre[0]) ):
datas = (quotes_pre[0][i],quotes_pre[1][i],quotes_pre[2][i],quotes_pre[3][i],quotes_pre[4][i])
quotes.append(datas)
#alldays = DayLocator()
#months = MonthLocator()
#month_formatter = DateFormatter("%b %Y")
#fig = plt.figure(figsize=(18, 9))
#ax = fig.add_subplot(111)
#ax.xaxis.set_major_locator(months)
#ax.xaxis.set_minor_locator(alldays)
#ax.xaxis.set_major_formatter(month_formatter)
#plt.title("Weekly Line")
#plt.xlabel("Week")
#plt.ylabel("Price")
#candlestick_ohlc(ax,quotes,width=0.2, colorup='r',colordown='g')
#plt.plot(quotes_pre[0], quotes_pre[4], 'r', lw=1.0) #画出收盘价折线图
# 2、找到极值点 ################################################################
#需考虑临值相等的情况 #
quotes_fg0_date = [] #峰谷的日期
quotes_fg0_price = [] #峰谷的价格
quotes_fg0_index = [] #峰谷在原时间序列中的位置
quotes_fg0_direction = [] #值为1表示波峰,值为0表示波谷
for i in range( len(quotes_pre[0]) )[1:-1]:
#波峰:
if quotes_pre[4][i]>quotes_pre[4][i-1] and quotes_pre[4][i]>quotes_pre[4][i+1]:
quotes_fg0_date.append(quotes_pre[0][i])
quotes_fg0_price.append(quotes_pre[4][i])
quotes_fg0_index.append(i)
quotes_fg0_direction.append(1)
#波谷:
if quotes_pre[4][i]<quotes_pre[4][i-1] and quotes_pre[4][i]<quotes_pre[4][i+1]:
quotes_fg0_date.append(quotes_pre[0][i])
quotes_fg0_price.append(quotes_pre[4][i])
quotes_fg0_index.append(i)
quotes_fg0_direction.append(0)
#3、修正极值点 #################################################################
#第1步:对于波峰(波谷),用本周最大值(最小值)代替收盘价
j = 0 # 记录quotes_fg0_price中元素的坐标
for i in range( len(quotes_fg0_index) ):
fg0_index = quotes_fg0_index[i]
#本极值点为波谷,用最低价代替收盘价
if quotes_fg0_direction[i] == 0:
quotes_fg0_price[j] = quotes_pre[3][fg0_index]
#开盘价<收盘价,本极值点为波峰,用最高价代替收盘价
if quotes_fg0_direction[i] == 1:
quotes_fg0_price[j] = quotes_pre[2][fg0_index]
j = j + 1 # quotes_fg0_price下一个元素的坐标
#plt.plot(quotes_fg0_date, quotes_fg0_price, 'y', lw=1.5) #画出极值点折线图
#ax.scatter(quotes_fg0_date, quotes_fg0_price, alpha=0.5) #画出极值点散点图
#第2步:根据规则,用新峰谷时间点代替部分原峰谷时间点
quotes_fg_date = copy.deepcopy(quotes_fg0_date)
quotes_fg_price = copy.deepcopy(quotes_fg0_price)
quotes_fg_index = copy.deepcopy(quotes_fg0_index)
quotes_fg_direction = copy.deepcopy(quotes_fg0_direction) #值为1表示波峰,值为0表示波谷
#先根据波峰确定波次,调整波谷
for j in range(len(quotes_fg_index)):
if quotes_fg_direction[j] == 1 and j + 2 < len(quotes_fg_index):#本波峰后面还有一个波峰,能构成完整波次,才在本波次内调整波谷
quotes_fwave_begin = quotes_fg_index[j] #第一个波峰在quotes的序号
quotes_fwave_end = quotes_fg_index[j+2] #第二个波峰在quotes的序号
quotes_wave_low = copy.deepcopy(quotes_pre[3][quotes_fwave_begin: quotes_fwave_end + 1])
quotes_wave_low_min_index = np.argmin(quotes_wave_low)
quotes_wave_low_min = quotes_wave_low[ quotes_wave_low_min_index ]
quotes_g_index = quotes_fwave_begin + quotes_wave_low_min_index #新波谷在quotes的序号
if quotes_wave_low_min < quotes_fg_price[j+1]:
# 用新波谷代替旧波谷:
quotes_fg_date[j+1] = quotes_pre[0][quotes_g_index]
quotes_fg_price[j+1] = quotes_pre[3][quotes_g_index]
quotes_fg_index[j+1] = quotes_g_index
#再根据波谷确定波次,调整波峰
for j in range(len(quotes_fg_index)):
if quotes_fg_direction[j] == 0 and j + 2 < len(quotes_fg_index):#本波谷后面还有一个波谷,能构成完整波次,才在本波次内调整波峰
quotes_gwave_begin = quotes_fg_index[j] #第一个波谷在quotes的序号
quotes_gwave_end = quotes_fg_index[j+2] #第二个波谷在quotes的序号
quotes_wave_high = copy.deepcopy(quotes_pre[2][quotes_gwave_begin: quotes_gwave_end + 1])
quotes_wave_high_max_index = np.argmax(quotes_wave_high)
quotes_wave_high_max = quotes_wave_high[ quotes_wave_high_max_index ]
quotes_f_index = quotes_gwave_begin + quotes_wave_high_max_index #新波峰在quotes的序号
if quotes_wave_high_max > quotes_fg_price[j+1]:
# 用新波峰代替旧波峰:
quotes_fg_date[j+1] = quotes_pre[0][quotes_f_index]
quotes_fg_price[j+1] = quotes_pre[2][quotes_f_index]
quotes_fg_index[j+1] = quotes_f_index
#plt.plot(quotes_fg_date, quotes_fg_price, 'b--', lw=2.0) #画出调整后的峰谷折线图
#ax.scatter(quotes_fg_date, quotes_fg_price, alpha=0.5) #画出调整后的峰谷散点图
#标注各周编号
#wk_no = range(len(quotes_pre[0])) # 周序号
#for i in range(len(quotes_pre[0])):
# wk_number = wk_no[i] + 1
# plt.text(quotes_pre[0][i], quotes_pre[2][i], wk_number, alpha=0.5)
#fig.autofmt_xdate()
#plt.savefig("wave.png")
#plt.show()
###############################################################################
############################ 二、定义函数 ######################################
# 本节定义这些函数:反转周函数getReverse、突破周函数getBreak、阻力定义函数getResistance、
# 反转首周定义函数getFirstReverse、突破首周定义函数getFirstBreak、本身K线含义函数getSelfTrend、
# 阻力空间函数getBreakTrend、本身定义调整函数getSelfAdjustTrend
# 1、本身K线含义函数:getSelfTrend(week_N)######################################
# 通过K线本身判断week_N的趋势,selfTrend = -1
# 表示本身K线趋势空,=1表示本身K线趋势多,=10 表示本身K线宽幅震荡。
def getSelfTrend(week_N):
selfTrend = 10
week_N_rise = 0
week_N_rise_rate = 0
# week_N的涨幅(跌幅):
if week_N == 1:
week_N_rise = (quotes_pre[4][week_N-1] - quotes_pre[1][week_N-1]) #上涨(下跌)值
week_N_rise_rate = week_N_rise / quotes_pre[1][week_N-1] #涨幅(跌幅)
elif week_N >= 2:
week_N_rise = (quotes_pre[4][week_N-1] - quotes_pre[4][week_N-2]) #上涨(下跌)值
week_N_rise_rate = week_N_rise / quotes_pre[4][week_N-2] #涨幅(跌幅)
# week_N的上(下)影线:
up_shadow = quotes_pre[2][week_N-1] - max(quotes_pre[1][week_N-1], quotes_pre[4][week_N-1]) #上影线
down_shadow = min(quotes_pre[1][week_N-1], quotes_pre[4][week_N-1]) - quotes_pre[3][week_N-1] #下影线
if week_N_rise_rate >= 0 :
if week_N_rise_rate>0.03 : selfTrend =1
elif week_N_rise_rate>0.012 and up_shadow < week_N_rise: selfTrend =1
elif week_N_rise_rate>0.012 and up_shadow >= week_N_rise: selfTrend =10
elif week_N_rise_rate>=0 : selfTrend =10
if week_N_rise_rate < 0 :
if abs(week_N_rise_rate)>0.03 : selfTrend =-1
elif abs(week_N_rise_rate)>0.012 and down_shadow < abs(week_N_rise): selfTrend =-1
elif abs(week_N_rise_rate)>0.012 and down_shadow >= abs(week_N_rise): selfTrend =10
elif abs(week_N_rise_rate)>0 : selfTrend =10
return selfTrend
# 2、反转周函数:getReverse(week_N)#############################################
# 判断第N周是否为反转周,reverse_wk = 0表示非反转周,=1表示反转周
def getReverse(week_N):
reverse_wk = 0
if quotes_pre[1][week_N-2] > quotes_pre[4][week_N-2] and quotes_pre[1][week_N-1] < quotes_pre[4][week_N-1]:
reverse_wk = 1
if quotes_pre[1][week_N-2] < quotes_pre[4][week_N-2] and quotes_pre[1][week_N-1] > quotes_pre[4][week_N-1]:
reverse_wk = 1
return reverse_wk
# 3、突破周函数:getBreak(week_N)###############################################
# 判断第N周是否为突破周,break_wk = 0表示非突破周,=1/-1表示突破周(趋势多/趋势空)
# 返回值break_list:[0]为week_N、[1]为break_wk(可取值:0,1,-1)、[2]突破的波峰f1(或波谷g1)在quotes中的序列
def getBreak(week_N):
break_wk = 0
break_list = [week_N,break_wk,-1] # 分别为week_N、 break_wk(可取值:0,1,-1)、 波峰f1(或波谷g1)
# week_N的涨幅(跌幅):
week_N_rise = (quotes_pre[4][week_N-1] - quotes_pre[4][week_N-2]) #上涨(下跌)值
week_N_rise_rate = week_N_rise / quotes_pre[4][week_N-2] #涨幅(跌幅)
# week_N的上(下)影线:
up_shadow = quotes_pre[2][week_N-1] - max(quotes_pre[1][week_N-1], quotes_pre[4][week_N-1]) #上影线
down_shadow = min(quotes_pre[1][week_N-1], quotes_pre[4][week_N-1]) - quotes_pre[3][week_N-1] #下影线
quotes_f_list = [[],[]] #将所有波峰,按时间从近到远进行排序,[0]存储价格,[1]存储波峰属于哪一周
quotes_g_list = [[],[]] #将所有波谷,按时间从近到远进行排序,[0]存储价格,[1]存储波峰属于哪一周
for i in range( len(quotes_fg_price) )[::-1]:
if( quotes_fg_direction[i] == 1 and quotes_fg_index[i] < week_N - 1 ):# week_N 之前的波峰
quotes_f_list[0].append( quotes_fg_price[i] )
quotes_f_list[1].append( quotes_fg_index[i] )
elif( quotes_fg_direction[i] == 0 and quotes_fg_index[i] < week_N - 1 ):# week_N 之前的波谷
quotes_g_list[0].append( quotes_fg_price[i] )
quotes_g_list[1].append( quotes_fg_index[i] )
last_f_price = 0 #记录上一个可能的阻力值
last_g_Price = 200000 #记录可能的阻力值
if week_N_rise_rate > 0.03 or ( 0.012 < week_N_rise_rate <= 0.03 and up_shadow < week_N_rise ):
#找符合约束条件的波峰:
quotes_f_index = -1 # quotes_f_index即为所求波峰
j1 = 0 # 记录遍历符合条件波峰的个数
for i in range( len(quotes_f_list[0]) ):
quotes_f_index = quotes_f_list[1][i]#波峰周在quotes序列中的下标
if j1 == 5: #如果已查找了5个波峰,直接结束循环
break
if quotes_f_list[0][i] > last_f_price: #找比f1之前更高的波峰f2
if quotes_pre[2][week_N-2] < quotes_pre[2][quotes_f_index] <= quotes_pre[2][week_N-1] - 5*tick and \
quotes_pre[4][quotes_f_index] <= quotes_pre[4][week_N-1] - 3*tick:#找到了符合条件的波峰
break_wk = 1 # 本周为突破周趋势多
break_list = [week_N, break_wk, quotes_f_index + 1]
break
else:
last_f_price = quotes_f_list[0][i] #将当前波峰价格设为f2,以此为基础找f3
j1 = j1 + 1
if week_N_rise_rate < -0.03 or ( -0.03 <= week_N_rise_rate < -0.012 and down_shadow < abs(week_N_rise) ):
#找符合约束条件的波谷:
quotes_g_index = -1 # quotes_g_index即为所求波谷
j1 = 0 # 记录遍历符合条件波谷的个数
for i in range( len(quotes_g_list[0]) ):
quotes_g_index = quotes_g_list[1][i]#波谷周在quotes序列中的下标
if j1 == 5: #如果已查找了5个波谷,直接结束循环
break
if quotes_g_list[0][i] < last_g_Price: #找比g1之前更低的波谷g2
if quotes_pre[3][week_N-2] > quotes_pre[3][quotes_g_index] >= quotes_pre[3][week_N-1] + 5*tick and \
quotes_pre[4][quotes_g_index] >= quotes_pre[4][week_N-1] + 3*tick:#找到了符合条件的波峰
break_wk = -1 # 本周为突破周趋势空
break_list = [week_N, break_wk, quotes_g_index + 1]
break
else:
last_g_Price = quotes_g_list[0][i] #将当前波峰价格设为g2,以此为基础找g3
j1 = j1 + 1
return break_list
# 4、本身定义调整函数:getSelfAdjustTrend(week_N)##############################
# 通过week_N-1的首周判断函数,得到week_N的本身定义调整函数,selfAdjustTrend=-1表示趋势明显空;# =1表示趋势明显多;=10表示宽幅震荡。
def getSelfAdjustTrend(week_N):
week_N_trend = 10
week_1N_trend = 10
if week_N in [1, 2, 3]: #前3周,用本身函数代替本身调整函数
week_N_trend = getSelfTrend(week_N)
return week_N_trend
# 数据准备1:week_2N,即W(N-2):
week_2N_rise = (quotes_pre[4][week_N-3] - quotes_pre[4][week_N-4]) #上涨(下跌)值
week_2N_rise_rate = week_2N_rise / quotes_pre[4][week_N-4] #涨幅(跌幅)
# 数据准备2:week_1N,即W(N-1):
week_1N_rise = (quotes_pre[4][week_N-2] - quotes_pre[4][week_N-3]) #上涨(下跌)值
week_1N_rise_rate = week_1N_rise / quotes_pre[4][week_N-3] #涨幅(跌幅)
week_1N_upShadow = quotes_pre[2][week_N-2]-max(quotes_pre[1][week_N-2], quotes_pre[4][week_N-2]) #上影线
week_1N_lowShadow = min(quotes_pre[1][week_N-2], quotes_pre[4][week_N-2]) - quotes_pre[3][week_N-2] #下影线
if week_N-1 in g_week_trend_wk: #如全局变量列表中已有数据,则使用全局变量
index_g_finalTrend = g_week_trend_wk.index( week_N-1 )
week_1N_trend = copy.deepcopy( g_week_trend[index_g_finalTrend] )
else:
week_1N_trend = getFinalTrend(week_N-1)
# 数据准备3:week_N,即W(N):
week_N_rise = (quotes_pre[4][week_N-1] - quotes_pre[4][week_N-2]) #上涨(下跌)值
week_N_rise_rate = week_N_rise / quotes_pre[4][week_N-2] #涨幅(跌幅)
week_N_upShadow = quotes_pre[2][week_N-1]-max(quotes_pre[1][week_N-1], quotes_pre[4][week_N-1]) #上影线
week_N_lowShadow = min(quotes_pre[1][week_N-1], quotes_pre[4][week_N-1]) - quotes_pre[3][week_N-1] #下影线
#情况(01)时W(N)周线定义:#####################
if week_1N_trend == 2:
if week_N_rise_rate >= 0:
if quotes_pre[3][week_N-1] >= quotes_pre[3][week_N - 2]:
week_N_trend = 1
elif quotes_pre[3][week_N-1] < quotes_pre[3][week_N - 2] and quotes_pre[4][week_N-1] > quotes_pre[3][week_N - 2]:
week_N_trend = 1
elif quotes_pre[3][week_N-1] < quotes_pre[3][week_N - 2] and quotes_pre[4][week_N-1] <= quotes_pre[2][week_N - 2]:
week_N_trend = 10
elif week_N_rise_rate < 0:
if week_N_rise_rate < 0 and week_1N_rise_rate > 0:
if abs(week_N_rise_rate) < week_1N_rise_rate * 0.5:
week_N_trend = 1
elif week_1N_rise_rate * 0.5 <= abs(week_N_rise_rate) <= week_1N_rise_rate:
week_N_trend = 10
elif abs(week_N_rise_rate) > week_1N_rise_rate:
week_N_trend = -1
#情况(02)时W(N)周线定义:#####################
if week_1N_trend == 1 and week_1N_rise_rate > 0.03:
if week_N_rise_rate >= 0:
if quotes_pre[3][week_N-1] >= quotes_pre[3][week_N - 2]:
week_N_trend = 1
elif quotes_pre[3][week_N-1] < quotes_pre[3][week_N - 2] and quotes_pre[4][week_N-1] > quotes_pre[2][week_N - 2] :
week_N_trend = 1
elif quotes_pre[3][week_N-1] < quotes_pre[3][week_N - 2] and quotes_pre[4][week_N-1] <= quotes_pre[2][week_N - 2] :
week_N_trend = 10
elif week_N_rise_rate < 0:
if week_1N_rise_rate > 0:
if abs(week_N_rise_rate) < week_1N_rise_rate/3:
week_N_trend = 1
elif week_1N_rise_rate/3 <= abs(week_N_rise_rate) <= week_1N_rise_rate * 0.5:
week_N_trend = 10
elif abs(week_N_rise_rate) > week_1N_rise_rate * 0.5:
week_N_trend = -1
#情况(03)时W(N)周线定义:#####################
if week_1N_trend == 1 and 0.012 < week_1N_rise_rate < 0.03 and week_1N_upShadow < week_1N_rise:
if week_N_rise_rate > 0:
if quotes_pre[3][week_N-1] >= quotes_pre[3][week_N - 2]:
week_N_trend = 1
elif quotes_pre[3][week_N-1] < quotes_pre[3][week_N - 2] and quotes_pre[4][week_N-1] > quotes_pre[2][week_N - 2]:
week_N_trend = 1
elif quotes_pre[3][week_N-1] < quotes_pre[3][week_N - 2] and quotes_pre[4][week_N-1] <= quotes_pre[2][week_N - 2]:
week_N_trend = 10
elif week_N_rise_rate < 0:
if week_1N_rise_rate > 0:
if abs(week_N_rise_rate) < week_1N_rise_rate/3:
week_N_trend = 1
elif week_1N_rise_rate/3 <= abs(week_N_rise_rate) <= week_1N_rise_rate * 0.5:
week_N_trend = 10
elif abs(week_N_rise_rate) > week_1N_rise_rate * 0.5:
week_N_trend = -1
#情况(04)时W(N)周线定义:#####################
if week_1N_trend == 1 and 0.012 < week_1N_rise_rate < 0.03 and week_1N_upShadow >= week_1N_rise:
if week_N_rise_rate > 0:
if quotes_pre[3][week_N-1] >= quotes_pre[3][week_N - 2]:
week_N_trend = 1
elif quotes_pre[3][week_N-1] < quotes_pre[3][week_N - 2] and quotes_pre[4][week_N-1] > quotes_pre[2][week_N - 2]:
week_N_trend = 1
elif quotes_pre[3][week_N-1] < quotes_pre[3][week_N - 2] and quotes_pre[4][week_N-1] <= quotes_pre[2][week_N - 2]:
week_N_trend = 10
elif week_N_rise_rate < 0:
if abs(week_N_rise_rate) > 0.03:
week_N_trend = 1
elif 0.012 < abs(week_N_rise_rate) <= 0.03 and week_N_lowShadow < abs(week_N_rise):
if abs(week_N_rise_rate) > week_1N_rise_rate:
week_N_trend = -1
elif abs(week_N_rise_rate) <= week_1N_rise_rate:
week_N_trend = 10
elif 0.012 < abs(week_N_rise_rate) <= 0.03 and week_N_lowShadow >= abs(week_N_rise):
week_N_trend = 10
elif abs(week_N_rise_rate) <= 0.012:
week_N_trend = 10
#情况(05)时W(N)周线定义:#####################
if week_1N_trend == 1 and 0 <= week_1N_rise_rate <= 0.012:
if week_N_rise_rate > 0:
if week_N_rise_rate > 0.03:
week_N_trend = 1
elif 0.012 < week_N_rise_rate <= 0.03 and week_N_upShadow < week_N_rise:
week_N_trend = 1
elif 0.012 < week_N_rise_rate <= 0.03 and week_N_upShadow >= week_N_rise and \
quotes_pre[2][week_N-1] > quotes_pre[2][week_N - 2]:
week_N_trend = 1
elif 0.012 < week_N_rise_rate <= 0.03 and week_N_upShadow >= week_N_rise and \
quotes_pre[2][week_N-1] <= quotes_pre[2][week_N - 2]:
week_N_trend = 10
elif 0 < week_N_rise_rate <= 0.012 and quotes_pre[2][week_N-1] > quotes_pre[2][week_N - 2]:
week_N_trend = 1
elif 0 < week_N_rise_rate <= 0.012 and quotes_pre[2][week_N-1] <= quotes_pre[2][week_N - 2]:
week_N_trend = 10
elif week_N_rise_rate < 0:
week_N_trend = getSelfTrend(week_N )
#情况(06)时W(N)周线定义:#####################
if week_1N_trend == 1 and -0.012 <= week_1N_rise_rate < 0:
if week_N_rise_rate > 0:
if week_N_rise_rate > 0.03:
week_N_trend = 1
elif 0.012 < week_N_rise_rate <= 0.03 and week_N_upShadow < week_N_rise and \
quotes_pre[4][week_N-1] >= quotes_pre[2][week_N - 2]:
week_N_trend = 1
elif 0.012 < week_N_rise_rate <= 0.03 and week_N_upShadow < week_N_rise and \
quotes_pre[4][week_N-1] < quotes_pre[2][week_N - 2]:
week_N_trend = 10
elif 0.012 < week_N_rise_rate <= 0.03 and week_N_upShadow >= week_N_rise and \
quotes_pre[4][week_N-1] >= quotes_pre[2][week_N - 2]:
week_N_trend = 1
elif 0.012 < week_N_rise_rate <= 0.03 and week_N_upShadow >= week_N_rise and \
quotes_pre[4][week_N-1] < quotes_pre[2][week_N - 2]:
week_N_trend = 10
elif week_N_rise_rate <= 0.012 :
week_N_trend = 10
elif week_N_rise_rate < 0:
if abs(week_N_rise_rate) > 0.03 and abs(week_N_rise_rate) > week_2N_rise_rate * 0.5 > 0:
week_N_trend = -1
elif abs(week_N_rise_rate) > 0.03 and abs(week_N_rise_rate) <= week_2N_rise_rate * 0.5:
week_N_trend = 10
elif 0.012 < abs(week_N_rise_rate) <= 0.03 and week_N_lowShadow < abs(week_N_rise) and \
abs(week_N_rise_rate) > week_2N_rise_rate * 0.5 > 0:
week_N_trend = -1
elif 0.012 < abs(week_N_rise_rate) <= 0.03 and week_N_lowShadow < abs(week_N_rise) and \
abs(week_N_rise_rate) < week_2N_rise_rate * 0.5:
week_N_trend = 10
elif 0.012 < abs(week_N_rise_rate) <= 0.03 and week_N_lowShadow >= abs(week_N_rise):
week_N_trend = 10
elif abs(week_N_rise_rate) <= 0.012 :
week_N_trend = 10
#情况(07)时W(N)周线定义:#####################
if week_1N_trend == 1 and week_1N_rise_rate < 0 and \
0.012< abs(week_1N_rise_rate) <0.03 and week_1N_lowShadow > abs(week_1N_rise):
if week_N_rise_rate > 0:
if week_N_rise_rate > 0.03 and quotes_pre[2][week_N-1] > quotes_pre[2][week_N - 2]:
week_N_trend = 1
elif week_N_rise_rate > 0.03 and quotes_pre[2][week_N-1] <= quotes_pre[2][week_N - 2]:
week_N_trend = 10
elif 0.012 < week_N_rise_rate <= 0.03 and week_N_upShadow < week_N_rise and \
quotes_pre[4][week_N-1] >= quotes_pre[2][week_N - 2]:
week_N_trend = 1
elif 0.012 < week_N_rise_rate <= 0.03 and week_N_upShadow < week_N_rise and \
quotes_pre[4][week_N-1] < quotes_pre[2][week_N - 2]:
week_N_trend = 10
elif 0.012 < week_N_rise_rate <= 0.03 and week_N_upShadow >= week_N_rise and \
quotes_pre[4][week_N-1] >= quotes_pre[2][week_N - 2]:
week_N_trend = 1
elif 0.012 < week_N_rise_rate <= 0.03 and week_N_upShadow >= week_N_rise and \
quotes_pre[4][week_N-1] < quotes_pre[2][week_N - 2]:
week_N_trend = 10
elif week_N_rise_rate <= 0.012:
week_N_trend = 10
elif week_N_rise_rate < 0:
if abs(week_N_rise_rate) > 0.03 and abs(week_N_rise_rate) > week_2N_rise_rate * 0.5 > 0:
week_N_trend = -1
elif abs(week_N_rise_rate) > 0.03 and abs(week_N_rise_rate) <= week_2N_rise_rate * 0.5:
week_N_trend = 10
elif 0.012 < abs(week_N_rise_rate) <= 0.03 and week_N_lowShadow < abs(week_N_rise) and \
abs(week_N_rise) > week_2N_rise * 0.5 > 0:
week_N_trend = -1
elif 0.012 < abs(week_N_rise_rate) <= 0.03 and week_N_lowShadow < abs(week_N_rise) and \
abs(week_N_rise) <= week_2N_rise * 0.5:
week_N_trend = 10
elif 0.012 < abs(week_N_rise_rate) <= 0.03 and week_N_lowShadow >= abs(week_N_rise):
week_N_trend = 10
elif abs(week_N_rise_rate) <= 0.012:
week_N_trend = 10
#情况(08)时W(N)周线定义:#####################
if week_1N_trend == 1 and week_1N_rise_rate < 0 and 0.012 < abs(week_1N_rise_rate) <= 0.03 and week_1N_lowShadow < abs(week_1N_rise):
if week_N_rise_rate > 0:
if week_N_rise_rate > 0.03 and quotes_pre[2][week_N-1] > quotes_pre[2][week_N - 2]:
week_N_trend = 1
elif week_N_rise_rate > 0.03 and quotes_pre[2][week_N-1] <= quotes_pre[2][week_N - 2]:
week_N_trend = 10
elif 0.012 < week_N_rise_rate <= 0.03 and week_N_upShadow < week_N_rise and quotes_pre[4][week_N-1] > quotes_pre[2][week_N - 2]:
week_N_trend = 1
elif 0.012 < week_N_rise_rate <= 0.03 and week_N_upShadow < week_N_rise and quotes_pre[4][week_N-1] <= quotes_pre[2][week_N - 2]:
week_N_trend = 10
elif 0.012 < week_N_rise_rate <= 0.03 and week_N_upShadow >= week_N_rise and quotes_pre[4][week_N-1] > quotes_pre[2][week_N - 2]:
week_N_trend = 1
elif 0.012 < week_N_rise_rate <= 0.03 and week_N_upShadow >= week_N_rise and quotes_pre[4][week_N-1] < quotes_pre[2][week_N - 2]:
week_N_trend = 10
elif 0 < week_N_rise_rate <= 0.012:
week_N_trend = 10
elif week_N_rise_rate < 0:
if abs(week_N_rise_rate) > 0.03 and abs(week_N_rise_rate) >= week_2N_rise_rate * 0.5 > 0:
week_N_trend = -1
elif abs(week_N_rise_rate) > 0.03 and abs(week_N_rise_rate) <= week_2N_rise_rate * 0.5:
week_N_trend = 10
elif 0.012 < abs(week_N_rise_rate) <= 0.03 and week_N_lowShadow < abs(week_N_rise) and \
abs(week_N_rise) > week_2N_rise * 0.5 > 0:
week_N_trend = -1
elif 0.012 < abs(week_N_rise_rate) <= 0.03 and week_N_lowShadow < abs(week_N_rise) and \
abs(week_N_rise) <= week_2N_rise * 0.5:
week_N_trend = 10
elif 0.012 < abs(week_N_rise_rate) <= 0.03 and week_N_lowShadow >= abs(week_N_rise):
week_N_trend = 10
elif abs(week_N_rise_rate) <= 0.012:
week_N_trend = 10
#情况(09)时W(N)周线定义:#####################
if week_1N_trend == 1 and week_1N_rise_rate < 0 and abs(week_1N_rise_rate) > 0.03:
if week_N_rise_rate > 0:
if week_N_rise_rate > 0.03 and quotes_pre[2][week_N-1] > quotes_pre[2][week_N - 2]:
week_N_trend = 1
elif week_N_rise_rate > 0.03 and quotes_pre[2][week_N-1] <= quotes_pre[2][week_N - 2]:
week_N_trend = 10
elif 0.012 < week_N_rise_rate <= 0.03 and week_N_upShadow < week_N_rise:
week_N_trend = 10
elif 0.012 < week_N_rise_rate <= 0.03 and week_N_upShadow >= week_N_rise:
week_N_trend = 10
elif week_N_rise_rate <= 0.012:
week_N_trend = 10
elif week_N_rise_rate < 0:
if abs(week_N_rise_rate) > 0.03 and abs(week_N_rise_rate) > week_2N_rise_rate * 0.5 > 0:
week_N_trend = -1
elif abs(week_N_rise_rate) > 0.03 and abs(week_N_rise_rate) <= week_2N_rise_rate * 0.5:
week_N_trend = 10
elif 0.012 < abs(week_N_rise_rate) <= 0.03 and week_N_lowShadow < abs(week_N_rise) and \
abs(week_N_rise) > week_2N_rise * 0.5 > 0:
week_N_trend = -1
elif 0.012 < abs(week_N_rise_rate) <= 0.03 and week_N_lowShadow < abs(week_N_rise) and \
abs(week_N_rise) <= week_2N_rise * 0.5:
week_N_trend = 10
elif 0.012 < abs(week_N_rise_rate) <= 0.03 and week_N_lowShadow >= abs(week_N_rise):
week_N_trend = 10
elif abs(week_N_rise_rate) <= 0.012:
week_N_trend = 10
#情况(10)时W(N)周线定义:#####################
if week_1N_trend == -2:
if week_N_rise_rate < 0:
if quotes_pre[2][week_N-1] <= quotes_pre[2][week_N - 2]:
week_N_trend = -1
elif quotes_pre[2][week_N-1] > quotes_pre[2][week_N - 2] and quotes_pre[4][week_N-1] < quotes_pre[3][week_N - 2]:
week_N_trend = -1
elif quotes_pre[2][week_N-1] > quotes_pre[2][week_N - 2] and quotes_pre[4][week_N-1] >= quotes_pre[3][week_N - 2]:
week_N_trend = 10
elif week_N_rise_rate > 0:
if week_1N_rise_rate < 0 and week_N_rise_rate < abs(week_1N_rise_rate) * 0.5:
week_N_trend = -1
elif week_1N_rise_rate < 0 and abs(week_1N_rise_rate) * 0.5 < week_N_rise_rate < abs(week_1N_rise_rate):
week_N_trend = 10
elif week_1N_rise_rate < 0 and week_N_rise_rate > abs(week_1N_rise_rate):
week_N_trend = 1
#情况(11)时W(N)周线定义:#####################
if week_1N_trend == -1 and week_1N_rise_rate < 0 and abs(week_1N_rise_rate) > 0.03:
if week_N_rise_rate < 0:
if quotes_pre[2][week_N-1] <= quotes_pre[2][week_N - 2]:
week_N_trend = -1
elif quotes_pre[2][week_N-1] > quotes_pre[2][week_N - 2] and quotes_pre[4][week_N-1] < quotes_pre[3][week_N - 2]:
week_N_trend = -1
elif quotes_pre[2][week_N-1] > quotes_pre[2][week_N - 2] and quotes_pre[4][week_N-1] >= quotes_pre[3][week_N - 2]:
week_N_trend = 10
elif week_N_rise_rate > 0:
if week_N_rise_rate < abs(week_1N_rise_rate)/3:
week_N_trend = -1
elif abs(week_1N_rise_rate)/3 <= week_N_rise_rate <= abs(week_1N_rise_rate) * 0.5:
week_N_trend = 10
elif week_N_rise_rate > abs(week_1N_rise_rate) * 0.5:
week_N_trend = 1
#情况(12)时W(N)周线定义:#####################
if week_1N_trend == -1 and week_1N_rise_rate < 0 and 0.012 < abs(week_1N_rise_rate) < 0.03 and week_1N_lowShadow < abs(week_1N_rise):
if week_N_rise_rate < 0:
if quotes_pre[2][week_N-1] <= quotes_pre[2][week_N - 2]:
week_N_trend = -1
elif quotes_pre[2][week_N-1] > quotes_pre[2][week_N - 2] and quotes_pre[4][week_N-1] < quotes_pre[3][week_N - 2]:
week_N_trend = -1
elif quotes_pre[2][week_N-1] > quotes_pre[2][week_N - 2] and quotes_pre[4][week_N-1] >= quotes_pre[3][week_N - 2]:
week_N_trend = 10
elif week_N_rise_rate > 0:
if week_N_rise_rate < abs(week_1N_rise_rate)/3:
week_N_trend = -1
elif abs(week_1N_rise_rate)/3 <= week_N_rise_rate <= abs(week_1N_rise_rate) * 0.5:
week_N_trend = 10
elif week_N_rise_rate > abs(week_1N_rise_rate) * 0.5:
week_N_trend = 1
#情况(13)时W(N)周线定义:#####################
if week_1N_trend == -1 and week_1N_rise_rate < 0 and 0.012 < abs(week_1N_rise_rate) < 0.03 and week_1N_lowShadow > abs(week_1N_rise):
if week_N_rise_rate < 0:
if quotes_pre[2][week_N-1] <= quotes_pre[2][week_N - 2]:
week_N_trend = -1
elif quotes_pre[2][week_N-1] > quotes_pre[2][week_N - 2] and quotes_pre[4][week_N-1] < quotes_pre[3][week_N - 2]:
week_N_trend = -1
elif quotes_pre[2][week_N-1] > quotes_pre[2][week_N - 2] and quotes_pre[4][week_N-1] >= quotes_pre[3][week_N - 2]:
week_N_trend = 10
elif week_N_rise_rate > 0:
if week_N_rise_rate > 0.03:
week_N_trend = 1
elif 0.012 < week_N_rise_rate < 0.03 and week_N_upShadow < week_N_rise and week_N_rise_rate > abs(week_1N_rise_rate):
week_N_trend = 1
elif 0.012 < week_N_rise_rate < 0.03 and week_N_upShadow < week_N_rise and week_N_rise_rate <= abs(week_1N_rise_rate):
week_N_trend = 10
elif 0.012 < week_N_rise_rate < 0.03 and week_N_upShadow >= week_N_rise:
week_N_trend = 10
elif week_N_rise_rate <= 0.012:
week_N_trend = 10
#情况(14)时W(N)周线定义:#####################
if week_1N_trend == -1 and week_1N_rise_rate < 0 and abs(week_1N_rise_rate) < 0.012:
if week_N_rise_rate < 0:
if abs(week_N_rise_rate) > 0.03:
week_N_trend = -1
elif 0.012 < abs(week_N_rise_rate) <= 0.03 and week_N_lowShadow < abs(week_N_rise):
week_N_trend = -1
elif 0.012 < abs(week_N_rise_rate) <= 0.03 and week_N_lowShadow >= abs(week_N_rise) and quotes_pre[3][week_N-1] < quotes_pre[3][week_N - 2]:
week_N_trend = -1
elif 0.012 < abs(week_N_rise_rate) <= 0.03 and week_N_lowShadow >= abs(week_N_rise) and quotes_pre[3][week_N-1] >= quotes_pre[3][week_N - 2]:
week_N_trend = 10
elif abs(week_N_rise_rate) <= 0.012 and quotes_pre[3][week_N-1] < quotes_pre[3][week_N - 2]:
week_N_trend = -1
elif abs(week_N_rise_rate) <= 0.012 and quotes_pre[3][week_N-1] >= quotes_pre[3][week_N - 2]:
week_N_trend = 10
elif week_N_rise_rate > 0:
week_N_trend = getSelfTrend(week_N)
#情况(15)时W(N)周线定义:#####################
if week_1N_trend == -1 and 0 < week_1N_rise_rate <= 0.012:
if week_N_rise_rate < 0:
if abs(week_N_rise_rate) > 0.03:
week_N_trend = -1
elif 0.012 < abs(week_N_rise_rate) <= 0.03 and week_N_lowShadow < abs(week_N_rise) and \
quotes_pre[4][week_N-1] <= quotes_pre[3][week_N - 2]:
week_N_trend = -1
elif 0.012 < abs(week_N_rise_rate) <= 0.03 and week_N_lowShadow < abs(week_N_rise) and \
quotes_pre[4][week_N-1] > quotes_pre[3][week_N - 2]:
week_N_trend = 10
elif 0.012 < abs(week_N_rise_rate) <= 0.03 and week_N_lowShadow >= abs(week_N_rise) and \
quotes_pre[4][week_N-1] <= quotes_pre[3][week_N - 2]:
week_N_trend = -1
elif 0.012 < abs(week_N_rise_rate) <= 0.03 and week_N_lowShadow >= abs(week_N_rise) and \
quotes_pre[4][week_N-1] > quotes_pre[3][week_N - 2]:
week_N_trend = 10
elif abs(week_N_rise_rate) <= 0.012:
week_N_trend = 10
elif week_N_rise_rate > 0:
if week_N_rise_rate > 0.03 and week_2N_rise_rate < 0 and week_N_rise_rate > abs(week_2N_rise_rate) * 0.5:
week_N_trend = 1
elif week_N_rise_rate > 0.03 and week_2N_rise_rate < 0 and week_N_rise_rate <= abs(week_2N_rise_rate) * 0.5:
week_N_trend = 10
elif 0.012 < week_N_rise_rate <= 0.03 and week_N_upShadow < week_N_rise and \
week_2N_rise_rate < 0 and week_N_rise_rate > abs(week_2N_rise_rate) * 0.5:
week_N_trend = 1
elif 0.012 < week_N_rise_rate <= 0.03 and week_N_upShadow < week_N_rise and \
week_2N_rise_rate < 0 and week_N_rise_rate <= abs(week_2N_rise_rate) * 0.5:
week_N_trend = 10
elif 0.012 < week_N_rise_rate <= 0.03 and week_N_upShadow >= week_N_rise:
week_N_trend = 10
elif week_N_rise_rate <= 0.012:
week_N_trend = 10
#情况(16)时W(N)周线定义:#####################
if week_1N_trend ==-1 and 0.012 < week_1N_rise_rate <= 0.03 and week_1N_upShadow > week_1N_rise:
if week_N_rise_rate < 0:
if abs(week_N_rise_rate) > 0.03 and quotes_pre[3][week_N-1] < quotes_pre[3][week_N - 2]:
week_N_trend = -1
elif abs(week_N_rise_rate) > 0.03 and quotes_pre[3][week_N-1] >= quotes_pre[3][week_N - 2]:
week_N_trend = 10
elif 0.012 < abs(week_N_rise_rate) <= 0.03 and week_N_lowShadow < abs(week_N_rise) and \
quotes_pre[4][week_N-1] <= quotes_pre[3][week_N - 2]:
week_N_trend = -1
elif 0.012 < abs(week_N_rise_rate) <= 0.03 and week_N_lowShadow < abs(week_N_rise) and \
quotes_pre[4][week_N-1] > quotes_pre[3][week_N - 2]:
week_N_trend = 10
elif 0.012 < abs(week_N_rise_rate) <= 0.03 and week_N_lowShadow >= abs(week_N_rise) and \
quotes_pre[4][week_N-1] <= quotes_pre[3][week_N - 2]:
week_N_trend = -1
elif 0.012 < abs(week_N_rise_rate) <= 0.03 and week_N_lowShadow >= abs(week_N_rise) and \
quotes_pre[4][week_N-1] > quotes_pre[3][week_N - 2]:
week_N_trend = 10
elif abs(week_N_rise_rate) <= 0.012:
week_N_trend = 10
elif week_N_rise_rate > 0:
if week_N_rise_rate > 0.03 and week_2N_rise_rate < 0 and week_N_rise_rate > abs(week_2N_rise_rate) * 0.5:
week_N_trend = 1
elif week_N_rise_rate > 0.03 and week_2N_rise_rate < 0 and week_N_rise_rate <= abs(week_2N_rise_rate) * 0.5:
week_N_trend = 10
elif 0.012 < week_N_rise_rate <= 0.03 and week_N_upShadow < week_N_rise and \
week_2N_rise_rate < 0 and week_N_rise_rate > abs(week_2N_rise_rate) * 0.5:
week_N_trend = 1
elif 0.012 < week_N_rise_rate <= 0.03 and week_N_upShadow < week_N_rise and \
week_2N_rise_rate < 0 and week_N_rise_rate <= abs(week_2N_rise_rate) * 0.5:
week_N_trend = 10
elif 0.012 < week_N_rise_rate <= 0.03 and week_N_upShadow > week_N_rise:
week_N_trend = 10
if week_N_rise_rate <= 0.012:
week_N_trend = 10
#情况(17)时W(N)周线定义:#####################
if week_1N_trend ==-1 and 0.012 < week_1N_rise_rate <= 0.03 and week_1N_upShadow < week_1N_rise:
if week_N_rise_rate < 0:
if abs(week_N_rise_rate) > 0.03 and quotes_pre[3][week_N-1] < quotes_pre[3][week_N - 2]:
week_N_trend = -1
elif abs(week_N_rise_rate) > 0.03 and quotes_pre[3][week_N-1] >= quotes_pre[3][week_N - 2]:
week_N_trend = 10
elif 0.012 < abs(week_N_rise_rate) <= 0.03 and week_N_lowShadow < abs(week_N_rise) and \
quotes_pre[4][week_N-1] <= quotes_pre[3][week_N - 2]:
week_N_trend = -1
elif 0.012 < abs(week_N_rise_rate) <= 0.03 and week_N_lowShadow < abs(week_N_rise) and \
quotes_pre[4][week_N-1] > quotes_pre[3][week_N - 2]:
week_N_trend = 10
elif 0.012 < abs(week_N_rise_rate) <= 0.03 and week_N_lowShadow >= abs(week_N_rise) and \
quotes_pre[4][week_N-1] <= quotes_pre[3][week_N - 2]:
week_N_trend = -1
elif 0.012 < abs(week_N_rise_rate) <= 0.03 and week_N_lowShadow >= abs(week_N_rise) and \
quotes_pre[4][week_N-1] > quotes_pre[3][week_N - 2]:
week_N_trend = 10
elif abs(week_N_rise_rate) <= 0.012:
week_N_trend = 10
elif week_N_rise_rate > 0:
if week_N_rise_rate > 0.03 and week_2N_rise_rate < 0 and week_N_rise_rate > abs(week_2N_rise_rate) * 0.5:
week_N_trend = 1
elif week_N_rise_rate > 0.03 and week_2N_rise_rate < 0 and week_N_rise_rate <= abs(week_2N_rise_rate) * 0.5:
week_N_trend = 10
elif 0.012 < week_N_rise_rate <= 0.03 and week_N_upShadow < week_N_rise and \
week_2N_rise_rate < 0 and week_N_rise_rate > abs(week_2N_rise_rate) * 0.5:
week_N_trend = 1
elif 0.012 < week_N_rise_rate <= 0.03 and week_N_upShadow < week_N_rise and \
week_2N_rise_rate < 0 and week_N_rise_rate <= abs(week_2N_rise_rate) * 0.5:
week_N_trend = 10
elif 0.012 < week_N_rise_rate <= 0.03 and week_N_upShadow >= week_N_rise:
week_N_trend = 10
if week_N_rise_rate <= 0.012:
week_N_trend = 10
#情况(18)时W(N)周线定义:#####################
if week_1N_trend == -1 and week_1N_rise_rate > 0.03:
if week_N_rise_rate < 0:
if abs(week_N_rise_rate) > 0.03 and quotes_pre[3][week_N-1] < quotes_pre[3][week_N - 2]:
week_N_trend = -1
elif abs(week_N_rise_rate) > 0.03 and quotes_pre[3][week_N-1] >= quotes_pre[3][week_N - 2]:
week_N_trend = 10
elif 0.012 < abs(week_N_rise_rate) <= 0.03 and week_N_lowShadow < abs(week_N_rise) :
week_N_trend = 10
elif 0.012 < abs(week_N_rise_rate) <= 0.03 and week_N_lowShadow >= abs(week_N_rise) :
week_N_trend = 10
elif abs(week_N_rise_rate) <= 0.012:
week_N_trend = 10
elif week_N_rise_rate > 0:
if week_N_rise_rate > 0.03 and week_2N_rise_rate < 0 and week_N_rise_rate > abs(week_2N_rise_rate) * 0.5:
week_N_trend = 1
elif week_N_rise_rate > 0.03 and week_2N_rise_rate < 0 and week_N_rise_rate <= abs(week_2N_rise_rate) * 0.5:
week_N_trend = 10
elif 0.012 < week_N_rise_rate <= 0.03 and week_N_upShadow < week_N_rise and \
week_2N_rise_rate < 0 and week_N_rise_rate > abs(week_2N_rise_rate) * 0.5:
week_N_trend = 1
elif 0.012 < week_N_rise_rate <= 0.03 and week_N_upShadow < week_N_rise and \
week_2N_rise_rate < 0 and week_N_rise_rate <= abs(week_2N_rise_rate) * 0.5:
week_N_trend = 10
elif 0.012 < week_N_rise_rate <= 0.03 and week_N_upShadow >= week_N_rise:
week_N_trend = 10
if week_N_rise_rate <= 0.012:
week_N_trend = 10
#情况(19、20)时W(N)周线定义:#####################
if week_1N_trend in [0, 10]:
week_N_trend = getSelfTrend(week_N)
#将W(N)周的 selfAdjustTrend 存入全局变量:
if week_N not in g_selfAdjustTrend_wk: #如全局变量列表中没有数据,则将该值存入全局变量中
g_selfAdjustTrend_wk.append( week_N )
g_selfAdjustTrend.append( week_N_trend )
return week_N_trend
# 5、阻力定义函数: getResistanceList(week_N)##############################################
# 获得第N周的阻力 resistanceList, [0]阻力价格列表,[1]阻力类型,[2]存储阻力来源。阻力由小到达进行排序
def getResistanceList(week_N):
resistancePrice = [] #存储 week_N 周所有的阻力值。
resistanceOrigin = [] #存储 week_N 周所有阻力类型。=11,反转阻力;=22,突破阻力;=33,重现阻力。
resistanceWeekNo = [] #存储 week_N 周所有阻力的来源周。
resistanceList = [[],[],[]] #阻力列表:[0]存储resistancePrice, [1]存储resistanceOrigin,[2]存储阻力的来源周
resistancePrice_1N = []
resistanceOrigin_1N = []
resistanceWeekNo_1N = []
resistanceList_1N = [[],[]]
# week_N的涨幅(跌幅):
week_N_rise = (quotes_pre[4][week_N-1] - quotes_pre[4][week_N-2]) #上涨(下跌)值
week_N_rise_rate = week_N_rise / quotes_pre[4][week_N-2] #涨幅(跌幅)
# week_N的上(下)影线:
up_shadow = quotes_pre[2][week_N-1] - max(quotes_pre[1][week_N-1], quotes_pre[4][week_N-1]) #上影线
down_shadow = min(quotes_pre[1][week_N-1], quotes_pre[4][week_N-1]) - quotes_pre[3][week_N-1] #下影线
quotes_f_list = [[],[]] #将所有波峰,按时间从近到远进行排序,[0]存储价格,[1]存储波峰属于哪一周
quotes_g_list = [[],[]] #将所有波谷,按时间从近到远进行排序,[0]存储价格,[1]存储波峰属于哪一周
for i in range( len(quotes_fg_price) )[::-1]:
if( quotes_fg_direction[i] == 1 and quotes_fg_index[i] < week_N - 2 ):# week_1N 之前(不含week_1N)的波峰
quotes_f_list[0].append( quotes_fg_price[i] )
quotes_f_list[1].append( quotes_fg_index[i] )
elif( quotes_fg_direction[i] == 0 and quotes_fg_index[i] < week_N - 2 ):# week_1N 之前(不含week_1N)的波谷
quotes_g_list[0].append( quotes_fg_price[i] )
quotes_g_list[1].append( quotes_fg_index[i] )
if week_N in [1, 2, 3]:#第三周的阻力,设为默认值为本周阻力:
resistancePrice.append(0)
resistanceOrigin.append(33)
resistanceWeekNo.append(week_N)
resistancePrice.append(200000)
resistanceOrigin.append(33)
resistanceWeekNo.append(week_N)
elif week_N > 3:#第三周之后某周的阻力,用递归方法得到本周阻力:
#步骤1:得到本周前一周阻力
if week_N -1 in g_resistanceList_wk:#如全局变量列表中已有数据,则使用全局变量
index_g_resceList = g_resistanceList_wk.index(week_N -1 )
resistanceList_1N = copy.deepcopy( g_resistanceList[index_g_resceList] )
else:
resistanceList_1N = getResistanceList(week_N -1)
resistancePrice_1N = copy.deepcopy( resistanceList_1N[0] )
resistanceOrigin_1N = copy.deepcopy( resistanceList_1N[1] )
resistanceWeekNo_1N = copy.deepcopy( resistanceList_1N[2] )
existedResceList = [] #以[[weekNo0,resceType0],,,,]结构存储已有阻力
for i in range( len(resistancePrice_1N) ):
existedResceList.append( [resistanceWeekNo_1N[i],resistanceOrigin_1N[i]] )
#步骤2:得到本周失效的阻力
#第一类失效:反转了阻力11,
reverse = getReverse(week_N)
if reverse==1: #删除11类阻力
if 11 in resistanceOrigin_1N:
resistanceIndex = resistanceOrigin_1N.index(11) # 11类阻力最多只有一个
g_resceAbateList.append( [resistanceWeekNo_1N[resistanceIndex],11] )
resistancePrice_1N.pop(resistanceIndex) #删除11阻力价格
resistanceOrigin_1N.pop(resistanceIndex) #删除11阻力类型
resistanceWeekNo_1N.pop(resistanceIndex) #删除11阻力类型
#第二类失效:击穿了阻力11、22、33
for i in range(len(resistancePrice_1N))[::-1]: #resistancePrice_1N.pop()函数会改变resistancePrice_1N的长度,导致坐标i错位,所以逆序删除。
resistancePrice = resistancePrice_1N[i]
if resistancePrice in [0,200000]:#默认阻力[0,200000]不会被击穿
continue
elif resistancePrice < quotes_pre[4][week_N - 2]:#阻力小于W(N-1)收盘价,属于W(N)的下阻力
if quotes_pre[3][week_N - 1] < resistancePrice - 20*tick:
g_resceAbateList.append( [resistanceWeekNo_1N[i],resistanceOrigin_1N[i]] )
resistancePrice_1N.pop(i)
resistanceOrigin_1N.pop(i)
resistanceWeekNo_1N.pop(i)
elif resistancePrice >= quotes_pre[4][week_N - 2]:#阻力大于W(N-1)收盘价,属于W(N)的上阻力
if quotes_pre[2][week_N - 1] > resistancePrice + 20*tick:
g_resceAbateList.append( [resistanceWeekNo_1N[i],resistanceOrigin_1N[i]] )
resistancePrice_1N.pop(i)
resistanceOrigin_1N.pop(i)
resistanceWeekNo_1N.pop(i)
#步骤3:得到本周新增的阻力
resistancePrice = copy.deepcopy( resistancePrice_1N )
resistanceOrigin = copy.deepcopy( resistanceOrigin_1N )
resistanceWeekNo = copy.deepcopy( resistanceWeekNo_1N )
resceIndex = 0
#第一类阻力来源:产生新反转类阻力11
if reverse == 1:
if week_N_rise_rate > 0 and len(quotes_f_list[0]) > 0:
resceIndex = quotes_f_list[1][0]
if quotes_f_list[0][0] > quotes_pre[2][week_N-1] - 20*tick and [resceIndex,11] not in existedResceList and [resceIndex,11] not in g_resceAbateList:
resistancePrice.append( quotes_f_list[0][0] )
resistanceOrigin.append(11)
resistanceWeekNo.append( resceIndex )
elif week_N_rise_rate < 0 and len(quotes_g_list[0]) > 0:
resceIndex = quotes_g_list[1][0]
if quotes_g_list[0][0] < quotes_pre[3][week_N-1] + 20*tick and [resceIndex,11] not in existedResceList and [resceIndex,11] not in g_resceAbateList:
resistancePrice.append( quotes_g_list[0][0] )
resistanceOrigin.append(11)
resistanceWeekNo.append( resceIndex )
#第二类阻力来源:产生新突破类阻力22
poss_f_Price = 0 #记录上一个可能的阻力值
poss_g_Price = 200000 #记录可能的阻力值
if week_N_rise_rate > 0.03 or ( 0.012 < week_N_rise_rate <= 0.03 and up_shadow < week_N_rise ):
#找符合约束条件的波峰:
quotes_f_index = -1 # quotes_f_index即为所求波峰
j1 = 0 # 记录遍历符合条件波峰的个数
for i in range( len(quotes_f_list[0]) ):
quotes_f_index = quotes_f_list[1][i]#波峰周在quotes序列中的下标
if j1 == 5: #如果已查找了5个波峰,直接结束循环
break
if quotes_f_list[0][i] > poss_f_Price: #找比f1之前更高的波峰f2
if quotes_pre[2][week_N-2] < quotes_pre[2][quotes_f_index] <= quotes_pre[2][week_N-1] - 40*tick and \
quotes_pre[4][quotes_f_index] <= quotes_pre[4][week_N-1] - 3*tick:#找到了符合条件的波峰
poss_f_Price = quotes_pre[2][quotes_f_index] #将当前波峰价格设为f2,以此为基础找f3
j1 = j1 + 1
if poss_f_Price != 0 and [quotes_f_index,22] not in existedResceList and [quotes_f_index,22] not in g_resceAbateList: #当前可能的阻力不是默认值0,该阻力即为要找的22类阻力
resistancePrice.append( poss_f_Price )
resistanceOrigin.append(22)
resistanceWeekNo.append( quotes_f_index )
if week_N_rise_rate < -0.03 or ( -0.03 <= week_N_rise_rate < -0.012 and down_shadow < abs(week_N_rise) ):
#找符合约束条件的波谷:
quotes_g_index = -1 # quotes_g_index即为所求波谷
j1 = 0 # 记录遍历符合条件波谷的个数
for i in range( len(quotes_g_list[0]) ):
quotes_g_index = quotes_g_list[1][i]#波谷周在quotes序列中的下标
if j1 == 5: #如果已查找了5个波谷,直接结束循环
break
if quotes_g_list[0][i] < poss_g_Price: #找比g1之前更低的波谷g2
if quotes_pre[3][week_N-2] > quotes_pre[3][quotes_g_index] >= quotes_pre[3][week_N-1] + 40*tick and \
quotes_pre[4][quotes_g_index] >= quotes_pre[4][week_N-1] + 3*tick:#找到了符合条件的波峰
poss_g_Price = quotes_pre[3][quotes_g_index] #将当前波谷价格设为g2,以此为基础找g3
j1 = j1 + 1
if poss_g_Price != 200000 and [quotes_g_index,22] not in existedResceList and [quotes_g_index,22] not in g_resceAbateList: #当前可能的阻力即要找的22类阻力
resistancePrice.append( poss_g_Price )
resistanceOrigin.append(22)
resistanceWeekNo.append( quotes_g_index )
#第三类阻力来源:产生新重现类阻力33的“上阻力”
f_list_np = np.array(quotes_f_list) # 将阻力数组(list)转换成numpy数组(array)
f_list_np_order = f_list_np.T[np.lexsort(f_list_np[::-1,:])].T #按第1行价格值,从小到大进行排序
f_list_np_order_diff = [[],[]]
f_list_np_order_diff[0] = np.diff(f_list_np_order[0])
f_list_np_order_diff[0] = np.append(f_list_np_order_diff[0], [0]) # f_list_np_order_diff 比 f_list_np_order 少一个元素,用0补上空位。
f_list_np_order_diff[1] = copy.deepcopy( f_list_np_order[1] )
for i in range( len(f_list_np_order_diff[1]) - 1 ):
if f_list_np_order_diff[0][i] < 10 * tick: # 即 0<=峰值2-峰值1<10,波峰1是阻力
# 检查两个波峰间的元素是否符合要求:
begin = int( min( f_list_np_order_diff[1][i] , f_list_np_order_diff[1][i+1] ) )
end = int( max( f_list_np_order_diff[1][i] , f_list_np_order_diff[1][i+1] ) )
quotes_high_between = quotes_pre[2][ begin+1 : end] # 提取在两个波峰间的最高价
quotes_high_between_np = np.array(quotes_high_between) # 将阻力数组(list)转换成numpy数组(array)
if len(quotes_high_between_np) == 0 :
continue
elif quotes_high_between_np.max() < f_list_np_order[0][i] and [end,33] not in existedResceList and [end,33] not in g_resceAbateList:
#产生一个阻力值:
resistancePrice.append( f_list_np_order[0][i] ) #波谷数组中存的价格即为当日最高价
resistanceOrigin.append( 33 )
resistanceWeekNo.append( end )
#第三类阻力来源:产生新重现类阻力33的“下阻力”
g_list_np = np.array(quotes_g_list) # 将阻力数组(list)转换成numpy数组(array)
g_list_np_order = g_list_np.T[np.lexsort(g_list_np[::-1,:])].T #按第1行价格值,从小到大进行排序
g_list_np_order_diff = [[],[]]
g_list_np_order_diff[0] = np.diff(g_list_np_order[0])
g_list_np_order_diff[0] = np.append(g_list_np_order_diff[0], [0]) # g_list_np_order_diff 比 g_list_np_order 少一个元素,用0补上空位。
g_list_np_order_diff[1] = copy.deepcopy( g_list_np_order[1] )
for i in range( len(g_list_np_order_diff[1]) - 1 ):
if g_list_np_order_diff[0][i] < 10 * tick: # 即 0<=谷值2-谷值1<10,波谷2是阻力
# 检查两个波谷间的元素是否符合要求:
begin = int( min( g_list_np_order_diff[1][i] , g_list_np_order_diff[1][i+1] ) )
end = int( max( g_list_np_order_diff[1][i] , g_list_np_order_diff[1][i+1] ) )
quotes_low_between = quotes_pre[3][ begin+1 : end] # 提取在两个波谷间各点的最低价
quotes_low_between_np = np.array(quotes_low_between) # 将阻力数组(list)转换成numpy数组(array)
if len(quotes_low_between_np) == 0 :
continue
elif quotes_low_between_np.min() > g_list_np_order[0][i+1] and [end,33] not in existedResceList and [end,33] not in g_resceAbateList:
#产生一个阻力值:
resistancePrice.append(g_list_np_order[0][i+1]) #波谷数组中存的价格即为当日最高价
resistanceOrigin.append( 33 )
resistanceWeekNo.append( end )
resistanceList[0] = copy.deepcopy( resistancePrice )
resistanceList[1] = copy.deepcopy( resistanceOrigin )
resistanceList[2] = copy.deepcopy( resistanceWeekNo )
#将W(N)周的 resistanceList 存入全局变量:
if week_N not in g_resistanceList_wk: #如全局变量列表中没有数据,则将该值存入全局变量中
g_resistanceList_wk.append( week_N )
g_resistanceList.append( resistanceList )
return resistanceList
# 6、综合周线判断函数:getSynthesizeTrend(week_N)########################################
# 通过W(N-1)的综合周线判断,结合W(N)的阻力空间,判断出W(N)的综合周线判断。
# SynthesizeTrend = =-1表示趋势明显空,=1表示趋势明显多,=10表示宽幅震荡。