Exemplo n.º 1
0
def findByMa2(lastDays=40, ma1=10, ma2=20, condition=settings.HIGHER):
    stocks = findAllExistentTickers()
    result = []

    for code in ['600600']:
        try:
            temp = getMa(code, lastDays, ma1)
            print temp

            temp2 = getMa(code, lastDays, ma2)

            size = len(temp)
            print code + ':' + str(size)

            flag = True
            for i in range(1, size):
                print temp2[i]
                print temp[i]
                if temp2[i] > temp[i]:
                    flag = False
                    logger.warn(code + ' does not pass MA:' + str(i))
                    break

            if flag:
                result.append(code)
        except:
            traceback.print_exc(file=sys.stdout)
            continue

    return result
Exemplo n.º 2
0
def findByNhnl(lastDays=200, nearDays=5):
    stocks = findAllExistentTickers()
    nhnlList = {'nhList': [], 'nlList': []}
    nh = 0
    nl = 0

    for code in stocks:
        try:
            triggered = triggerNhNl(code, lastDays, nearDays)
            print triggered
            if triggered == 0:
                continue
            elif triggered.get('value') == 1:
                nhnlList['nhList'].append({
                    'date': triggered['date'],
                    'code': code
                })
                nh += 1
            elif triggered.get('value') == -1:
                nhnlList['nlList'].append({
                    'date': triggered['date'],
                    'code': code
                })
                nl += 1

        except:
            traceback.print_exc(file=sys.stdout)
            continue
    nhnlList['nh'] = nh
    nhnlList['nl'] = nl
    nhnlList['nhnl'] = nh - nl
    return nhnlList
Exemplo n.º 3
0
def findByNhnl(lastDays=200,nearDays=5):
    stocks = findAllExistentTickers()
    nhnlList = {'nhList':[],'nlList':[]}
    nh = 0
    nl = 0
   
    for code in stocks:       
                try:
                    triggered = triggerNhNl(code,lastDays,nearDays) 
                    print triggered
                    if triggered == 0:
                        continue
                    elif triggered.get('value') == 1:
                        nhnlList['nhList'].append({'date':triggered['date'],'code':code})
                        nh += 1;
                    elif triggered.get('value') == -1:
                        nhnlList['nlList'].append({'date':triggered['date'],'code':code})
                        nl += 1;
                                                                                            
                except:
                    traceback.print_exc(file=sys.stdout)
                    continue 
    nhnlList['nh'] = nh
    nhnlList['nl'] = nl
    nhnlList['nhnl'] = nh - nl
    return nhnlList  
Exemplo n.º 4
0
def findByMa2(lastDays=40,ma1=10,ma2=20,condition=settings.HIGHER):
    stocks = findAllExistentTickers()
    result = []
    
    for code in ['600600']:       
                try:
                    temp = getMa(code,lastDays,ma1) 
                    print temp   
                    
                    temp2 = getMa(code,lastDays,ma2) 
                   
                    size = len(temp)
                    print code+':'+str(size)
                    
                    flag = True
                    for i in range(1,size):
                        print temp2[i]
                        print temp[i]
                        if temp2[i] > temp[i]:
                            flag = False     
                            logger.warn(code+' does not pass MA:'+str(i))                       
                            break;
                            
                    if flag:         
                        result.append(code)    
                except:
                    traceback.print_exc(file=sys.stdout)
                    continue 
      
        
    return result 
Exemplo n.º 5
0
def download2(clearAll=False,
              download_latest=False,
              downloadHistory=False,
              parse_industry=False,
              stockList='stock_list_all'):
    logger.info('Begin Download stock list data {}'.format(stockList))
    if clearAll:
        #clear redis cache
        # redclient.flushall()
        clear()

    #download securities list from local
    downloadQuoteList(True, False, stockList)
    quotes = findAllExistentTickers()

    import multiprocessing as mp
    pool = mp.Pool(len(quotes))

    for code in quotes:
        s = Stock(code)
        pool.apply_async(download_stock,
                         args=[
                             s, download_latest, settings.SINA, True,
                             settings.CSV_ENGINE, False
                         ])

    pool.close()
    pool.join()
    logger.info('****Download latest price from sina finished****')
Exemplo n.º 6
0
 def test_peak_price(self):
     delta = timedelta(-20)
     begin = date.today()+delta
     #begin_date ='2014-1-1'
     #rise('600327',begin)
     # find_percentage(['600327','600583'],'2014-01-01')
     result = find_percentage(findAllExistentTickers(),'2014-01-01')
     for stock in result:
         logger.debug(stock.shortStr())
Exemplo n.º 7
0
 def test_peak_price(self):
     delta = timedelta(-20)
     begin = date.today() + delta
     #begin_date ='2014-1-1'
     #rise('600327',begin)
     # find_percentage(['600327','600583'],'2014-01-01')
     result = find_percentage(findAllExistentTickers(), '2014-01-01')
     for stock in result:
         logger.debug(stock.shortStr())
Exemplo n.º 8
0
def downloadLatestData(quotes = findAllExistentTickers(),engine='sina'):
    logger.info( '****Begin Download latest price from SINA****'+str(len(quotes)))
    import multiprocessing as mp
    pool = mp.Pool(len(quotes))
    
    for code in quotes: 
        update(code,engine)
        pool.apply_async(update, args = [str(code),engine])
    
    pool.close()
    pool.join()        
    logger.info( '****Download latest price from sina finished****')
Exemplo n.º 9
0
def findByMa(lastDays=40, ma=10, condition=settings.HIGHER):
    stocks = findAllExistentTickers()
    result = []

    for code in stocks:
        try:
            triggered = checkStockWithMA(code, lastDays, ma, condition)
            print code + str(triggered)
            if triggered:
                result.append(code)
        except:
            traceback.print_exc(file=sys.stdout)
            continue

    return result
Exemplo n.º 10
0
def findByMa(lastDays=40,ma=10,condition=settings.HIGHER):
    stocks = findAllExistentTickers()
    result = []
    
    for code in stocks:       
                try:
                    triggered = checkStockWithMA(code,lastDays,ma,condition) 
                    print code+str(triggered)
                    if triggered:
                        result.append(code)                      
                except:
                    traceback.print_exc(file=sys.stdout)
                    continue 
      
        
    return result     
Exemplo n.º 11
0
def download(clearAll=False,
             downloadLatest=False,
             downloadHistory=False,
             parse_industry=False,
             stockList='stock_list_all'):
    from stocktrace.parse.yahooparser import downloadHistoryData
    from stocktrace.dao.stockdao import clear, findAllExistentTickers
    from stocktrace.parse.reutersparser import downloadKeyStatDatas
    from stocktrace.parse.sinaparser import downloadLatestData
    from stocktrace.parse.ifengparser import parseIndustry
    from stocktrace.redis.redisservice import findStocksByList

    logger.info('***Start download finance data****')

    if clearAll:
        #clear redis cache
        # redclient.flushall()
        clear()
    #download industry info from ifeng
    if parse_industry:
        parseIndustry()

    #download securities list from local
    downloadQuoteList(True, False, stockList)

    #load stock list to redis zset
    loadStockListToRedis(stockList)

    #download statistics from reuters
    if settings.DOWNLOAD_KEY_STAT:
        downloadKeyStatDatas()

    quotes = findAllExistentTickers()
    #find from redis cache
    # quotes = findStocksByList(stockList)
    # quotes = stockList
    logger.debug(quotes)
    #update latest price from yahoo or sina
    #Seems YQL API is not stable,tables often to be locked
    if downloadLatest:
        downloadLatestData(quotes, engine=settings.SINA)

    if downloadHistory:
        #download history data from yahoo
        downloadHistoryData(quotes, engine=settings.CSV_ENGINE)

    logger.info('***Finish download finance data****')
Exemplo n.º 12
0
def download(clearAll= False,downloadLatest = False,downloadHistory = False,parse_industry = False,stockList='stock_list_all'):
    from stocktrace.parse.yahooparser import downloadHistoryData
    from stocktrace.dao.stockdao import clear,findAllExistentTickers
    from stocktrace.parse.reutersparser import downloadKeyStatDatas
    from stocktrace.parse.sinaparser import downloadLatestData
    from stocktrace.parse.ifengparser import parseIndustry
    from stocktrace.redis.redisservice import findStocksByList
    
    logger.info('***Start download finance data****')
    
    if clearAll:
        #clear redis cache
        # redclient.flushall()
        clear();
    #download industry info from ifeng
    if parse_industry:
        parseIndustry()
    
    #download securities list from local
    downloadQuoteList(True,False,stockList)
    
    #load stock list to redis zset
    loadStockListToRedis(stockList)
    
    #download statistics from reuters        
    if settings.DOWNLOAD_KEY_STAT:
        downloadKeyStatDatas()
        
    quotes = findAllExistentTickers()
    #find from redis cache
    # quotes = findStocksByList(stockList)
    # quotes = stockList
    logger.debug(quotes)
    #update latest price from yahoo or sina
    #Seems YQL API is not stable,tables often to be locked
    if downloadLatest:
        downloadLatestData(quotes,engine = settings.SINA)
        
    if downloadHistory:
        #download history data from yahoo
        downloadHistoryData(quotes,engine = settings.CSV_ENGINE)
    
    logger.info('***Finish download finance data****')
Exemplo n.º 13
0
def download2(clearAll= False,download_latest = False,downloadHistory = False,parse_industry = False,stockList='stock_list_all'):
    logger.info( 'Begin Download stock list data {}'.format(stockList))
    if clearAll:
        #clear redis cache
        # redclient.flushall()
        clear();

    #download securities list from local
    downloadQuoteList(True,False,stockList)
    quotes = findAllExistentTickers()

    import multiprocessing as mp
    pool = mp.Pool(len(quotes))

    for code in quotes:
        s = Stock(code)
        pool.apply_async(download_stock, args = [s,download_latest, settings.SINA, True,
             settings.CSV_ENGINE, False])

    pool.close()
    pool.join()
    logger.info( '****Download latest price from sina finished****')