Daniel 2 rokov pred
rodič
commit
e08c644f88
1 zmenil súbory, kde vykonal 21 pridanie a 23 odobranie
  1. 21 23
      futures_backtrader.py

+ 21 - 23
futures_backtrader.py

@@ -130,6 +130,20 @@ class TestStrategy(bt.Strategy):
 
     def stop(self):
         # pass
+        print(f'以{num}内最低值波动{Volatility}为支撑、乖离率为{rate}%,结果状态为:')
+        print('正盈利的个股为:', len(result_change), '成功率为:', len(result) / len(table_list))
+        print(
+            f'总盈利:{np.sum(result_change)} 平均盈利:{np.mean(result_change)},最大盈利:{np.max(result_change)}, 最小盈利:{np.min(result_change)}')
+        print(
+            f'总亏损:{np.sum(result_change_fall)},平均亏损:{np.mean(result_change_fall)},最大亏损:{np.min(result_change_fall)} 最小亏损:{np.max(result_change_fall)}')
+        endtime = dt.now()
+        df.loc[len(df)] = [num, Volatility, len(result), len(result) / len(table_list), np.sum(result_change),
+                           np.mean(result_change), np.max(result_change), np.min(result_change),
+                           np.sum(result_change_fall), np.mean(result_change_fall),
+                           np.min(result_change_fall), np.max(result_change_fall)]
+        print(df)
+        print('每轮耗时:', endtime - stattime)
+        df.to_csv(r'D:\Daniel\策略\策略穷举.csv', index=True)
         self.log(u'(MA趋势交易效果) Ending Value %.2f' % (self.broker.getvalue()))
 
 
@@ -216,20 +230,18 @@ if __name__ == '__main__':
 
 
     sttime = dt.now()
-
-    for num in range(60, 140, 20):
+    thread_list = []
+    for num in range(30, 70, 10):
         for Volatility in range(8, 10, 1):
             for rate in range(7, 10, 1):
                 step = math.ceil(len(table_list) / mp.cpu_count())
-                thread_list = []
+
                 result = mp.Manager().list()
                 result_change = mp.Manager().list()
                 result_change_fall = mp.Manager().list()
                 err_list = mp.Manager().list()
                 print(f'{num}天波动率为{Volatility}%乖离率为{rate}')
                 for i in range(0, len(table_list), step):
-
-
                     stattime = dt.now()
                     # thd = threading.local()
                     # print(i)
@@ -239,24 +251,10 @@ if __name__ == '__main__':
                     # p.start()
                     # p.join()
                     # print(thread_list)
-                for thread in thread_list:
-                    thread.start()
-                for thread in thread_list:
-                    thread.join()
-
-                print(f'以{num}内最低值波动{Volatility}为支撑、乖离率为{rate}%,结果状态为:')
-                print('正盈利的个股为:', len(result_change), '成功率为:', len(result)/len(table_list))
-                print(f'总盈利:{np.sum(result_change)} 平均盈利:{np.mean(result_change)},最大盈利:{np.max(result_change)}, 最小盈利:{np.min(result_change)}')
-                print(
-                    f'总亏损:{np.sum(result_change_fall)},平均亏损:{np.mean(result_change_fall)},最大亏损:{np.min(result_change_fall)} 最小亏损:{np.max(result_change_fall)}')
-                endtime = dt.now()
-                df.loc[len(df)] = [num, Volatility, len(result), len(result)/len(table_list), np.sum(result_change),
-                                                np.mean(result_change), np.max(result_change), np.min(result_change),
-                                                np.sum(result_change_fall), np.mean(result_change_fall),
-                                                np.min(result_change_fall), np.max(result_change_fall)]
-                print(df)
-                print('每轮耗时:', endtime-stattime)
-                df.to_csv(r'D:\Daniel\策略\策略穷举.csv', index=True)
+    for thread in thread_list:
+        thread.start()
+    for thread in thread_list:
+        thread.join()
     edtime = dt.now()
     print('总耗时:', edtime - sttime)
     # df.to_csv(r'C:\Users\Daniel\Documents\策略穷举2.csv', index=True)