本文利用对格雷厄姆的价值投资策略进行了量化并将其应用于A股市场上。回测的时间是2010-10-28至2016-10-28,总收益是415%,年化收益是39%。以下是选股策略的简要:

  • PE ratio < 20
  • PB ratio <1.8
  • 抗风险的大公司,高市值,高销售
  • 偿债能力,不会有破产风险; 即流动比率 > 2, 长期债务 < 营运资本
  • 赚钱能力,利润持续增长
  • 每月进行一次调仓

 

回测结果

格雷厄姆的价值投资

格雷厄姆的价值投资

 

量化策略

# 可以自己import我们平台支持的第三方python模块,比如pandas、numpy等。
# 可以自己import我们平台支持的第三方python模块,比如pandas、numpy等。
import pandas as pd
import numpy as np
import datetime
import math

# 在这个方法中编写任何的初始化逻辑。context对象将会在你的算法策略的任何方法之间做传递。
def init(context):

    scheduler.run_monthly(rebalance,8)
    
# 你选择的证券的数据更新将会触发此段逻辑,例如日或分钟历史数据切片或者是实时数据切片更新
def handle_bar(context, bar_dict):
    pass
    
def before_trading(context):
    num_stocks = 10
    
    # 筛选股票
    fundamental_df = get_fundamentals(
        query(
            fundamentals.eod_derivative_indicator.pb_ratio,
            fundamentals.eod_derivative_indicator.pe_ratio,
            fundamentals.financial_indicator.inc_earnings_per_share,
            fundamentals.financial_indicator.inc_profit_before_tax,
            fundamentals.financial_indicator.quick_ratio,
            fundamentals.financial_indicator.earnings_per_share,
            fundamentals.financial_indicator.book_value_per_share,
        )
        .filter(
            fundamentals.eod_derivative_indicator.pe_ratio<20
        )
        .filter(
            fundamentals.eod_derivative_indicator.pb_ratio<1.8
        )
         .filter(
            fundamentals.financial_indicator.inc_earnings_per_share>0
        )
        .filter(
            fundamentals.financial_indicator.inc_profit_before_tax>0
        )
        .filter(
            fundamentals.financial_indicator.current_ratio>2
        )
        .filter(
            fundamentals.financial_indicator.quick_ratio>1
        )
        .order_by(
            fundamentals.eod_derivative_indicator.market_cap.desc()
        ).limit(
            num_stocks
        )
    )

    context.fundamental_df = fundamental_df
    context.stocks = context.fundamental_df.columns.values
    
def rebalance(context,bar_dict):
    
    # 调仓
    for stock in context.portfolio.positions:
        if stock not in context.fundamental_df:
            order_target_percent(stock, 0)

    weight = update_weights(context, context.stocks)

    for stock in context.fundamental_df:
        if weight != 0 and stock in context.fundamental_df:
            order_target_percent(stock,weight)
              
def update_weights(context,stocks):
    if len(stocks) == 0:
        return 0 
    else:   
        weight = .95/len(stocks)
        return weight

第一步:规避具有造成资本永久损失的的风险的股票

1. 识别潜在的诈骗与操控

1.1 应计项目筛选器(Accrual Screens)

STA = Scaled Total Accruals = (CA(t) – CL(t) – DEP(t)) / Total Assets(t)

  • CA = change in current assets – change in cash and equivalents
  • CL = change in current liabilities – change in LT debt included in current liabilities – change in income taxes payable
  • DEP = depreciation and amortization expense
  • P_STA = percentile(STA) among all firms in the universe
  • SNOA = (operating assets (t) – operating liabilities (t)) / total asset (t)
  • P_SNOA = percentile(SNOA) among all firms in the universe
  • COMBOACCRUAL = average(P_STA, P_SNOA)

1.2 诈骗与操控筛选器(Fraud and Manipulation Screen)

Calculate variables:

  • DSRI = days’ sales in receivables index = days’ sales in receivables (t) / days’ sales in receivables (t-1)
  • GMI = gross margin index = Gross margin (t-1) / gross margin (t)
  • AQI = asset quality index = Noncurrent asset other than PPE / total assets
  • SGI = sales growth index = sales (t) / sales (t-1)
  • DEPI = depreciation index = rate of depreciation (t-1) / rate of depreciation (t)
  • SGAI = sales, general and administrative expenses index = SGA expenses (t) / SGA expenses (t-1)
  • LVGI = leverage index = the ratio of total debt to total asset (t) / the ratio of total debt to total asset (t-1)
  • TATA = total accruals to total assets = \bigtriangleupworking capital (excluding cash) – depreciation

Calculate probit probability of manipulation (PROBM) values:

  • PROBM = -4.84 + 0.92 × DSRI + 0.528 × GMI + 0.404 × AQI + 0.892 × SGI + 0.115 × DEPI – 0.172 × SGAI + 4.679 × TATA – 0.327 × LVGI

Calculate probability of manipulation from PROBM:

  • PMAN = CDF(PROBM), where CDF is the cumulative density function for a normal (0, 1) variable.

2. 识别具有高财务危机风险的股票

2.1 财务危机的概率(Probability of Financial Distress (PFA) 

Calculate PFA variables:

  • NIMTAAVG = weighted average (quarter’s net income/MTA)
  • MTA = market value of total assets = book value of liabilities + market cap
  • TLMTA = total liabilities / MTA
  • CASHMTA = cash & equivalents / MTA
  • EXRETAVG = weighted average(log(1 + stock’s return) − log(1 + S&P 500 TR return)
  • SIGMA = annualized stock’s standard deviation over the previous 3 months (daily)
  • RSIZE = log (stock market cap / S&P 500 TR total market value)
  • MB = MTA / adjusted book value
  • Adjusted book value = book value +.1 × (market cap-book value)
  • PRICE = log (recent stock price), capped at $15, so a stock with a stock price of $20, would be given a value of log(15) instead of log(20).

Calculate logit for the probability of financial distress (LPFD) values:

  • LPFD = −20.26 × NIMTAAVG + 1.42 × TLMTA − 7.13 × EXRETAVG + 1.41 × SIGMA − .045 × RSIZE − 2.13 × CASHMTA + .075 × MB − .058 × PRICE − 9.16

Calculate the probability of financial distress (PFD) value:

  • PFD = 1/(1 + e^(-LPFD))

3. 剔除具有造成资本永久损失的风险的股票

同时对以下三项进行筛选:

  • Eliminate all firms in the top 5 percent of the sample based on COMBOACCRUAL.
  • Eliminate all firms in the top 5 percent of the sample based on PMAN.
  • Eliminate all firms in the top 5 percent of the sample based on PFD.

第二步:寻找最廉价的股票

To calculate PRICE we simply calculate EBIT enterprise value for each stock and then rank all stocks on PRICE.

  • PRICE = EBIT/TEV

第三步:寻找最高质量的股票

1. 特许经营权(Franchise Power)

8yr_ROA = Eight-Year Return on Assets (Geometric Average).

  • Return on assets = net income before extraordinary items (t) / total assets (t).
  • P_8yr_ROA = percentile (8yr_ROA) among all stocks in the universe.

8yr_ROC = Eight-Year Return on Capital (Geometric Average).

  • Return on capital = EBIT (t) / capital (t)
  • P_8yr_ROC = percentile (8yr_ROA) among all stocks in the universe.

FCFA = Long-Term Free Cash Flow on Assets

  • Sum (eight-year FCF) / total assets (t)
  • P_CFOA = percentile (FCFA) among all stocks in the universe

MG = Margin Growth

  • Eight-year gross margin growth (geometric average)
  • P_MG = percentile (MG) among all stocks in the universe

MS = Margin Stability

  • Eight-year average gross margin % / eight-year gross margin % standard deviation
  • P_MS = percentile (MS) among all firms in the universe

MM = Margin Max

  • Max (P_MG, P_MS)

P_FP = Franchise Power

  • Percentile (average (P_8yr_ROA, P_8yr_ROC, P_CFOA, MM) among all rms in the universe

2. 财务实力(Financial Strength (FS) )

2.1 当下的盈利能力(Current Profitability)

  • ROA = return on assets
    • Net income before extraordinary items (t) / total assets (t)
    • FS_ROA = 1 if ROA > 0, 0 otherwise
  • FCFTA = free cash flow (t) / total assets (t)
    • FS_FCFTA = 1 if FCFTA > 0, 0 otherwise
  • ACCRUAL = FCFTA – ROA
    • FS_ACCRUAL = 1 if ACCRUAL > 0, 0 otherwise

2.2 稳定性(Stability)

  • LEVER = long-term debt (− 1) / total assets (− 1) − long-term debt (t) / total assets (t)
    • FS_LEVER = 1 if LEVER > 0, 0 otherwise
  • LIQUID = current ratio (t) − current ratio (− 1)
    • FS_LIQUID = 1 if LIQUID > 0, 0 otherwise
  • NEQISS = net equity issuance from − 1 to t
    • FS_NEQISS = 1 if NEQISS > 0, 0 otherwise

2.3 近期的业务提升(Recent Operational Improvements)

  • ROA = year-over-year change in ROA
    • FS_ \bigtriangleupROA = 1 if \bigtriangleupROA > 0, 0 otherwise
  • FCFTA = year-over-year change in FCFTA
    • FS_ \bigtriangleupFCFTA = 1 if \bigtriangleupFCFTA > 0, 0 otherwise
  • MARGIN = year-over-year change in gross margin
    • FS_ \bigtriangleupMARGIN= 1 if \bigtriangleupMARGIN > 0, 0 otherwise
  • TURN = year-over-year change in asset turnover
    • FS_ \bigtriangleupTURN = 1 if \bigtriangleupTURN > 0, 0 otherwise

2.4 P_FS = Financial Strength

  • P_FS = Sum(FS_ROA, FS_FCFTA, FS_ACCRUAL, FS_LEVER, FS_LIQUID,FS_NEQISS, FS_ \bigtriangleupROA, FS_ \bigtriangleupFCFTA, FS_ \bigtriangleupMARGIN, FS_ \bigtriangleupTURN))/10

3. 识别股票的质量

To calculate quality we simply take an average of the franchise power score and the financial strength score. We then rank all firms on QUALITY.

  • QUALITY(质量)= .5 × P_FP + .5 × P_FS

Step I – Screening

  • Quantitative
    • Low market-to-book, low price-to-earnings, high dividend yield, etc.
  • Qualitative
    • Business cycle analysis, franchise-based research, special situations (such as bankruptcies, spin-offs, and restructuring) analysis, etc.

Step II – Initial Valuation

  • Conservative
    • Net Asset Value (NAV) Adjustments
      • Reconstructing a balance sheet, line by line, on a reproduction basis for a more accurate valuation of assets, liabilities, and equity
    • Earnings Power value (EPV) Assumptions – earnings-based inputs
      • Different investors may have their own approaches for particular firms
      • Most valuations end at EPV since most firms are not franchises
    • Franchise Value (FV) Analysis – identifying competitive advantage
      • Return on equity (ROE) > cost of equity OR return on capital (ROC) > weighted-average cost of capital (WACC)
      • Uniqueness by which a firm creates value for its customers
      • Top management manages to perpetuate the FV over time
    •  Growth Value (GV) Analysis – evaluating the logic of growth
      • The economy environment
      • Are firms able to deliver a unique franchise value and keep up substantial innovation?
  • Initial margin of safety assessment
    • Margin of safety = 1 – current stock price / intrinsic value (or book value, or NAV)
    • Rule of thumb – at least 30% to 33%, and preferably larger

Step III – Validations

  • NAV Adjustments – appraiser, auditor, consultant, and/or expert input on select balance sheet adjustments
  • EPV Assumptions – targeted executive discussion items
  • FV Analysis – financial strategy – based inquires and corresponding questions for executive management
  • GV Analysis – do consistent strategic themes support growth initiatives?

Step IV – Final Valuation

  • Margin of safety assessment