Пример #1
0
def getstockdayline(stocklist):
    #删除0字节文件
    for code in (stocklist):
        prefix = get_stock_market(code)
        file = stock_day_line_file + prefix + code + '.csv'
        if os.path.exists(file):
            if os.path.getsize(file) == 0:
                #print(file)
                os.remove(file)
    time.sleep(5)

    error_file = open('error-UPDATE.log', 'w')
    for code in (stocklist):
        stop_catch = False
        prefix = get_stock_market(code)
        file = stock_day_line_file + prefix + code + '.csv'
        #读取已下载最新日期
        if os.path.exists(file):
            alldata = pd.read_csv(file, names=stock_day_line_headers)
            lasteddate = alldata.iloc[0]['date']
            #print((lasteddate))
        else:
            lasteddate = '1990-12-19'
        #print(code,lasteddate,type(lasteddate))
        if prefix in ['sh', 'sz']:
            try:
                for year in range(2017, 1989, -1):  #1989
                    for season in range(4, 0, -1):
                        if stop_catch:
                            break
                        #print(year,season,stop_catch)
                        stop_catch = getstockdaylineupdate(
                            code, year, season, file, lasteddate, stop_catch)
                    if stop_catch:
                        break
            except Exception as e:
                error_file.write(code + '\n')
                #print(e)
                error_file.flush()
            #重新排序
            alldata = csv.reader(open(file), delimiter=',')
            sortedlist = sorted(alldata, key=lambda x: (x[0]), reverse=True)
            with open(file, "w", newline='') as f:
                fileWriter = csv.writer(f, delimiter=',')
                for row in sortedlist:
                    fileWriter.writerow(row)

    error_file.close()
Пример #2
0
def minchoice(logfile):
    print('minchoice output' + ':\n')
    logfile.write('minchoice output' + ':\n')
    for code in depickle_stock_list():
        #print(code)
        market = get_stock_market(code)
        if market in ['sh', 'sz']:
            try:
                if market == 'sh':
                    choosedir = Sse_lday
                else:
                    choosedir = Sze_lday

                stk = Stock(code)
                stk.readldaysim(choosedir, 20)
                #print(stk.ldayvalue)
                upcount = 0
                for n in range(15):
                    if stk.limitup(n): upcount += 1
                #print(upcount)
                if upcount >= 3:

                    gd = stk.gaodian(0, 14)
                    #print(stk.ldayvalue[0]["Close"] / gd)
                    if stk.ldayvalue[0]["Close"] / gd < 0.85:

                        print(code)
                        logfile.write(code + '\n')

            except Exception as e:
                pass  #print(e)
Пример #3
0
def main2():
    stocklist = [
        '300561', '000728', '600333', '002221', '603618', '002449', '000910',
        '600422', '002668', '002562', '002692', '600844', '300349', '000625',
        '300423', '002729', '002063', '300241', '300163', '603067'
    ]
    #删除出错文件
    for code in (stocklist):
        prefix = get_stock_market(code)
        file = stock_day_line_file + prefix + code + '.csv'
        if os.path.exists(file):
            os.remove(file)
            print('del ' + file)
    getstockdayline(stocklist)
    print('[+]股票日线数据更新完毕')
Пример #4
0
def runchzhshch(logfile):
    #strtoday = datetime.datetime.now().strftime('%Y%m%d')
    #today = pd.Timestamp(strtoday)
    print('chzhshch_day_B1 output' + ':\n')
    logfile.write('chzhshch_day_B1 output' + ':\n')
    for code in depickle_stock_list():
        if get_stock_market(code) in ['sh', 'sz']:
            try:
                a = chzhshch(code)
                out = a.test()
                if out:
                    print(code)
                    logfile.write(code + '\n')

            except Exception as e:
                pass
Пример #5
0
def runjasonshort(logfile, trading):
    #strtoday = datetime.datetime.now().strftime('%Y%m%d')
    #today = pd.Timestamp(strtoday)

    print('chzhshch_30m_jasonshort output' + ':\n')
    logfile.write('chzhshch_30m_jasonshort output' + ':\n')
    for code in depickle_stock_list():
        if get_stock_market(code) in ['sh', 'sz']:
            try:
                a = jasonshort(code, trading)
                out = a.test()
                if out:
                    print(code)
                    logfile.write(code + '\n')

            except Exception as e:
                print(e)
Пример #6
0
def getstockfzline(stocklist):
    '''
    读取通达信5分钟数据
    '''
    for root, dirs, files in os.walk(stock_fz_line_file):
        for file in files:
            os.remove(root + file)
    time.sleep(3)
    for code in (stocklist):
        prefix = get_stock_market(code)
        if prefix in ['sh', 'sz']:
            try:
                file_to_w = stock_fz_line_file + prefix + code + '.csv'
                file_to_o = tdx_fz_line_file + '/' + prefix + '/fzline' + '/' + prefix + code + '.lc5'
                file_o = open(file_to_o, "rb")
                file_w = open(file_to_w, "w")
                count = 0
                while (file_o.seek(-(count + 1) * Daylength, 2)):
                    tmpfz = struct.unpack('hhfffffii', file_o.read(32))
                    tmpdata = []
                    tmpdata.append('{}-{}-{} {:0>2}:{:0>2}:00'.format(
                        tmpfz[0] // 2048 + 2004, tmpfz[0] % 2048 // 100,
                        tmpfz[0] % 2048 % 100, tmpfz[1] // 60, tmpfz[1] % 60))
                    tmpdata.append('{:.2f}'.format(tmpfz[2]))  #open
                    tmpdata.append('{:.2f}'.format(tmpfz[3]))  #high
                    tmpdata.append('{:.2f}'.format(tmpfz[4]))  #low
                    tmpdata.append('{:.2f}'.format(tmpfz[5]))  #close
                    tmpdata.append('{:.2f}'.format(tmpfz[6]))  #amount
                    tmpdata.append('{:.2f}'.format(tmpfz[7]))  #vol

                    for d in tmpdata:
                        file_w.write(d)
                        file_w.write(',')
                    file_w.write('\n')
                    #print(tmpdata)

                    count += 1
                    #if count > 187:break
                file_o.close()
                file_w.close()
            except:
                pass
Пример #7
0
def runjasonshort(logfile):
    #file = open('runjasonshort.log','w')
    strtoday = datetime.datetime.now().strftime('%Y%m%d')
    today = pd.Timestamp(strtoday)
    print('Jasonshort output' + ':\n')
    logfile.write('Jasonshort output' + ':\n')
    for code in depickle_stock_list():
        if get_stock_market(code) in ['sh', 'sz']:
            try:
                a = jasonshort(code)
                a.test()
                b = a.stockdayline[a.stockdayline['yz'] == True]['yz']
                b = b.reset_index()
                b['span'] = (today - b['date']) < datetime.timedelta(days=2)
                c = b[b['span'] == True]['date']
                if (len(c) > 0):
                    print(code + ',' + str(c[0])[:11] + '\n')
                    logfile.write(code + ',' + str(c[0])[:11] + '\n')
            except Exception as e:
                pass
Пример #8
0
def getstocktdxdayline(stocklist):
    '''
    读取通达信日线数据
    '''
    for root, dirs, files in os.walk(stock_tdx_day_line_file):
        for file in files:
            os.remove(root + file)
    time.sleep(3)
    for code in (stocklist):
        prefix = get_stock_market(code)
        if prefix in ['sh', 'sz']:
            try:
                file_to_w = stock_tdx_day_line_file + prefix + code + '.csv'
                file_to_o = tdx_fz_line_file + '/' + prefix + '/lday' + '/' + prefix + code + '.day'
                file_o = open(file_to_o, "rb")
                file_w = open(file_to_w, "w")
                count = 0
                while (file_o.seek(-(count + 1) * Daylength, 2)):
                    tmpfz = struct.unpack('iiiiifii', file_o.read(32))
                    tmpdata = []
                    tmpdata.append('{}'.format(tmpfz[0]))
                    tmpdata.append('{:.2f}'.format(tmpfz[1] / 100))  #open
                    tmpdata.append('{:.2f}'.format(tmpfz[2] / 100))  #high
                    tmpdata.append('{:.2f}'.format(tmpfz[3] / 100))  #low
                    tmpdata.append('{:.2f}'.format(tmpfz[4] / 100))  #close
                    tmpdata.append('{:.2f}'.format(tmpfz[5]))  #amount
                    tmpdata.append('{:.2f}'.format(tmpfz[6]))  #vol

                    for d in tmpdata:
                        file_w.write(d)
                        file_w.write(',')
                    file_w.write('\n')
                    #print(tmpdata)

                    count += 1
                    #if count > 187:break
                file_o.close()
                file_w.close()
            except Exception as e:
                print(e)  #pass
Пример #9
0
               self.stockdayline['5dma'].shift(2)))


'''
#test
a=Short100('600080')
a.days3db7()
b=a.stockdayline[a.stockdayline['days3db7']==True]['openrev']
print(b.describe())
print(b.sum())
print(a.stockdayline[a.stockdayline['days3db7']==True])
'''
log_file = open('days3db7.log', 'w')
geshu = 0
for code in (depickle_stock_list()):
    prefix = get_stock_market(code)
    if prefix in ['sh', 'sz']:
        try:
            a = Short100(code)
            a.days3db7()
            del a.stockdayline['low']
            del a.stockdayline['high']
            del a.stockdayline['vol']
            del a.stockdayline['amount']
            b = a.stockdayline[a.stockdayline['days3db7'] == True]['openrev']
            log_file.write(code + '\t')
            log_file.write(
                str(a.stockdayline[a.stockdayline['days3db7'] == True]
                    ['openrev'].sum()))
            log_file.write('\t')
            log_file.write(str(len(b[b > 0])))