コード例 #1
0
def get_plan_sell_list_mv(planSellList, tradingDay, signalData, dailyQuote, cannotSellList, dailyQuote1day, currHoldSet):
    planSellListMV = []
    if len(planSellList) == 0:
        return planSellListMV

    # 排序
    planSellList = sort_by_tech(planSellList, signalData, tradingDay, StockConst.MOM) #TODO 排序

    for innerCode in planSellList:
        isCannotSell = SourceDataDao.check_if_cannot_sell_1day(dailyQuote1day, innerCode)

        #能卖
        if not isCannotSell:
            dailyQuoteRow = SourceDataDao.select_by_inner_code_and_date(dailyQuote, tradingDay, innerCode)

            stockHoldEntity = currHoldSet.get(innerCode)
            # 当前vwap
            sellPrice = BackTestHelper.get_vwap(dailyQuoteRow)
            # 当前市值
            sellMV = BackTestHelper.get_sell_mv(stockHoldEntity.buyPrice, stockHoldEntity.buyMV, sellPrice)

            # mVEntity = MVEntity.MVEntity(innerCode, currMV)
            planDict = {StockConst.INNERCODE: innerCode, planDictMV: sellMV, planDictPrice:sellPrice}
            planSellListMV.append(planDict)
        else:
            cannotSellList.append(innerCode)

    return planSellListMV
コード例 #2
0
def get_plan_sell_list_mv(planSellList, tradingDay, signalData, dailyQuote, cannotSellList, dailyQuote1day, currHoldSet, preHoldList, currSelectStock, lastCapitalEntity):
    planSellListMV = []
    if len(planSellList) == 0:
        return planSellListMV

    # 昨日总现金
    lastTotalCash = get_last_total_cash(lastCapitalEntity)

    # 排序
    planSellList = sort_by_tech(planSellList, signalData, tradingDay, StockConst.MOM) #TODO 排序

    for innerCode in planSellList:
        isCannotSell = SourceDataDao.check_if_cannot_sell_1day(dailyQuote1day, innerCode)

        #能卖
        if not isCannotSell:
            dailyQuoteRow = SourceDataDao.select_by_inner_code_and_date(dailyQuote, tradingDay, innerCode)

            stockHoldEntity = currHoldSet.get(innerCode)
            # 当前vwap
            sellPrice = BackTestHelper.get_vwap(dailyQuoteRow)
            # 当前市值
            sellMV = BackTestHelper.get_sell_mv(stockHoldEntity.closePrice, stockHoldEntity.closeMV, sellPrice) #stockHoldEntity.buyPrice, stockHoldEntity.buyMV

            # [处理调整仓位2017-03-28]######################################
            # 在昨日持有列表中:调整仓位
            isAdjust = None
            partialFlg = None
            if innerCode in preHoldList:
                volWeight = currSelectStock.ix[innerCode][StockConst.VOL_WEIGHT]
                # 计划买入现金=昨日总现金*仓位权重
                buyCash = lastTotalCash * volWeight
                # 不卖的情况
                if sellMV <= buyCash:
                    sellMV = 0
                # 调整仓位
                else:
                    sellMV = sellMV - buyCash
                    isAdjust = 1
                    partialFlg = 1
            #################################################

            # 有卖出
            if sellMV > 0:
                planDict = {StockConst.TRADINGDAY: tradingDay, StockConst.INNERCODE: innerCode, planDictMV: sellMV, planDictPrice: sellPrice, planDictIsAdjust:isAdjust, 'partialFlg': partialFlg}
                planSellListMV.append(planDict)
        else:
            cannotSellList.append(innerCode)

    return planSellListMV