Porfolio(现金比率+负债现金+现金保障倍数)+市盈率
来源:https://uqer.io/community/share/566a896bf9f06c6c8a91cae7
?DataAPI.MktStockFactorsOneDayGet
import numpy as np
import pandas as pd
start = '2015-01-01'
end = '2015-11-30'
benchmark = 'HS300'
universe = set_universe('HS300')
capital_base = 100000
freq = 'd'
refresh_rate = 1
def initialize(account):
pass
def handle_data(account):
market_val = DataAPI.MktEqudGet(tradeDate=account.current_date,field=u"secID,negMarketValue",pandas="1")
factor = DataAPI.MktStockFactorsOneDayGet(tradeDate=account.current_date,field='secID,ROE,ROA,CashRateOfSales,FinancialExpenseRate,CashToCurrentLiability,OperCashInToCurrentLiability,GrossIncomeRatio,NetProfitRatio,PE,PB',pandas="1")
factor.set_index('secID',inplace=True);
sec_val_mkt = {'symbol':[], 'factor_value':[], 'market_value':[]}
x='CashToCurrentLiability'
y='OperCashInToCurrentLiability'
z='PE'
for stock in account.universe:
sec_val_mkt['symbol'].append(stock)
factor_va=float(1/3*factor.ix[stock][x]+1/3*factor.ix[stock][y]+1/3*factor.ix[stock][z]);
sec_val_mkt['factor_value'].append(factor_va)
sec_val_mkt['market_value'].append(float(market_val.negMarketValue[market_val.secID==stock]))
sec_val_mkt = pd.DataFrame(sec_val_mkt).sort(columns='factor_value',ascending=True).reset_index()
sec_val_mkt = sec_val_mkt[:int(len(sec_val_mkt)*0.1)]
buylist = list(sec_val_mkt.symbol)
sum_market_val = sum(sec_val_mkt.market_value)
position = np.array(sec_val_mkt.market_value)/sum_market_val*account.cash
for stock in account.valid_secpos:
if stock not in buylist:
order_to(stock, 0)
for stock in buylist:
if stock not in account.valid_secpos:
order(stock, position[buylist.index(stock)])
return
bt.blotter
None