首页>文档>Python>Python 入门策略(二)】 Graham+number+格雷厄姆数字价值投资法

Python 入门策略(二)】 Graham+number+格雷厄姆数字价值投资法

Benjamin Graham 是一位价值投资者。他比较有名的有 Graham number 和 Graham formula。

著名的 Graham number 公式22.5∗(�����������ℎ���)∗(�������������ℎ���)22.5∗(EarningPerShare)∗(BookValuePerShare)​

这个 22.5 是怎么来的呢?取自他的观点 -只买便宜的,投资 15 倍以下 pe 和 1.5 倍以下 pb 的股票。

著名的 Graham number 适用于 Defensive investor (防御型投资者),既然是防御保守型的投资者,那么除了较低的 PE 和 PB ratio 以外,还需要考察公司的其他几个方面(不然就选到垃圾股了)

抗风险的大公司,高市值,高销售

偿债能力,不会有破产风险 current ratio>2, long term debt<working captial

赚钱能力,利润持续增长

PE ratio < 15

PB ratio <1.5

这是价值投资的一个大概思路。每个月调仓一次。看下来中长期的投资回报还是相对稳健的。有兴趣的同学可以尝试修改完善。

%%rqalpha_plus -s 20100401 -e 20161031 --account stock 1000000 -fq 1d -p -bm 000001.XSHG
# 可以自己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<15
        )
        .filter(
            fundamentals.eod_derivative_indicator.pb_ratio<1.5
        )
        .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

运行回测的结果如下:
Python 入门策略(二)】 Graham+number+格雷厄姆数字价值投资法

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧