【中金固收·可转债】简易的转债策略测试框架——以及python实现方法 20190519( 九 )

If selMethod:

tempCodes= list(condition[condition].index)

moreCon= selMethod(obj, codes, date, tempCodes)

condition&= moreCon

# 这个函数最后返回的变量是这个

retCodes = list(condition[condition].index)

# 如果一个都没有,进入这里,并给出提示

if not retCodes:

print 'its a empty selection, when date: ',date

return retCodes

# 下面以低价策略举例,如果我们希望在调仓时买入所有价格低于均价的品种,则可以写下面这个函数,并把_lowprice作为selMethod传入上面的函数:

def _lowPrice(obj, codes, date, tempCodes):

avgPrice = obj.DB['Close'].loc[date][tempCodes].mean()

推荐阅读