예제 #1
0
    def real(cls, **kwargs):
        # 包装一个函数
        def real_func(di):
            return CrossAction(di['kline'], di['date'], di['task'], di['codes']).batch()

        scs = np.array(kd.field('XDXR_day', 'stock_code'))
        bt = dt.timedelta(2018, 3, 21)
        args = [{'kline': 'XDXR_day', 'date': bt, 'task': i, 'codes': scs} for i in range(1, 5, 1)]
        pool = multiprocessing.Pool(processes=4)
        result = pool.map(real_func, args)
        pool.close()
        pool.join()
        [print(r) for r in result]
        pass
예제 #2
0
 def batch_his(self, start, end):
     # 方案一,我们不使用多进程,直接对全市场的股票进行历史信号采集
     codes = kd.field(table_name='XDXR_day', field_name='stock_code')
     traitors = pd.DataFrame([])
     # 为了更快的演示程序,我们只计算10只股票
     for sc in codes[0:9]:
         _rls = self.one_his(sc, start, end)
         traitors = pd.concat([traitors, _rls], axis=0, join='outer', ignore_index=True)
     # 最后我们建议将traitors存入数据库,这肯定需要自己去执行
     # 为了方便演示,这个不存入数据库,直接输出
     print(traitors.head(2).T)
     # 为了区别开每一次历史数据的采集结果,我们添加一个字段version
     traitors['version'] = 1
     # 为了方便下一步的验证,我们将这个结果保存为一个csv文件
     traitors.to_csv(path_or_buf='D:traitors.csv', index=False)
     pass
예제 #3
0
 def __init__(self, kline, date_time, task=0, codes=None):
     self.task = task
     self.kline = kline
     self.date_time = date_time
     self.codes = codes if codes is not None else np.array(kd.field(kline, 'stock_code'))
     pass