【基本面指标】Cash Cow

来源:https://uqer.io/community/share/55418287f9f06c1c3d687fde

策略思路

每个季度,计算沪深300成分股资产负债表中的 现金及现金等价物/总资产 ,数值以最近一次披露的财报为准

清仓,选出该比率最大的前30只股票,将资金分成30份,分别买入

每60个交易日调仓一次

  1. from heapq import nlargest
  2. from datetime import timedelta
  3. start = '2010-01-01'
  4. end = '2015-04-01'
  5. benchmark = 'HS300'
  6. universe = set_universe('HS300')
  7. capital_base = 500000
  8. refresh_rate = 60
  9. def initialize(account):
  10. pass
  11. def handle_data(account):
  12. cashpct = getCashPct(account.universe, account.current_date)
  13. buylist = nlargest(30, cashpct, key=cashpct.get)
  14. for stock in account.valid_secpos:
  15. order_to(stock, 0)
  16. for stock in buylist:
  17. order(stock, int(account.referencePortfolioValue/len(buylist)/account.referencePrice[stock]/100)*100)
  18. def getCashPct(universe, date):
  19. start, end = (date - timedelta(weeks=26)).strftime('%Y%m%d'), date.strftime('%Y%m%d')
  20. N = len(universe)
  21. if N == 0:
  22. return None
  23. elif N <= 45:
  24. batches = [universe]
  25. else:
  26. batches = [universe[i:i+45] for i in range(0, N, 45)]
  27. CashPct = {}
  28. for sub in batches:
  29. df = DataAPI.FdmtBSGet(secID=','.join(sub), publishDateBegin=start, publishDateEnd=end, field=['secID', 'cashCEquiv', 'TAssets'])
  30. for stock in sub:
  31. try:
  32. df_sub = df[df.secID==stock]
  33. df_sub['pct'] = df_sub['cashCEquiv'] / df_sub['TAssets']
  34. CashPct[stock] = df_sub['pct'].mean()
  35. except:
  36. pass
  37. return CashPct

【基本面指标】Cash Cow - 图1