def getParseResult(self,isDump=False):
    print '***************************************************************************'
    print 'In custom mode'
    print '***************************************************************************'
    # idFile = '振幅/振幅>=5%D<=20D向上/'+self._parseDay+'-AmplitudeParser.sel'

    idFile = '2017年所有5日线下阳线/'+self._parseDay+'-AmplitudeParser.sel'
    # idFile = '2018年所有5日线下振幅超过5%的阳线/'+self._parseDay+'-AmplitudeParser.sel'

    allIdList = Tools.getIdListOfFile(idFile)
    idList = []
    num = 0
    parsedNum = 0
    total = len(allIdList)
    for id in allIdList:
      try:
        self.printProcess(parsedNum,total)
        f = Tools.getPriceDirPath()+'/'+id
        res = open(f,'r').read()
        ret = self.parse(res,self._parseDay,id)
        if ret:
          idList.append(id)
          num += 1
          print str(num) + ' ↗'
        parsedNum += 1
      except Exception, e:
        pass
        print repr(e)
Exemple #2
0
 def getParseResult(self, isDump=False):
     print '***************************************************************************'
     print 'In custom mode'
     print '***************************************************************************'
     # idFile = '最高价低于5日线,振幅大于5%,D值小于20/'+self._parseDay+'-MaxPriceUnderMaParser.sel'
     idFile = '最高价低于5日线,振幅大于5%,阳线/' + self._parseDay + '-MaxPriceUnderMaParser.sel'
     allIdList = Tools.getIdListOfFile(idFile)
     idList = []
     num = 0
     parsedNum = 0
     total = len(allIdList)
     for id in allIdList:
         try:
             self.printProcess(parsedNum, total)
             f = Tools.getPriceDirPath() + '/' + id
             res = open(f, 'r').read()
             ret = self.parse(res, self._parseDay, id)
             if ret:
                 idList.append(id)
                 num += 1
                 print str(num) + ' ↗'
             parsedNum += 1
         except Exception, e:
             pass
             print repr(e)
Exemple #3
0
def traceCD(id, parseDay):
    print '相对信号日收盘价跌幅达到一定值,抄底'

    r1 = -0.01  # 跌幅
    r2 = 0.02  # 止盈幅度
    N = 20  # 持股天数

    print id, parseDay
    parser = RelativeParser.RelativeParser(parseDay, id)
    priceFile = Tools.getPriceDirPath() + '/' + str(id)
    res = open(priceFile, 'r').read()

    dayList = parser.getNextTradingDayList(parseDay, N)  #
    endPriceOfParseDay = parser.getEndPriceOfDay(res, parseDay)
    if 0 == endPriceOfParseDay:
        return False  # 坏数据

    targetInPrice = endPriceOfParseDay * (1 + r1)  # 跌到该价格则买入
    inPrice = 0
    inDay = ''
    outPrice = parser.getEndPriceOfDay(res, dayList[-1])  # 默认最后一天卖出
    outDay = dayList[-1]
    targetOutPrice = 0

    minPrice = 999999
    maxPrice = 0
    inDayList = dayList[:-1]  # 截止第9天可买入
    index = 0
    for day in inDayList:
        index += 1
        minP = parser.getMinPriceOfDay(res, day)
        if minP < targetInPrice:
            inPrice = targetInPrice  # 跌到目标价,买入
            inDay = day
            targetOutPrice = inPrice * (1 + r2)  # 目标止盈
            print '买入'
            break

    if 0 == targetOutPrice:
        return False

    outDayList = dayList[index:]
    for day in outDayList:
        maxPrice = parser.getMinPriceOfDay(res, day)
        if maxPrice > targetOutPrice:
            outPrice = targetOutPrice
            outDay = day
            break

    ret = {}
    ret['id'] = id
    ret['name'] = Tools.getNameById(id)
    ret['inPrice'] = inPrice
    ret['outDay'] = outDay
    ret['outPrice'] = outPrice
    ret['holdDays'] = N
    ret['minPrice'] = minPrice
    ret['maxPrice'] = maxPrice
    return ret
Exemple #4
0
def traceYYY(id, parseDay):
    print id, parseDay

    maxDays = 20  # 最长持股时间

    parser = MaxPriceUnderMaParser.MaxPriceUnderMaParser(parseDay, id)
    priceFile = Tools.getPriceDirPath() + '/' + str(id)
    res = open(priceFile, 'r').read()

    dayList = parser.getNextTradingDayList(parseDay, maxDays)  #
    inDay = dayList[0]
    inPrice = parser.getStartPriceOfDay(res, inDay)  # 买入价为信号日后一天的开盘价
    if 0 == inPrice:
        return False  # 坏数据

    # 确定止损价
    sp1 = parser.getMinPriceOfDay(res, parseDay)
    sp2 = parser.getMinPriceOfDay(res, inDay)
    stopPrice = min(sp1, sp2)

    outPrice = 0
    dayList = dayList[1:]
    holdDays = 1
    outDay = ''
    for day in dayList:
        holdDays += 1
        startPrice = parser.getStartPriceOfDay(res, day)

        # 开盘即获利则止盈
        if startPrice > inPrice:
            outPrice = startPrice
            outDay = day
            break

        # 止损
        # sp = parser.getMinPriceOfDay(res,day)
        # if sp < stopPrice:
        #   outPrice = stopPrice
        #   outDay = day
        #   break

    if outPrice == 0:
        outPrice = parser.getEndPriceOfDay(res, dayList[-1])  # 默认按到期后的收盘价为卖出价
        outDay = dayList[-1]
        if outPrice == 0:
            return False

    ret = {}
    ret['id'] = id
    ret['name'] = Tools.getNameById(id)
    ret['inPrice'] = inPrice
    ret['outDay'] = outDay
    ret['outPrice'] = outPrice
    ret['holdDays'] = holdDays
    ret['minPrice'] = 0
    ret['maxPrice'] = 0
    return ret
Exemple #5
0
def trace(id, day):
    parser = BaseParser.BaseParser(day)
    priceFile = Tools.getPriceDirPath() + '/' + str(id)
    res = open(priceFile, 'r').read()

    ret = {}
    ret['id'] = id
    ret['name'] = Tools.getNameById(id)
    ret['day'] = day
    ret['inPrice'] = parser.getEndPriceOfDay(res, day)  # 买入价为当日收盘价
    ret['islp'] = parser.getMinPriceOfDay(res, day)  # 初始止损价为买入当日最低价
    ret['risk'] = round(ret['islp'] - ret['inPrice'], 5)
    ret['riskRate'] = round(ret['risk'] / ret['inPrice'], 5)
    #if ret['riskRate'] < -0.03:
    #if ret['riskRate'] < -0.1:
    if ret['riskRate'] < -0.04:  # 初始止损不超过n%(平均持股时间才4天) <-----------------
        return False

    dayList = parser.getNextTradingDayList(day, 30)
    inDayMaxPrice = parser.getMaxPriceOfDay(res, day)
    inDayMinPrice = parser.getMinPriceOfDay(res, day)
    holdDays = 0
    inTracking = False
    #slp = round(ret['islp'],1)-0.1 # 去尾
    slp = ret['islp']
    for d in dayList:  # 从第2天开始
        holdDays += 1
        endPrice = parser.getEndPriceOfDay(res, d)
        minPrice = parser.getMinPriceOfDay(res, d)

        if minPrice < slp:  # 触发止损  要有大盘配合
            ret['outPrice'] = slp
            break

        if not inTracking:  # 处于启动期
            if minPrice > inDayMaxPrice:  # 进入跟踪止损的信号<-----------------
                #if minPrice > ret['inPrice']:
                #if minPrice > inDayMinPrice:
                inTracking = True
                #slp = round(minPrice,1)-0.1 # 上调止损价
                #slp = ret['inPrice']
                slp = minPrice
        else:  # 处于跟踪期
            dayList = parser.getPastTradingDayList(
                d, 1)  # n日止损 <-----------------
            newIntervalMinPrice = getMinPriceOfDays(id, dayList)
            if newIntervalMinPrice > slp:
                #slp = round(newIntervalMinPrice,1)-0.1
                slp = newIntervalMinPrice

    ret['holdDays'] = holdDays
    ret['profit'] = round(ret['outPrice'] - ret['inPrice'], 5)
    ret['profitRate'] = str(
        round(ret['profit'] / ret['inPrice'], 5) * 100.0) + '%'
    ret['growthRate'] = round(ret['profit'] / ret['inPrice'], 5)

    return ret
Exemple #6
0
def trace(id, parseDay):
    print id, parseDay
    parser = MaxPriceUnderMaParser.MaxPriceUnderMaParser(parseDay, id)
    priceFile = Tools.getPriceDirPath() + '/' + str(id)
    res = open(priceFile, 'r').read()

    dayList = parser.getNextTradingDayList(parseDay, 20)  #
    inDay = dayList[0]
    inPrice = parser.getStartPriceOfDay(res, inDay)  # 开盘价买入
    # inPrice = parser.getMinPriceOfDay(res,inDay)  # 最低价买入(理想情况)
    stopPrice = parser.getMinPriceOfDay(res, parseDay)  # 信号日(阳线)最低价为底线
    if 0 == inPrice or 0 == stopPrice:
        return False  # 坏数据

    outDay = ''
    outPrice = 0
    holdDays = 0
    minPrice = 9999
    maxPrice = 0

    for day in dayList:
        holdDays += 1
        minP = parser.getMinPriceOfDay(res, day)
        maxP = parser.getMaxPriceOfDay(res, day)
        endP = parser.getEndPriceOfDay(res, day)
        # if endP == 0 or maxP ==0 or minP==0:
        # outPrice = 0
        # break
        if maxP > maxPrice:
            maxPrice = maxP
        if minP < minPrice:
            minPrice = minP
        if maxP < stopPrice:  # 最高价低于底线(进入下一个箱体)
            outPrice = endP  # 尾盘走
            outDay = day
            break

    if outPrice == 0:
        outPrice = parser.getEndPriceOfDay(res, dayList[-1])  # 默认按到期后的收盘价为卖出价
        outDay = dayList[-1]
        if outPrice == 0:
            return False

    ret = {}
    ret['id'] = id
    ret['name'] = Tools.getNameById(id)
    ret['inPrice'] = inPrice
    ret['outDay'] = outDay
    ret['outPrice'] = outPrice
    ret['holdDays'] = holdDays
    ret['minPrice'] = minPrice
    ret['maxPrice'] = maxPrice
    return ret
def traceXX(id, parseDay):
    print '持有N日'
    N = 20  # 持股天数
    print id, parseDay
    parser = RelativeParser.RelativeParser(parseDay, id)
    priceFile = Tools.getPriceDirPath() + '/' + str(id)
    res = open(priceFile, 'r').read()

    dayList = parser.getNextTradingDayList(parseDay, N)  #
    inDay = dayList[0]
    inPrice = parser.getStartPriceOfDay(res, inDay)  # 开盘价买入
    # inPrice = parser.getMinPriceOfDay(res,inDay)  # 最低价买入
    startPrice = parser.getStartPriceOfDay(res, inDay)
    endPrice = parser.getEndPriceOfDay(res, inDay)

    if 0 == inPrice:
        return False  # 坏数据

    # 剔除买入日阴线
    if endPrice < startPrice:
        return False

    outDay = dayList[-1]
    outPrice = parser.getEndPriceOfDay(res, outDay)  # 收盘价卖出
    # outPrice = parser.getMaxPriceOfDay(res,outDay) # 最高价卖出
    # outPrice = parser.getStartPriceOfDay(res,outDay) # 开盘价卖出
    if 0 == outPrice:
        return False  # 坏数据

    minPrice = 999999
    maxPrice = 0
    dayList = dayList[1:]  # 从买入后第2天开始统计最高价、最低价
    for day in dayList:
        maxP = parser.getMaxPriceOfDay(res, day)
        minP = parser.getMinPriceOfDay(res, day)
        if maxP > maxPrice:
            maxPrice = maxP
        if minP < minPrice:
            minPrice = minP

    ret = {}
    ret['id'] = id
    ret['name'] = Tools.getNameById(id)
    ret['inPrice'] = inPrice
    ret['outDay'] = outDay
    ret['outPrice'] = outPrice
    ret['holdDays'] = N
    ret['minPrice'] = minPrice
    ret['maxPrice'] = maxPrice
    return ret
Exemple #8
0
def trace1(id, parseDay):
    print id, parseDay
    parser = MaxPriceUnderMaParser.MaxPriceUnderMaParser(parseDay, id)
    priceFile = Tools.getPriceDirPath() + '/' + str(id)
    res = open(priceFile, 'r').read()

    dayList = parser.getNextTradingDayList(parseDay, 20)  #
    inDay = dayList[0]
    inPrice = parser.getStartPriceOfDay(res, inDay)  # 买入价为板后第一天的开盘价
    # inPrice = parser.getMinPriceOfDay(res,inDay)  #
    if 0 == inPrice:
        return False  # 坏数据

    # 确定止损价
    sp1 = parser.getMinPriceOfDay(res, parseDay)
    sp2 = parser.getMinPriceOfDay(res, inDay)
    stopPrice = min(sp1, sp2)

    outPrice = 0
    dayList = dayList[1:]
    holdDays = 0
    for day in dayList:
        holdDays += 1
        minPrice = parser.getMinPriceOfDay(res, day)
        endPrice = parser.getEndPriceOfDay(res, day)
        if endPrice == 0:
            outPrice = 0
            break
        if endPrice < stopPrice:
            outPrice = endPrice
            outDay = day
            break
        else:
            stopPrice = minPrice

    if outPrice == 0:
        return False

    ret = {}
    ret['id'] = id
    ret['name'] = Tools.getNameById(id)
    ret['inPrice'] = inPrice
    ret['outDay'] = outDay
    ret['outPrice'] = outPrice
    ret['holdDays'] = holdDays
    ret['minPrice'] = 0
    ret['maxPrice'] = 0
    return ret
Exemple #9
0
def trace2(id, parseDay):
    print id, parseDay
    parser = MaxPriceUnderMaParser.MaxPriceUnderMaParser(parseDay, id)
    priceFile = Tools.getPriceDirPath() + '/' + str(id)
    res = open(priceFile, 'r').read()

    dayList = parser.getNextTradingDayList(parseDay, 50)  #
    inDay = dayList[0]
    inPrice = parser.getStartPriceOfDay(res, inDay)  # 买入价为板后第一天的开盘价
    if 0 == inPrice:
        return False  # 坏数据

    sp1 = parser.getMinPriceOfDay(res, parseDay)
    sp2 = parser.getMinPriceOfDay(res, inDay)
    stopPrice = min(sp1, sp2)

    outPrice = 0

    l = len(dayList)
    holdDays = 0
    for i in xrange(1, l):
        day = dayList[i]
        minPrice = parser.getMinPriceOfDay(res, day)
        minPriceLastDay = parser.getMinPriceOfDay(res, dayList[i - 1])
        holdDays += 1
        if minPrice == 0:
            outPrice = 0
            break
        if minPrice < stopPrice:  # 触发止损
            outDay = day
            outPrice = stopPrice
            break
        else:  # 未触发止损,上调止损价
            stopPrice = min(minPriceLastDay, minPrice)

    if outPrice == 0:
        return False

    ret = {}
    ret['id'] = id
    ret['name'] = Tools.getNameById(id)
    ret['inPrice'] = inPrice
    ret['outDay'] = outDay
    ret['outPrice'] = outPrice
    ret['holdDays'] = holdDays
    ret['minPrice'] = 0
    ret['maxPrice'] = 0
    return ret
Exemple #10
0
    def parse(self, res, parseDay, id=''):
        # 近几日无涨停、跌停行情,排除基于获利和解套的
        dayList = BaseParser.getPastTradingDayList(parseDay, 5)
        for day in dayList:
            if self.isUpwardLimit(res, day):
                return False
            if self.isDownwardLimit(res, day):
                return False

        # 流通市值小于50亿
        basicInfo = BaseParser.getBasicInfoById(id)
        mvc = float(basicInfo[45])
        if mvc < 1:
            return False  # 错误数据

        if mvc > 5000000000:
            return False

        # 去掉ST,涨停有限
        name = Tools.getNameById(id)
        if 'st' in name or 'ST' in name:
            return False

        # # 换手率大于1%
        # changeRate = float(self.geChangeRateOfDay(res,parseDay))
        # if changeRate < 1.0:
        #   return False

        return True
Exemple #11
0
def getTopGrowthIdListOfDayList(dayList):
    allList = []
    day1 = dayList[0]
    day2 = dayList[-1]
    idList = getAllIdList()
    parser = BaseParser.BaseParser(dayList[0])

    for id in idList:
        path = Tools.getPriceDirPath() + '/' + str(id)
        res = open(path, 'r').read()
        endPrice1 = parser.getEndPriceOfDay(res, day1)
        endPrice2 = parser.getEndPriceOfDay(res, day2)

        # print day1,day2
        # print endPrice1,endPrice2

        if 0 == endPrice1:
            rate = -1
        else:
            rate = round((endPrice2 - endPrice1) / endPrice1, 5)
        allList.append((id, rate))

    # 排序
    allList = sorted(allList, key=lambda i: i[1])
    l = len(allList)
    # print allList[0]
    # print allList[-1]
    #allList = allList[l-topNum:]
    allList = allList[traceDays:traceDays * 2]
    return allList
Exemple #12
0
  def isBiasMinOfDays(parseDay,days,id):

    path = Tools.getBiasDataPath()+'/' +id
    res = open(path,'r').read()
    dayList = BaseParser.getPastTradingDayList(parseDay,days)
    biasList = eval(res[26:-1])
    dataOfDays = {}
    for item in biasList:
      for d in dayList:
        if d == item['time']:
          dataOfDays[d] = eval(item['bias'])

    # 坏数据:个股交易日未必连续        
    if (len(dataOfDays)<1) or (len(dayList) != len(dataOfDays)):
      # print 'len(dataOfDays)<1) or (len(dayList) != len(dataOfDays)'
      return False


    # bias n日最低
    biasIsMin = True
    bias = float(dataOfDays[parseDay][1])
    for day,data in dataOfDays.items():
      theBias = float(dataOfDays[day][1])
      if theBias < bias:
        biasIsMin = False
        break

    if not biasIsMin:
      return False

    return True
    def calcuR(self, idList, num):
        vList = []
        for id in idList:
            path = Tools.getPriceDirPath() + '/' + str(id)
            res = open(path, 'r').read()

            # am = self.getEntityAm(res,parseDay)
            # d = KdjParser.getD(parseDay,id)

            # r = am/d
            # r = d

            dayList = BaseParser.getPastTradingDayList(parseDay, 5)
            (v, v, ma) = self.getMAPrice(res, dayList)
            endPrice = self.getEndPriceOfDay(res, parseDay)

            r = ma / endPrice

            vList.append((id, r))

        # 排序
        sList = sorted(vList, key=lambda x: -x[1])
        # sList = sorted(vList,key=lambda x: x[1])
        print "sorted list:"
        print sList
        selectedList = sList[:num]

        print "\nselected list:"
        print selectedList
        l = []
        for item in selectedList:
            l.append(item[0])
        return l
Exemple #14
0
  def isRecentlyPenetrate(self,id,parseDay):
    try:
      path = Tools.getPriceDirPath()+'/'+str(id)
      res = open(path,'r').read()

      # 1 2 3 4
      dayList = self.getPastTradingDayList(parseDay,8)
      startDay = dayList[0]
      endDay = dayList[-1]

      shortTerm = 13
      longTerm = 34

      dayList = self.getPastTradingDayList(startDay,shortTerm)
      (v,v,startDayM13) = self.getMAPrice(res,dayList)
      dayList = self.getPastTradingDayList(startDay,longTerm)
      (v,v,startDayM34) = self.getMAPrice(res,dayList)

      dayList = self.getPastTradingDayList(endDay,shortTerm)
      (v,v,endDayM13) = self.getMAPrice(res,dayList)
      dayList = self.getPastTradingDayList(endDay,longTerm)
      (v,v,endDayM34) = self.getMAPrice(res,dayList)

      isRecentlyPenetrate = ((startDayM13 < startDayM34) and (endDayM13 > endDayM34))
    except Exception, e:
      isRecentlyPenetrate = None
Exemple #15
0
    def isDUpwardAndNotTooHigh(parseDay, id):
        path = Tools.getKdjDataPath() + '/' + id
        res = open(path, 'r').read()
        dayList = BaseParser.getPastTradingDayList(parseDay, 2)
        kdjList = eval(res[26:-1])
        dataOfDays = {}
        for item in kdjList:
            for d in dayList:
                if d == item['time']:
                    dataOfDays[d] = eval(item['kdj'])

        # print dataOfDays
        d1 = float(dataOfDays[dayList[-2]][1])
        d = float(dataOfDays[dayList[-1]][1])

        # 数据错误,当做下降处理
        if (len(dataOfDays) < 1) or (len(dayList) != len(dataOfDays)):
            return False

        # d在下降
        if d < d1:
            return False

        # d大于70
        if d > 70:
            return False

        return True
Exemple #16
0
    def isKdjBull(parseDay, id):
        path = Tools.getKdjDataPath() + '/' + id
        res = open(path, 'r').read()
        dayList = BaseParser.getPastTradingDayList(parseDay, 2)
        kdjList = eval(res[26:-1])
        dataOfDays = {}
        for item in kdjList:
            for d in dayList:
                if d == item['time']:
                    dataOfDays[d] = eval(item['kdj'])

        # 数据错误
        if (len(dataOfDays) < 1) or (len(dayList) != len(dataOfDays)):
            return False

        k1 = float(dataOfDays[dayList[-2]][0])
        k2 = float(dataOfDays[dayList[-1]][0])
        d1 = float(dataOfDays[dayList[-2]][1])
        d2 = float(dataOfDays[dayList[-1]][1])
        j1 = float(dataOfDays[dayList[-2]][2])
        j2 = float(dataOfDays[dayList[-1]][2])

        # D在20之下
        dayLimit = 20
        if d2 > dayLimit or d2 < 1:  # d大于20,或d数据错误
            return False

        if (k2 <= k1) or (d2 <= d1) or (j2 <= j1):
            return False

        # J K D
        if not ((j2 > k2) and (k2 > d2)):
            return False

        return True
Exemple #17
0
    def calcuR(self, idList, num):
        num = topNum  # 前n
        vList = []
        for id in idList:
            path = Tools.getPriceDirPath() + '/' + str(id)
            res = open(path, 'r').read()

            # 近60日涨停数
            upwardLimitNum = self.countUpwardLimits(res, parseDay, 60)
            if upwardLimitNum < 1:
                continue
            print str(upwardLimitNum)

            r = upwardLimitNum
            vList.append((id, r))

        # 排序
        sList = sorted(vList, key=lambda x: -x[1])
        print "sorted list:"
        print sList
        selectedList = sList[:num]

        print "\nselected list:"
        print selectedList
        l = []
        for item in selectedList:
            l.append(item[0])
        return l
Exemple #18
0
    def calcuR(self, idList, num):
        maDays = 10  # 均线
        vList = []
        for id in idList:
            path = Tools.getPriceDirPath() + '/' + str(id)
            res = open(path, 'r').read()
            (v, v, ma) = self.getMAPrice(
                res, self.getPastTradingDayList(self._parseDay, maDays))
            endPrice = self.getEndPriceOfDay(res, self._parseDay)
            if ma == -1 or endPrice == 0:
                continue
            r = endPrice / ma
            vList.append((id, r))

        # 排序
        sList = sorted(vList, key=lambda x: x[1])  #
        print "sorted list:"
        print sList
        selectedList = sList[:num]

        print "\nselected list:"
        print selectedList
        l = []
        for item in selectedList:
            l.append(item[0])
        return l
Exemple #19
0
    def calcuR(self, idList, num):
        num = topNum  # 前n
        vList = []
        for id in idList:
            path = Tools.getPriceDirPath() + '/' + str(id)
            res = open(path, 'r').read()

            # 振幅
            am = self.getAm(res, parseDay)
            print am

            r = am
            vList.append((id, r))

        # 排序
        sList = sorted(vList, key=lambda x: -x[1])
        print "sorted list:"
        print sList
        selectedList = sList[:num]

        print "\nselected list:"
        print selectedList
        l = []
        for item in selectedList:
            l.append(item[0])
        return l
Exemple #20
0
 def initDir(self):
     if len(self._source) < 1:
         raise Exception("Exception:source未设置!")
     if BaseHotPoint.isNew():
         Tools.initDir(self._source)
         Tools.initDir('failed_' + self._source)
     else:
         Tools.touchDir(self._source)
         Tools.touchDir('failed_' + self._source)
Exemple #21
0
def run(parseDay, parsers, isNew=False):
    if isNew:
        spiders = [
            'PriceSpider',
            # 'KdjSpider',
            # 'BiasSpider',
            # 'MacdSpider',
            # 'BasicInfoSpider'
        ]
        runSpiders(spiders)

    Tools.initDir('enterList')
    for parser, tag in parsers.items():
        cmd = 'python ' + Tools.getParsersDirPath(
        ) + '/' + parser + '.py ' + parseDay
        print cmd
        os.system(cmd)
Exemple #22
0
def trace555(id, parseDay):
    print '5日线上走'
    N = 20  # 持股天数
    print id, parseDay
    parser = RelativeParser.RelativeParser(parseDay, id)
    priceFile = Tools.getPriceDirPath() + '/' + str(id)
    res = open(priceFile, 'r').read()

    dayList = parser.getNextTradingDayList(parseDay, N)  #
    inDay = dayList[0]
    inPrice = parser.getStartPriceOfDay(res, inDay)  # 开盘价买入
    if 0 == inPrice:
        return False  # 坏数据

    outDay = dayList[-1]  # 默认卖出日
    outPrice = parser.getEndPriceOfDay(res, outDay)  # 收盘价卖出
    if 0 == outPrice:
        return False  # 坏数据

    minPrice = 999999
    maxPrice = 0
    dayList = dayList[1:]  # 从买入后第2天开始统计最高价、最低价
    for day in dayList:
        maxP = parser.getMaxPriceOfDay(res, day)
        minP = parser.getMinPriceOfDay(res, day)
        if maxP > maxPrice:
            maxPrice = maxP
        if minP < minPrice:
            minPrice = minP
        maDayList = parser.getPastTradingDayList(day, 5)
        (v, v, ma) = parser.getMAPrice(res, maDayList)
        if minP > ma:
            outDay = day
            outPrice = parser.getEndPriceOfDay(res, day)  # 收盘价卖出
            break

    ret = {}
    ret['id'] = id
    ret['name'] = Tools.getNameById(id)
    ret['inPrice'] = inPrice
    ret['outDay'] = outDay
    ret['outPrice'] = outPrice
    ret['holdDays'] = N
    ret['minPrice'] = minPrice
    ret['maxPrice'] = maxPrice
    return ret
Exemple #23
0
def dumpBkReport(allBk, bkShowTimes):
    pass
    s = '<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" />'
    s += '''
<style>
font-size:0.8em;

table {
  width:100%;
}

td{
  font-size:0.8em;
  text-align:center;
  padding:5px;
  border-bottom: thin dashed #ccc;
}

.table_header{
  font-weight:bold;
  font-size:1.2em;
}

</style>
  '''
    s += '</head><body>'
    s += '<table width="100%" cellspacing="0" cellpadding="0">'
    s += '<tr class="table_header">'
    s += '<td>序号</td>'
    s += '<td>板块名称</td>'
    s += '<td>出现次数</td>'
    s += '</tr>'

    bkList = []
    for bkCode, bkInfo in allBk.items():
        times = 0
        if bkShowTimes.has_key(bkInfo[1]):
            times = bkShowTimes[bkInfo[1]]
        bk = (bkInfo, times)
        bkList.append(bk)

    # 排序
    bkList = sorted(bkList, key=lambda i: (-i[1]))

    i = 1
    for bk in bkList:
        tr = '<tr>'
        tr += '<td>' + str(i) + '</td>'
        i += 1
        tr += '<td>' + str(bk[0][1]) + '</td>'
        tr += '<td>' + str(bk[1]) + '</td>'
        s += tr
    s += '</table>'

    parseTime = time.strftime('%Y-%m-%d', time.localtime(time.time()))
    path = Tools.getReportDirPath() + '/BK-Count.html'
    open(path, 'w').write(s)
    os.system('open ' + path)
Exemple #24
0
 def dumpIdList(self,idList):
   print 'dumpIdList'
   enterListDirPath = Tools.getEnterListDirPath()
   #open('data/golden-pin-bottom/'+ confirmDay +'.sel','w').write(','.join(idList))
   open(enterListDirPath + '/' + self._parseDay + '-'+ self._tag+'.sel','w').write(','.join(idList))
   print "\n\n",self._parseDay
   print "============================================ Result ============================================ \n"
   print str(idList) + "\n\n"
   print " - " + str(len(idList)) + " - \n\n"
Exemple #25
0
def getFilteredIdList(date):
    # http://quote.eastmoney.com/stocklist.html
    fp = Tools.getRootPath() + '/data/enterList/' + date + '-FilterParser.sel'
    f = open(fp, 'r')
    data = f.read()
    idList = data.split(',')
    if len(idList) < 1:
        print "\n候选id列表为空!\n"
    return idList
Exemple #26
0
    def parse(self, res, id=''):
        print id
        data = {}
        dayList = BaseParser.getPastTradingDayList(self._parseDay, 100)

        endPrice = self._parser.getEndPriceOfDay(res, self._parseDay)
        # lastDayMaxPrice = self._parser.getMaxPriceOfDay(res,dayList[-2])
        lastDayEndPrice = self._parser.getMaxPriceOfDay(res, dayList[-2])

        startDay = ''
        peakDay = ''
        leftInterval = 0
        rightInterval = 0
        total = len(dayList)

        # 寻找区间顶
        for i in xrange(3, total - 1):  # 从-3开始
            maxPrice = self._parser.getMaxPriceOfDay(res, dayList[-i])
            if maxPrice >= endPrice:  # 最高价已超过当日收盘价,突破已不存在
                break
            if maxPrice > lastDayEndPrice:
                peakDay = dayList[-i]  # 区间顶
                rightInterval = i - 1
                break
        if '' == peakDay:
            return False

    # 确定左边区间
        peakDayMaxPrice = self._parser.getMaxPriceOfDay(res, peakDay)
        dayList = BaseParser.getPastTradingDayList(peakDay, 100)
        total = len(dayList)
        for i in xrange(2, total - 1):
            maxPrice = self._parser.getMaxPriceOfDay(res, dayList[-i])
            if maxPrice > peakDayMaxPrice:
                startDay = dayList[-i]
                leftInterval = i
                break
        if '' == startDay:
            return False

        if leftInterval < minLeftInterval:
            return False

        if rightInterval < minRightInterval:
            return False

        data = {
            "id": id,
            "name": Tools.getNameById(id),
            "startDay": startDay,
            "leftInterval": leftInterval,
            "peakDay": peakDay,
            "rightInterval": rightInterval,
            "breakDay": self._parseDay
        }
        return data
Exemple #27
0
def dumpReport(ret):
    tPath = Tools.getRootPath() + '/src/tools/T_EndPriceComparators.html'
    for code, data in ret.items():
        s = '['
        detail = ''
        t = open(tPath, 'r').read()
        for item in data:
            s += str(item[1]) + ','
            detail += item[0] + ' : ' + str(item[1]) + '<br/>'
        s = s[:-2]
        s += '];'
        t = t.replace('$DATA$', s)

        name = Tools.getNameById(code)
        t = t.replace('$CODE$', code + ' ' + name)
        t = t.replace('$DETAILS$', detail)
        path = Tools.getReportDirPath(
        ) + '/EndPriceCompareReport-' + code + '.html'
        open(path, 'w').write(t)
        os.system('open ' + path)
Exemple #28
0
def getMinPriceOfDays(id, dayList):
    parser = BaseParser.BaseParser(dayList[-1])
    priceFile = Tools.getPriceDirPath() + '/' + str(id)
    res = open(priceFile, 'r').read()

    minPrice = 999999
    for d in dayList:
        price = parser.getMinPriceOfDay(res, d)
        if price < minPrice:
            minPrice = price
    return minPrice
Exemple #29
0
  def getGrowthRate(self,id,startDay,endDay):
    try:
      path = Tools.getPriceDirPath()+'/'+str(id)
      res = open(path,'r').read()

      startPrice = self.getEndPriceOfDay(res,startDay)
      endPrice = self.getEndPriceOfDay(res,endDay)

      rate = float((endPrice - startPrice)/startPrice)*100
    except Exception, e:
      rate = 0
Exemple #30
0
 def run(self):
   try:
     for parseDay in self._dayList:
       # print parseDay
       print str(self._threadId) + ' -> ' + parseDay
       cmd = 'python '+Tools.getParsersDirPath() + '/'+ parser +'.py ' + parseDay
       print cmd
       os.system(cmd)
   except Exception, e:
     pass
     print repr(e)