Exemplo n.º 1
0
def main():
    signalData = SourceDataDao.getSignalData()
    dailyQuote = SourceDataDao.getDailyQuote()

    #columns filter
    #df3 = sourceData.loc[(df['Mom'] <= 4) & (df['Mom'] <= 4), ['Mom']]

    #index filter
    #startDate=DateUtils.str2Datetime('20010105');
    #endDate=DateUtils.str2Datetime('20010111');
    #df4 = df3.ix[startDate:endDate]

    #select top 5 group by TradingDay order by Mom desc
    groupedSignalData = signalData.groupby(level='TradingDay').apply(
        SelectUtil.top, 5, 'Mom', False)

    #param
    #period = 5
    startDate = '1/8/2001'
    #endDate = '1/1/2017'
    endDate = '18/1/2001'

    #time series
    dateList = DateUtil.get_date_list2(startDate, endDate)

    stockHoldDF = {}
    stockTradeDF = {}
    lastSignalData = pd.DataFrame()
    usableVol = 100
    netValue = 1
    stockStatDaily = pd.DataFrame(index=pd.date_range(startDate, endDate),
                                  columns=['netValue', 'changePCT'])
    for date in dateList.index:
        #print(date)
        dateStr = DateUtil.datetime2_str(date)
        #print(dateStr)
        #isinstance(date, datetime)
        #DateUtil.str2Datetime('20010108')

        # select by single date
        try:
            #print(1)
            currSignalData = groupedSignalData.ix[date]
            print("currSignalData:" + str(len(currSignalData)))
            print(currSignalData)

        except:
            #假期,双休日,原数据问题
            print(DateUtil.datetime2_str(date) + ': no data')
            continue
Exemplo n.º 2
0
def main():
    signalData = SourceDataDao.getSignalData()
    dailyQuote = SourceDataDao.getDailyQuote()

    #columns filter
    #df3 = sourceData.loc[(df['Mom'] <= 4) & (df['Mom'] <= 4), ['Mom']]

    #index filter
    #startDate=DateUtils.str2Datetime('20010105');
    #endDate=DateUtils.str2Datetime('20010111');
    #df4 = df3.ix[startDate:endDate]

    #select top 5 group by TradingDay order by Mom desc
    groupedSignalData = signalData.groupby(level='TradingDay').apply(SelectUtil.top,5,'Mom',False)

    #param
    period = 5
    startDate = '1/8/2001'
    #endDate = '1/1/2017'
    endDate = '1/18/2001'

    #time series
    dateList = DateUtil.get_date_list2(startDate, endDate)

    currHoldSet = {}
    stockHoldDF = {}
    stockTradeDF = {}
    #lastSignalData = pd.DataFrame()
    usableVol = 100;
    netValue = 1;
    stockStatDaily = pd.DataFrame(index=pd.date_range(startDate, endDate), columns=['netValue','changePCT','buyCnt','sellCnt','holdCnt'])
    for date in dateList.index:
        #print(date)
        dateStr = DateUtil.datetime2_str(date)
        #print(dateStr)
        #isinstance(date, datetime)
        #DateUtil.str2Datetime('20010108')

        # select by single date
        try:
            #print(1)
            currSignalData = groupedSignalData.ix[date]
            print("currSignalData:"+str(len(currSignalData)))
            #print(2)
            buyList = getBuyList(currSignalData,lastSignalData)
            #print(3)
            sellList = getSellList(currSignalData,lastSignalData)
            #print(4)
            holdList = getHoldList(currSignalData,lastSignalData)
            #print(currSignalData)
            #print("len:"+str(len(currSignalData)))
        except:
            #假期,双休日,原数据问题
            print(DateUtil.datetime2_str(date) + ': no data')
            continue

        buyCnt = len(buyList)
        sellCnt = len(sellList)
        holdCnt = len(holdList)

        dailyChangePCT = 0
        changePCTBuy = handleBuyList(date,buyList,dailyQuote,usableVol,stockHoldDF,stockTradeDF)
        releasedVol = getReleasedVol(sellList, stockHoldDF)
        usableVol = usableVol + releasedVol
        changePCTSell = handleSellList(date,sellList,dailyQuote,usableVol,stockHoldDF,stockTradeDF)
        #changePCTHold = handleHoldList(date, sellList, dailyQuote, usableVol, stockHoldDF, stockTradeDF)
        changePCTHold = 0

        print("dateStr:" + dateStr +
              " changePCTBuy:" + str(changePCTBuy) +
              " changePCTSell:" + str(changePCTSell) +
              " changePCTHold:" + str(changePCTHold))

        dailyChangePCT = changePCTBuy+changePCTSell+changePCTHold
        #print("dailyChangePCT:"+str(dailyChangePCT))
        netValue = netValue * (1 + dailyChangePCT / 100)
        #print("netValue:" + str(netValue))
        stockStatDaily.ix[dateStr] = netValue,dailyChangePCT,buyCnt,sellCnt,holdCnt

        #innerCodeList = currSignalData["InnerCode"]
        #print(innerCodeList)

        #lastSignalData = currSignalData

    print(stockStatDaily)