Esempio n. 1
0
def GetAllHistoryDataAndSaveTo_MultiProcess(folder, autype='hfq', forceUpdate=False):
    if autype == 'hfq':
        subFolder = u'%s/后复权/同花顺/XLS/' % (folder)
    elif autype == 'qfq':
        subFolder = u'%s/前复权/同花顺/XLS/' % (folder)
    elif autype == 'bfq':
        subFolder = u'%s/不复权/同花顺/XLS/' % (folder)
    else:
        subFolder = u'%s/后复权/同花顺/XLS/' % (folder)
    if forceUpdate:
        DeleteFolderNotEmpty(subFolder)
    CheckFileName(subFolder)

    import tushare as ts
    allStock = ts.get_stock_basics()
    sortedIndexs = sorted(allStock.index)
    jobs = []
    _initCookieQueue()
    for stockID in sortedIndexs:
        # 过滤掉创业板
        if re.findall("^30\d", stockID):
            continue
        file_name = u'%s/%s.xls' % (subFolder, stockID)
        if IsFileExist(file_name):
            continue
        cookie = _getNextCookie()
        eng = jqka.CHisotryDataEngine_10jqka()
        jobs.append([eng, stockID, autype, cookie, file_name])

    mgr = CMultiProcessMgr()
    mgr.StartMultiProcess(10, jobs, GetAllHistoryData_MultiProcess_Fun,False)
Esempio n. 2
0
    def SaveAnalysisResultToFile(self,
                                 result,
                                 retFileFullName,
                                 sheetName='result'):
        title = None
        retData = []
        if isinstance(result, (dict, )):
            for _, value in result.items():
                if not isinstance(value, (list, tuple)):
                    continue
                li = self.ListDictToList(value)
                if title is None:
                    title = li[0]
                if title != li[0]:
                    raise Exception('title not the same')
                retData.extend(li[1:])
        elif isinstance(result, (list, tuple)):
            li = self.ListDictToList(result)
            title = li[0]
            retData.extend(li[1:])
        else:
            raise Exception('data error')

        CheckFileName(retFileFullName)
        res = pd.DataFrame(retData, columns=title)
        res.to_excel(retFileFullName, sheetName, encoding='GBK', index=False)
def TestOneFolder_ALTA(folder, saveFolder, retFileFullName):
    CheckFileName(saveFolder)
    analyzer = ALTA.CAverageLineThroughAnalysisBase()
    res = AnalysisOneFolderWithMultiProcess(folder, analyzer, 1, None, None)
    # 分析倒数一天的数据
    analyzer.SaveAnalysisResultToFile(res, retFileFullName)
    for stockID in res:
        fileName = u'%s%s.xls' % (folder, stockID)
        print(stockID)
        saveFile = u'%s/all/%s.xls' % (saveFolder, stockID)
        test = ALTA.CAverageLineThroughAnalysisBase()
        result = test.doManualTest(fileName, 30, None)
        test.SaveAnalysisResultToFile(result, saveFile)
def GetAllHistoryDataAndSaveTo(folder, autype='hfq', forceUpdate=False):
    if autype == 'hfq':
        subFolder = u'%s/后复权/同花顺/XLS/' % (folder)
    elif autype == 'qfq':
        subFolder = u'%s/前复权/同花顺/XLS/' % (folder)
    elif autype == 'bfq':
        subFolder = u'%s/不复权/同花顺/XLS/' % (folder)
    else:
        subFolder = u'%s/后复权/同花顺/XLS/' % (folder)
    if forceUpdate:
        DeleteFolderNotEmpty(subFolder)
    CheckFileName(subFolder)

    import tushare as ts
    allStock = ts.get_stock_basics()
    eng = jqka.CHisotryDataEngine_10jqka()
    count = 1
    start = datetime.datetime.now()
    last = start
    size = len(allStock.index)
    sortedIndexs = sorted(allStock.index)
    index = 1
    for stockID in sortedIndexs:
        # 过滤掉创业板
        if re.findall("^30\d", stockID):
            count += 1
            continue
        file_name = u'%s/%s.xls' % (subFolder, stockID)
        if IsFileExist(file_name):
            count += 1
            continue
        cookie = _getNextCookie()
        dataFrame = eng.getHistoryDataFromStartToNow(stockID, autype, cookie)
        #dataFrame = eng.getHistoryDataLastDay(stockID, autype, cookie)
        sleep(0.01)
        if dataFrame is None:
            print('stockID:%06d data is none' % (int(stockID)))
            continue
        dataFrame.to_excel(file_name, encoding='GBK', index=False)
        current = datetime.datetime.now()
        t = (current - last)
        total = current - start
        print("==StockID:%s,index:%d,all:%d,remain:%d,    \
              time:%s,totalTime:%s==" % (stockID, index, size, size-count,
                                         t, total))
        last = current
        count += 1
        index += 1
    allTime = datetime.datetime.now() - start
    print('allTime:%s' % (allTime))