Exemplo n.º 1
0
    def __init__(self):
        mongoUrl = "localhost"
        self.freshList = set()
        self.forcusList = set()
        self.nearNewHigh = set()
        self.stockList = set()
        self.fpDict = {}
        self.mongodb = pymongo.MongoClient(mongoUrl)
        self.today = datetime.date.today().strftime("%Y%m%d")
        # self.today = "20170519"
        self.yestoday = common.get_last_date(self.today)
        self.yestoday = common.format_date(self.yestoday, "%Y%m%d")
        # print self.yestoday
        self.updateNewHighlist()
        while (True):
            ttime = time.localtime()
            thour = ttime.tm_hour
            tmin = ttime.tm_min
            if (thour > 9) or (thour == 9 and tmin >= 30):
                break
            time.sleep(10)

        self.updatefreshlist()  # 次新股
        self.updateForcusList()  # 关注股
        self.updateFpList()  # 复牌股
Exemplo n.º 2
0
    def update_ZDT_yesterday(self,dateEq='19890928',dateStart = '19890928', dateEnd = '19890928'):
        # step 2
        ## 从指定日期开始,计算meat,hole, 以及pre的情况
        mongoUrl = "localhost"
        mongodb = pymongo.MongoClient(mongoUrl)
        dateDicts = common.get_mongoDicts(dateEq=dateEq,dateStart=dateStart,dateEnd=dateEnd)

        for dateDict in dateDicts:
            cdate=dateDict['date']
            cdate=datetime.datetime.strptime(cdate,"%Y%m%d").strftime("%Y-%m-%d")
            predate=common.get_last_date(cdate)
            self.get_meat(cdate,predate,mongodb)
Exemplo n.º 3
0
    def get_backsee(self,sframe):
        try:
            # step 1: write "ZT_stocks,ZT_num,DT_stocks,DT_num" base info to mongo
            [dicts,ZT_list,DT_list,HD_list,LD_list]=self.baseInfo(sframe)

            # step 2: ZT/DT stocks, that got big amount
            # ZT_overMonut=self.overMount(ZT_list)
            # dicts['ZT_Mount']=ZT_overMonut
            # DT_overMonut=self.overMount(DT_list)
            # dicts['DT_Mount']=DT_overMonut

            # step 3: generate Add_newStocks, actulZtStocks, freshStocks, openedFreshedStocks
            print dicts['date']
            yesterday = common.get_last_date(dicts['date'])
            yesterday = common.format_date(yesterday,"%Y%m%d")
            yesResults = self.mongodb.stock.ZDT_by_date.find_one({"date":yesterday})
            freshStocks = []
            if yesResults.has_key("freshStocks"):
                freshStocks = yesResults['freshStocks'].split("_")

            yesterdayNewAddStocks = []
            if yesResults.has_key("Add_newStocks"):
                yesterdayNewAddStocks = yesResults['Add_newStocks'].keys()


            ## 新股加入到mongo中,每天刷新一次
            Collect_NewStocks.fresh_newStockWebsite()
            todResults = self.mongodb.stock.ZDT_by_date.find_one({"date":dicts['date']})
            newAddStocks = []
            if todResults is not None and todResults.has_key("Add_newStocks"):
                newAddStocks = todResults['Add_newStocks'].keys()
                freshStocks.extend(newAddStocks)

            ## 自然涨停股票
            dicts['actulZtStocks'] = "_".join([x for x in dicts['ZT_stocks'].split("_") if x not in freshStocks])

            ## 连续涨停的次新股
            freshStocks = [x for x in freshStocks if x in dicts['ZT_stocks']]
            # ZT_stocks可能不包含今日的股票(因为从tushare拿股票代码,不一定包括今天和昨天的新股, 可能还不包括前天的股票list)
            freshStocks.extend(newAddStocks)
            freshStocks.extend(yesterdayNewAddStocks)
            dicts['freshStocks'] = "_".join(list(set(freshStocks)))

            ## 开板次新股
            dicts['openedFreshedStocks'] = "_".join([x for x in freshStocks if x not in dicts['ZT_stocks'] and x not in newAddStocks])
            self.mongodb.stock.ZDT_by_date.update({"date":dicts['date']},{"$set":dicts},True)
            logging.getLogger().info("【getTenpercent summary】daily ZDT/actualZt. summary finished!")
        except:
            err = traceback.format_exc()
            logging.getLogger().info("【getTenpercent summary】daily ZDT/actualZt. summary finished!")
Exemplo n.º 4
0
    def update_ZDT_contsNum(self, dateEq='19890928',dateStart = '19890928', dateEnd = '19890928'):
        # step 2
        # 给定日期区间内,计算连续涨跌停个数,并去重zt_stocks, dt_stocks, 重新计算个数
        # 需要依赖数据库中已经有的涨跌停股票代码以及连续涨跌停数(如果没有连续值,则从0开始)
        mongoUrl = "localhost"
        mongodb = pymongo.MongoClient(mongoUrl)
        dateDicts = common.get_mongoDicts(dateEq=dateEq,dateStart=dateStart,dateEnd=dateEnd)

        for dateDict in dateDicts:
            cdate=dateDict['date']
            print "handle continus ZDT number for %s"%cdate
            cdate=datetime.datetime.strptime(cdate,"%Y%m%d").strftime("%Y-%m-%d")
            predate=common.get_last_date(cdate)
            common.update_numZD(cdate,predate,mongodb)
Exemplo n.º 5
0
    def update_freshStocks(self,dateEq='19890928',dateStart = '19890928', dateEnd = '19890928'):
        # step 2
        # 给定日期区间内,计算连续涨跌停个数,并去重zt_stocks, dt_stocks, 重新计算个数
        # 需要依赖数据库中已经有的涨跌停股票代码以及连续涨跌停数(如果没有连续值,则从0开始)
        mongoUrl = "localhost"
        mongodb = pymongo.MongoClient(mongoUrl)
        try:
            dateDicts = common.get_mongoDicts(dateEq=dateEq,dateStart=dateStart,dateEnd=dateEnd)

            for dateDict in dateDicts:
                cdate=dateDict['date']
                predate=common.get_last_date(cdate)
                self.oneDate_freshStocks(cdate,predate,mongodb)
        except Exception,e:
            print "Exception error: %s"%e
Exemplo n.º 6
0
    def __init__(self):
        mongoUrl = "localhost"
        self.freshList = set()
        self.forcusList = set()
        self.nearNewHigh = set()
        self.stockList = set()
        self.mongodb = pymongo.MongoClient(mongoUrl)
        self.today = datetime.date.today().strftime("%Y%m%d")
        # self.today = "20160520"
        self.yestoday = common.get_last_date(self.today)
        self.yestoday = common.format_date(self.yestoday,"%Y%m%d")
        self.updateNewHighlist()
        while(True):
            ttime=time.localtime()
            thour=ttime.tm_hour
            tmin=ttime.tm_min
            if (thour > 9) or (thour == 9 and tmin >= 30):
                break
            time.sleep(10)

        self.updatefreshlist()      # 次新股
        self.updateForcusList()     # 关注股
Exemplo n.º 7
0
    def get_backsee(self,sframe):
        # step 1: write "ZT_stocks,ZT_num,DT_stocks,DT_num" base info to mongo
        [dicts,ZT_list,DT_list,HD_list,LD_list]=self.baseInfo(sframe)

        # step 2: ZT/DT stocks, that got big amount
        ZT_overMonut=self.overMount(ZT_list)
        dicts['ZT_Mount']=ZT_overMonut
        DT_overMonut=self.overMount(DT_list)
        dicts['DT_Mount']=DT_overMonut

        # step 3: generate Add_newStocks, actulZtStocks, freshStocks, openedFreshedStocks
        print dicts['date']
        yesterday = common.get_last_date(dicts['date'])
        yesterday = common.format_date(yesterday,"%Y%m%d")
        yesResults = self.mongodb.stock.ZDT_by_date.find_one({"date":yesterday})
        freshStocks = []
        if yesResults.has_key("freshStocks"):
            freshStocks = yesResults['freshStocks'].split("_")

        ## 新股加入到mongo中,每天刷新一次
        Collect_NewStocks.fresh_newStockWebsite()
        todResults = self.mongodb.stock.ZDT_by_date.find_one({"date":dicts['date']})
        newAddStocks = []
        if todResults.has_key("Add_newStocks"):
            newAddStocks = todResults['Add_newStocks'].keys()
            freshStocks.extend(newAddStocks)

        ## 自然涨停股票
        dicts['actulZtStocks'] = "_".join([x for x in dicts['ZT_stocks'].split("_") if x not in freshStocks])

        ## 连续涨停的次新股
        freshStocks = [x for x in freshStocks if x in dicts['ZT_stocks']]
        freshStocks.extend(newAddStocks)
        dicts['freshStocks'] = "_".join(list(set(freshStocks)))

        ## 开板次新股
        dicts['openedFreshedStocks'] = "_".join([x for x in freshStocks if x not in dicts['ZT_stocks'] and x not in newAddStocks])
        self.mongodb.stock.ZDT_by_date.update({"date":dicts['date']},{"$set":dicts},True)
Exemplo n.º 8
0
 def calCons(self):
     predate = common.get_last_date(self.today)
     common.update_numZD(self.today,predate,self.mongodb)
     print "calculate continus number finished!"
Exemplo n.º 9
0
#coding:utf8
import pymongo
import common
import datetime
import multiprocessing
import numpy as np
import pandas as pd
from Tkinter import *
from tkMessageBox import *
import time

# multiprocessing.freeze_support()
mongoUrl = "localhost"
today = datetime.date.today().strftime("%Y%m%d")
yesToday = common.get_last_date(today)
strYestoday = common.format_date(yesToday, "%Y%m%d")
mongodb = pymongo.MongoClient(mongoUrl)
freshCols = mongodb.stock.ZDT_by_date.find_one({"date": strYestoday})
freshList = freshCols['freshStocks'].split("_")
datelist = []
datelist.append(strYestoday)
lastFrame = common.get_mysqlData(freshList, datelist)
lastFrame['ZT_PRICE'] = lastFrame['CLOSE_PRICE'].astype(np.float64) * 1.1
lastFrame['ZT_PRICE'] = lastFrame['ZT_PRICE'].round(decimals=2)
lastFrame.set_index('TICKER_SYMBOL', inplace=True)
lastFrame = lastFrame['ZT_PRICE']
excludeList = []

while (True):

    time.sleep(5)
Exemplo n.º 10
0
 def scan_yestoday(self):
     last_day = common.get_last_date(self.day)
     common.generate_html(last_day, self.day)
Exemplo n.º 11
0
    def parse_content(self, content):
        content = content.replace(u'var kcSTlIop=', u'').replace(u'pages', u'"pages"').replace(u'data', u'"data"')
        con_dict = eval(content)

        # 当前时间点
        ttime = time.localtime()
        thour = ttime.tm_hour
        tmin = ttime.tm_min
        day_list = []
        if thour >= 18:  # 晚上6点以后,可以得到当天收盘价了,关注复牌时间点为[明天,今天,昨天]
            for n in range(2-self.dayRange, 2):
                day_list.append(common.get_lastN_date(self.date, n))
        else:               # 否则,关注时间点为[今天,昨天,前天]
            for n in range(1-self.dayRange, 1):
                day_list.append(common.get_lastN_date(self.date, n))

        for infos in con_dict['data']:
            elements = infos.split(",")
            if len(elements) < 2:
                continue
            secid = elements[0]
            secname = elements[1]
            tp_time = elements[-2]
            fp_time = elements[-1]
            reason = elements[5]
            db_num = self.mongodb.stock.FP.find({"stcid":"%s" % secid, "tp_time":"%s" % tp_time, "fp_time":"%s" % fp_time, "target_ratio":{"$exists":True}}).count()
            if db_num > 0:
                continue
            else:
                self.mongodb.stock.FP.update({"stcid":"%s" % secid, "tp_time":"%s" % tp_time},
                                             {"$set":{"stcid":"%s" % secid, "tp_time":"%s" % tp_time, "fp_time":"%s" % fp_time, "reason":"%s" %reason}},
                                             True, True)


            # 仅仅记录目标日期在关注日期内的信息
            if fp_time in day_list:
                # 期间大盘涨幅
                if secid[:2] == '60':
                    dp_stockid = 'ZS000001'
                else:
                    dp_stockid = 'ZS399006'

                dp_frame = common.get_mysqlData([dp_stockid], [tp_time, common.get_last_date(fp_time)])
                if len(dp_frame) < 2:
                    continue

                dp_ratio = (dp_frame.loc[1, 'CLOSE_PRICE'] - dp_frame.loc[0, 'CLOSE_PRICE']) / dp_frame.loc[0, 'CLOSE_PRICE']
                dp_ratio = round(dp_ratio, 2)

                # 停牌时价格
                stock_price = common.get_mysqlData([secid], [tp_time]).loc[0, 'CLOSE_PRICE']
                if dp_ratio > 0:
                    diff = 0.05
                else:
                    diff = -0.05

                # 目标涨幅
                target_ratio = dp_ratio + diff

                # 目标价格
                target_price = round(stock_price*(1+target_ratio), 2)

                # 停牌时间
                delta_days = common.get_mongoDicts(dateStart=tp_time,dateEnd=fp_time).count()

                self.mongodb.stock.FP.update({"stcid":"%s" % secid, "tp_time":"%s" % tp_time},
                                             {"$set":{"dp_ratio":dp_ratio, "target_ratio":target_ratio, "target_price": target_price, 'delta_days':delta_days}},
                                             True, True)
Exemplo n.º 12
0
def plot_back_open_num(ax, markersize=8):
    global results, html1
    count = 0

    # 回封数,同html格式一致,[["2016-01-01", 回封连板数,符合条件的股票数(相同回封数), 股票代码字符串], ["2016-09-28", 回封连板数,符合条件的股票数, 股票代码字符串], ...]
    backTen_list = []

    # 开板数,格式如上, [['2016-01-01', 之前连板数,符合条件的股票数(相同连板), 股票代码字符串], ['2016-09-29', '之前连板数', 符合条件的股票数, 股票代码字符串], ...]
    open_list = []

    # 昨日back涨停股票,今日涨幅,格式如上, [['2016-01-01', 股票涨幅, 符合条件的股票数(相同涨幅), 股票代码字符串]
    yes_back_ratio_list = []

    # 第一次回封失败股票,格式如上,[['2016-01-01', 股票亏损额度(10 - 涨幅), 符合条件的股票数(相同涨幅), 股票代码字符串]
    # 第一次回封失败的股票,第二日的涨幅, [['2016-01-01', 股票涨幅, 符合条件的股票数(相同涨幅), 股票代码字符串]
    first_back_fail_list = []
    first_back_next_ratio_list = []

    # 第二次回封失败股票,格式如上,[['2016-01-01', 股票亏损额度(10 - 涨幅), 符合条件的股票数(相同涨幅), 股票代码字符串]
    # 第二次回封失败的股票,第二日的涨幅, [['2016-01-01', 股票涨幅, 符合条件的股票数(相同涨幅), 股票代码字符串]
    second_back_fail_list = []
    second_back_next_ratio_list = []


    last_result = {}
    # 记录昨日最高冲击涨停股,今日的涨幅
    last_direct_high_list = []
    last_second_back_high_list = []
    for result in results:
        # 记录backCount和openCount是哪些
        trace_backCount = {}  # trace_backCount = {3:"000002_000012_000026"}
        trace_openCount = {}
        trace_yesbackRatio = {} # trace_yesbackRatio = {2.75:"000002"}

        # 回封失败的损失
        trace_first_back_fail_loss = {} # trace_first_back_fail_loss = {2.75:"000002"}
        trace_second_back_fail_loss = {}
        trace_next_first_fail_ratio = {}
        trace_next_second_fail_ratio = {}

        # 记录每日回封的个数, backCount = {3:2}, 在第几个板回封的个数
        backCount = {}
        # 记录每日开板的情况, openCount = {15:2, 10:1}, 表示前面N连板且在今天开板的股票数
        openCount = {}
        # 记录昨日回封股票,今日的涨幅, yesbackRatio = {3.27:2, 10:1}
        yesbackRatio = {}
        # 回封失败的个数
        firstbackCount = {}
        secondbackCount = {}
        next_firstbackCount = {}
        next_secondbackCount = {}


        day = result['date']
        day = common.format_date(day, "%Y-%m-%d")
        print day

        if len(last_result) == 0:
            yesDay = common.get_last_date(day)
            last_result = mongodb.stock.ZDT_by_date.find({"date":common.format_date(yesDay, "%Y%m%d")})[0]

        backTen_acc = result['backTen_acc']
        dummyDirectTen = result['dummyDirectTen']
        directOpen = result['directOpen']
        backOpen = result['backOpen']
        highDirectOpenList = result['highDirectOpen']
        highBackOpenList = result['highBackOpen']

        last_dummyDirectTen_list = last_result['dummyDirectTen'].keys()  # 昨日回封的股票
        last_backTen_acc = last_result['backTen_acc']  # 昨日回封的涨幅

        # 记录昨日回封的股票,今日收益
        if len(last_dummyDirectTen_list) > 0:        #昨日有回封的
            for stockid in last_dummyDirectTen_list:
                acc_last_back_ratio = last_backTen_acc[stockid]
                ratio = backTen_acc[stockid] - acc_last_back_ratio # 得到今日涨幅
                ratio = round(ratio, 2)
                if ratio in yesbackRatio:
                    yesbackRatio[ratio] += 1
                    trace_yesbackRatio[ratio] += "_%s"%stockid
                else:
                    yesbackRatio[ratio] = 1
                    trace_yesbackRatio[ratio] = stockid
        else:
            yesbackRatio = {0:0}
            trace_yesbackRatio = {0:""}

        # 记录每日的回封股票数
        if len(dummyDirectTen) > 0: # 存在回封的股票
            for stockid in dummyDirectTen.keys():
                num_back = int(backTen_acc[stockid] / 9)    # 回封的时候是几个板
                if num_back in backCount.keys():
                    backCount[num_back] += 1
                    trace_backCount[num_back] += "_%s"%stockid
                else:
                    backCount[num_back] = 1
                    trace_backCount[num_back] = stockid
        else:
            backCount = {0: 0}
            trace_backCount = {0:""}

        # 记录每日的开板数
        if len(directOpen) > 0:   # 直接开板
            for stockid in directOpen:
                continue_num = last_result['directTen'][stockid]        # 昨日会记录该股票的连板数
                continue_num = round(float(continue_num)/5, 2)
                continue_num *= -1
                if continue_num in openCount.keys():
                    openCount[continue_num] += 1
                    trace_openCount[continue_num] += "_%s"%stockid
                else:
                    openCount[continue_num] = 1
                    trace_openCount[continue_num] = stockid

        if len(backOpen) > 0:   # 回封开板
            for stockid in backOpen:
                print stockid
                continue_num = last_result['dummyDirectTen'][stockid]        # 昨日会记录该股票的连板数
                continue_num = round(float(continue_num)/5, 2)
                continue_num *= -1
                if continue_num in openCount.keys():
                    openCount[continue_num] += 1
                    trace_openCount[continue_num] += "_%s"%stockid
                else:
                    openCount[continue_num] = 1
                    trace_openCount[continue_num] = stockid
        if len(openCount) == 0:
            openCount = {0: 0}
            trace_openCount = {0:""}


        # 记录1回封失败,第二天的涨跌幅
        for stockid in last_direct_high_list:
            ratio = common.get_day_k_status(stockid, day)   # 今日涨幅
            if ratio in next_firstbackCount.keys():
                next_firstbackCount[ratio] += 1
                trace_next_first_fail_ratio[ratio] += "_%s"%stockid
            else:
                next_firstbackCount[ratio] = 1
                trace_next_first_fail_ratio[ratio] = stockid
        if len(next_firstbackCount) == 0:
            next_firstbackCount = {0: 0}
            trace_next_first_fail_ratio = {0:""}

        # 记录2回封失败,第二天的涨跌幅
        for stockid in last_second_back_high_list:
            ratio = common.get_day_k_status(stockid, day)   # 今日涨幅
            if ratio in next_secondbackCount.keys():
                next_secondbackCount[ratio] += 1
                trace_next_second_fail_ratio[ratio] += "_%s"%stockid
            else:
                next_secondbackCount[ratio] = 1
                trace_next_second_fail_ratio[ratio] = stockid
        if len(next_secondbackCount) == 0:
            next_secondbackCount = {0: 0}
            trace_next_second_fail_ratio = {0:""}

        # 记录每日的直接开板后回封失败情况
        for stockid in highDirectOpenList.keys():
            hit_status = common.get_hit_status(stockid, day)   # 是否开板之后有回封
            if hit_status:  # 有回封
                last_direct_high_list.append(stockid)
                ratio = highDirectOpenList[stockid]
                loss = round(10 - ratio, 2)
                if loss in firstbackCount.keys():
                    firstbackCount[loss] += 1
                    trace_first_back_fail_loss[loss] += "_%s"%stockid
                else:
                    firstbackCount[loss] = 1
                    trace_first_back_fail_loss[loss] = stockid
        if len(firstbackCount) == 0:
            firstbackCount = {0:0}
            trace_first_back_fail_loss = {0:""}
            last_direct_high_list = []

        # 记录每日的二封回封失败情况
        for stockid in highBackOpenList.keys():
            num_back = int(backTen_acc[stockid] / 9)    # 回封的时候是几个板
            if num_back != 1:       # 只记录第二封的情况
                continue
            hit_status = common.get_hit_status(stockid, day)   # 是否开板之后有回封
            if hit_status:  # 有回封
                last_second_back_high_list.append(stockid)
                ratio = highBackOpenList[stockid]
                loss = round(10 - ratio, 2)
                if loss in secondbackCount.keys():
                    secondbackCount[loss] += 1
                    trace_second_back_fail_loss[loss] += "_%s"%stockid
                else:
                    secondbackCount[loss] = 1
                    trace_second_back_fail_loss[loss] = stockid
        if len(secondbackCount) == 0:
            secondbackCount = {0:0}
            trace_second_back_fail_loss = {0:""}
            last_second_back_high_list = []


        for num in backCount:
            ax.plot(count, num, color='r', marker=markers[backCount[num]], markersize=markersize)
            backTen_list.append([day, num, backCount[num], trace_backCount[num]])     # 回封

        for num in openCount:
            open_list.append([day, num, openCount[num], trace_openCount[num]])     # 开板
            ax.plot(count, num, color='g', marker=markers[openCount[num]], markersize=markersize)

        for ratio in yesbackRatio:
            yes_back_ratio_list.append([day, ratio, yesbackRatio[ratio], trace_yesbackRatio[ratio]])

        for ratio in firstbackCount:
            first_back_fail_list.append([day, ratio, firstbackCount[ratio], trace_first_back_fail_loss[ratio]])

        for ratio in next_firstbackCount:
            first_back_next_ratio_list.append([day, ratio, next_firstbackCount[ratio], trace_next_first_fail_ratio[ratio]])

        for ratio in secondbackCount:
            second_back_fail_list.append([day, ratio, secondbackCount[ratio], trace_second_back_fail_loss[ratio]])

        for ratio in next_secondbackCount:
            second_back_next_ratio_list.append([day, ratio, next_secondbackCount[ratio], trace_next_second_fail_ratio[ratio]])

        count += 1
        last_result = result

    # 写入html
    str_back = str(backTen_list).replace('"', '').replace("'", '"')
    str_open = str(open_list).replace('"', '').replace("'", '"')
    str_yesback_ratio = str(yes_back_ratio_list).replace('"', '').replace("'", '"')
    str_4 = "[]"
    str_first_fail = str(first_back_fail_list).replace('"', '').replace("'", '"')
    str_second_fail = str(second_back_fail_list).replace('"', '').replace("'", '"')
    size1 = size2 = size3 = "5"
    html_1 = html1.replace("DATA1", str_back).replace("DATA2", str_open).replace("DATA3", str_yesback_ratio).replace("DATA4", str_4).replace("SIZE1", size1).replace("SIZE2", size2).replace(' u"', ' "')
    html_1 = html_1.replace("DATA5", str_first_fail).replace("DATA6", str_second_fail).replace(' u"', ' "').replace("SIZE3", size3)
    with open(os.path.join(u"D:/Money/modeResee/复盘/次新", u"复盘.html"), 'wb') as fHanlder:
        fHanlder.write(html_1)
Exemplo n.º 13
0
#coding:utf8
import pymongo
import common
import datetime
import multiprocessing
import numpy as np
import pandas as pd
from Tkinter import *
from tkMessageBox import *
import time

# multiprocessing.freeze_support()
mongoUrl = "localhost"
today = datetime.date.today().strftime("%Y%m%d")
yesToday = common.get_last_date(today)
strYestoday = common.format_date(yesToday,"%Y%m%d")
mongodb = pymongo.MongoClient(mongoUrl)
freshCols = mongodb.stock.ZDT_by_date.find_one({"date":strYestoday})
freshList =freshCols['freshStocks'].split("_")
datelist = []
datelist.append(strYestoday)
lastFrame = common.get_mysqlData(freshList,datelist)
lastFrame['ZT_PRICE']=lastFrame['CLOSE_PRICE'].astype(np.float64)*1.1
lastFrame['ZT_PRICE']=lastFrame['ZT_PRICE'].round(decimals=2)
lastFrame.set_index('TICKER_SYMBOL',inplace=True)
lastFrame = lastFrame['ZT_PRICE']
excludeList = []

while(True):

    time.sleep(5)
Exemplo n.º 14
0
 def scan_yestoday(self):
     last_day = common.get_last_date(self.day)
     common.generate_html(last_day, self.day)
Exemplo n.º 15
0
    def parse_content(self, content):
        content = content.replace(u'var kcSTlIop=', u'').replace(
            u'pages', u'"pages"').replace(u'data', u'"data"')
        con_dict = eval(content)

        # 当前时间点
        ttime = time.localtime()
        thour = ttime.tm_hour
        tmin = ttime.tm_min
        day_list = []
        if thour >= 18:  # 晚上6点以后,可以得到当天收盘价了,关注复牌时间点为[明天,今天,昨天]
            for n in range(2 - self.dayRange, 2):
                day_list.append(common.get_lastN_date(self.date, n))
        else:  # 否则,关注时间点为[今天,昨天,前天]
            for n in range(1 - self.dayRange, 1):
                day_list.append(common.get_lastN_date(self.date, n))

        for infos in con_dict['data']:
            elements = infos.split(",")
            if len(elements) < 2:
                continue
            secid = elements[0]
            secname = elements[1]
            tp_time = elements[-2]
            fp_time = elements[-1]
            reason = elements[5]
            db_num = self.mongodb.stock.FP.find({
                "stcid": "%s" % secid,
                "tp_time": "%s" % tp_time,
                "fp_time": "%s" % fp_time,
                "target_ratio": {
                    "$exists": True
                }
            }).count()
            if db_num > 0:
                continue
            else:
                self.mongodb.stock.FP.update(
                    {
                        "stcid": "%s" % secid,
                        "tp_time": "%s" % tp_time
                    }, {
                        "$set": {
                            "stcid": "%s" % secid,
                            "tp_time": "%s" % tp_time,
                            "fp_time": "%s" % fp_time,
                            "reason": "%s" % reason
                        }
                    }, True, True)

            # 仅仅记录目标日期在关注日期内的信息
            if fp_time in day_list:
                # 期间大盘涨幅
                if secid[:2] == '60':
                    dp_stockid = 'ZS000001'
                else:
                    dp_stockid = 'ZS399006'

                dp_frame = common.get_mysqlData(
                    [dp_stockid],
                    [tp_time, common.get_last_date(fp_time)])
                if len(dp_frame) < 2:
                    continue

                dp_ratio = (dp_frame.loc[1, 'CLOSE_PRICE'] -
                            dp_frame.loc[0, 'CLOSE_PRICE']
                            ) / dp_frame.loc[0, 'CLOSE_PRICE']
                dp_ratio = round(dp_ratio, 2)

                # 停牌时价格
                stock_price = common.get_mysqlData(
                    [secid], [tp_time]).loc[0, 'CLOSE_PRICE']
                if dp_ratio > 0:
                    diff = 0.05
                else:
                    diff = -0.05

                # 目标涨幅
                target_ratio = dp_ratio + diff

                # 目标价格
                target_price = round(stock_price * (1 + target_ratio), 2)

                # 停牌时间
                delta_days = common.get_mongoDicts(dateStart=tp_time,
                                                   dateEnd=fp_time).count()

                self.mongodb.stock.FP.update(
                    {
                        "stcid": "%s" % secid,
                        "tp_time": "%s" % tp_time
                    }, {
                        "$set": {
                            "dp_ratio": dp_ratio,
                            "target_ratio": target_ratio,
                            "target_price": target_price,
                            'delta_days': delta_days
                        }
                    }, True, True)