ROIC&cashROIC
来源:https://uqer.io/community/share/564d30eff9f06c4446b483db
from CAL.PyCAL import *
import numpy as np
from pandas import DataFrame , Series
start = '2015-01-01'
end = '2015-11-01'
benchmark = 'HS300'
universe = set_universe('HS300')
capital_base = 100000
freq = 'd'
refresh_rate = 30
cal = Calendar('China.SSE')
def initialize(account):
pass
def handle_data(account):
today = account.current_date.strftime('%Y%m%d')
yesterday = cal.advanceDate(account.current_date, '-1B', BizDayConvention.Following).strftime('%Y%m%d')
ROIC = {}
cashROIC = {}
EBITToTOR = DataAPI.MktStockFactorsOneDayGet(tradeDate=yesterday,secID=account.universe,field=u"secID,EBITToTOR",pandas="1")
EBITToTOR.drop_duplicates('secID' , inplace= True)
EBITToTOR.set_index('secID' , inplace = True)
tRevenue = DataAPI.FdmtISAllLatestGet(secID=account.universe,endDate=u"20151101",beginDate=u"20150101",field=u"secID,tRevenue",pandas="1")
tRevenue.drop_duplicates('secID' , inplace= True)
tRevenue.set_index('secID' , inplace = True)
freeCF = DataAPI.FdmtCFAllLatestGet(secID=account.universe,endDate=u"20151101",beginDate=u"20150101",field=u"secID,NCFOperateA,purFixAssetsOth,dispFixAssetsOth",pandas="1")
freeCF.drop_duplicates('secID' , inplace= True)
freeCF.set_index('secID' , inplace= True)
IC = DataAPI.FdmtBSAllLatestGet(secID=account.universe,endDate=u"20151101",beginDate=u"20150101",field=u"secID,TShEquity,LTBorr",pandas="1")
IC.drop_duplicates('secID' , inplace= True)
IC.set_index('secID' , inplace = True)
for s in account.universe:
ROIC[s] = (EBITToTOR['EBITToTOR'][s] * tRevenue['tRevenue'][s] * (1-0.25)) / (IC['TShEquity'][s] + IC['LTBorr'][s])
cashROIC[s] = (freeCF['NCFOperateA'][s] - (freeCF['purFixAssetsOth'][s] - freeCF['dispFixAssetsOth'][s])) / (IC['TShEquity'][s] + IC['LTBorr'][s])
ROIC = Series(ROIC)
ROIC.sort(ascending = False)
ROIC.dropna(inplace = True)
ROIC = ROIC[0:60]
buylist1 = list(ROIC.index)
cashROIC = Series(cashROIC)
cashROIC.sort(ascending = False)
cashROIC.dropna(inplace = True)
cashROIC = cashROIC[0:60]
buylist2 = list(cashROIC.index)
buylist = list(set(buylist1)&set(buylist2))
print 'buylist', len(buylist)
print buylist
sell_list = [x for x in account.valid_secpos if x not in buylist]
for s in sell_list :
order_to(s,0)
total_money = account.referencePortfolioValue
for s in buylist:
if s in account.valid_secpos:
pass
else:
order(s,total_money/(len(buylist)-len(set(buylist)&set(account.valid_secpos)))/account.referencePrice[s])
buylist 24
['601601.XSHG', '601899.XSHG', '000895.XSHE', '000539.XSHE', '600276.XSHG', '600011.XSHG', '600887.XSHG', '000712.XSHE', '600863.XSHG', '600018.XSHG', '000538.XSHE', '600900.XSHG', '002470.XSHE', '600600.XSHG', '600153.XSHG', '002304.XSHE', '600104.XSHG', '000333.XSHE', '600873.XSHG', '600578.XSHG', '000999.XSHE', '002294.XSHE', '601006.XSHG', '600177.XSHG']
buylist 24
['600027.XSHG', '000559.XSHE', '601899.XSHG', '000895.XSHE', '000876.XSHE', '000539.XSHE', '600276.XSHG', '600011.XSHG', '601006.XSHG', '000538.XSHE', '600900.XSHG', '002470.XSHE', '600600.XSHG', '600153.XSHG', '600332.XSHG', '002304.XSHE', '600104.XSHG', '000333.XSHE', '600873.XSHG', '600578.XSHG', '000999.XSHE', '002294.XSHE', '000712.XSHE', '600177.XSHG']
buylist 21
['600276.XSHG', '600900.XSHG', '600104.XSHG', '600011.XSHG', '600887.XSHG', '600873.XSHG', '600027.XSHG', '601006.XSHG', '600663.XSHG', '600018.XSHG', '000538.XSHE', '601899.XSHG', '600863.XSHG', '002470.XSHE', '002304.XSHE', '000999.XSHE', '000895.XSHE', '000876.XSHE', '600153.XSHG', '600177.XSHG', '000712.XSHE']
buylist 22
['601601.XSHG', '600027.XSHG', '000876.XSHE', '600276.XSHG', '600011.XSHG', '600887.XSHG', '600863.XSHG', '000538.XSHE', '002470.XSHE', '600332.XSHG', '002304.XSHE', '601377.XSHG', '600104.XSHG', '000333.XSHE', '600873.XSHG', '601628.XSHG', '002294.XSHE', '600663.XSHG', '000712.XSHE', '600886.XSHG', '601318.XSHG', '600177.XSHG']
buylist 22
['601216.XSHG', '600027.XSHG', '000895.XSHE', '000876.XSHE', '600011.XSHG', '600887.XSHG', '000538.XSHE', '002470.XSHE', '600649.XSHG', '600332.XSHG', '002304.XSHE', '601377.XSHG', '600104.XSHG', '000333.XSHE', '600873.XSHG', '600578.XSHG', '600741.XSHG', '601628.XSHG', '000999.XSHE', '600795.XSHG', '600663.XSHG', '601318.XSHG']
buylist 26
['601216.XSHG', '600340.XSHG', '000876.XSHE', '600276.XSHG', '600011.XSHG', '600887.XSHG', '601006.XSHG', '600018.XSHG', '000538.XSHE', '002470.XSHE', '000069.XSHE', '600332.XSHG', '002304.XSHE', '601377.XSHG', '600104.XSHG', '000333.XSHE', '600578.XSHG', '601628.XSHG', '000999.XSHE', '002294.XSHE', '600795.XSHG', '600663.XSHG', '600863.XSHG', '600060.XSHG', '601318.XSHG', '600177.XSHG']
buylist 28
['002304.XSHE', '601216.XSHG', '600027.XSHG', '601111.XSHG', '601899.XSHG', '000878.XSHE', '600018.XSHG', '000895.XSHE', '600276.XSHG', '600887.XSHG', '601006.XSHG', '601601.XSHG', '601088.XSHG', '002470.XSHE', '000069.XSHE', '600332.XSHG', '600597.XSHG', '601377.XSHG', '600873.XSHG', '600578.XSHG', '600649.XSHG', '601628.XSHG', '002294.XSHE', '600795.XSHG', '600663.XSHG', '600863.XSHG', '601318.XSHG', '600177.XSHG']