Prechádzať zdrojové kódy

修订格式及入库方案
if_exists='replace' 以确保每日复权数据有效

Daniel 2 rokov pred
rodič
commit
26f9779a2a
1 zmenil súbory, kde vykonal 12 pridanie a 13 odobranie
  1. 12 13
      QMT/get_macd.py

+ 12 - 13
QMT/get_macd.py

@@ -2,9 +2,6 @@
 from datetime import datetime as dt
 import os
 import pandas as pd
-# from xtquant.xttrader import XtQuantTrader, XtQuantTraderCallback
-# from xtquant.xttype import StockAccount
-# from xtquant import xtdata, xtconstant
 import time
 from sqlalchemy import create_engine
 from jqdatasdk import *
@@ -13,11 +10,13 @@ import multiprocessing as mp
 import math
 import talib as ta
 
-pd.set_option('display.max_columns', None) # 设置显示最大行
+# pd.set_option('display.max_columns', None)  # 设置显示最大行
+
 
 def err_call_back(err):
     print(f'出错啦~ error:{str(err)}')
 
+
 def myself_kdj(df):
     low_list = df['low'].rolling(9, min_periods=9).min()
     low_list.fillna(value=df['low'].expanding().min(), inplace=True)
@@ -60,12 +59,12 @@ def get_bias(df):
     # 计算方法:
     # bias指标
     # N期BIAS=(当日收盘价-N期平均收盘价)/N期平均收盘价*100%
-    df['bias_6'] = (df['close'] - df['close'].rolling(6, min_periods=1).mean()) / df['close'].rolling(6,
-                                                                                                      min_periods=1).mean() * 100
-    df['bias_12'] = (df['close'] - df['close'].rolling(12, min_periods=1).mean()) / df['close'].rolling(12,
-                                                                                                        min_periods=1).mean() * 100
-    df['bias_24'] = (df['close'] - df['close'].rolling(24, min_periods=1).mean()) / df['close'].rolling(24,
-                                                                                                        min_periods=1).mean() * 100
+    df['bias_6'] = (df['close'] - df['close'].rolling(6, min_periods=1).mean()) / \
+                    df['close'].rolling(6, min_periods=1).mean() * 100
+    df['bias_12'] = (df['close'] - df['close'].rolling(12, min_periods=1).mean()) / \
+                     df['close'].rolling(12, min_periods=1).mean() * 100
+    df['bias_24'] = (df['close'] - df['close'].rolling(24, min_periods=1).mean()) / \
+                     df['close'].rolling(24, min_periods=1).mean() * 100
     df['bias_6'] = round(df['bias_6'], 2)
     df['bias_12'] = round(df['bias_12'], 2)
     df['bias_24'] = round(df['bias_24'], 2)
@@ -88,7 +87,7 @@ def tech_anal(datas):
         get_bias(df)
         get_wilr(df)
         df = df.reset_index(drop=True)
-        df.to_sql('%s_1d' % stock, con=engine_tech, index=False, if_exists='append')
+        df.to_sql('%s_1d' % stock, con=engine_tech, index=False, if_exists='replace')
         # with engine.connect() as con:
         #     con.execute("ALTER TABLE `%s_1d` ADD PRIMARY KEY (`time`);" % stock)
         print(stock, df)
@@ -108,10 +107,10 @@ if __name__ == '__main__':
     step = 100
 
     for i in range(0, len(stock_pool), step):
-        pool.apply_async(func=tech_anal, args=(stock_pool[i:i+step],), error_callback=err_call_back)
+        pool.apply_async(func=tech_anal, args=(stock_pool[i:i + step],), error_callback=err_call_back)
 
     pool.close()
     pool.join()
     edtime = dt.now()
 
-    print(edtime-sttime)
+    print(edtime - sttime)