V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
OceanCafe
V2EX  ›  Python

利用 Python 实现格雷厄姆价值投资

  •  
  •   OceanCafe · 2017-07-11 16:42:48 +08:00 · 1831 次点击
    这是一个创建于 2483 天前的主题,其中的信息可能已经有所发展或是发生改变。
    ### **Life is short,I use python to invest..囧**
    ### **今天给大家分享

    ![alt text]( https://dn-ricequant.qbox.me/forum/upload-66e71217-1351-4dfd-ba5b-923d3d554a67.jpg)

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

    著名的 Graham number 适用于 Defensive investor (防御型投资者),既然是防御保守型的投资者,那么除了较低的 PE 和 PB ratio 以外,还需要考察一个超经典的价值投资策略**

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

    ### **著名的 Graham number 公式**公司的其他几个方面(不然就选到垃圾股了)

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

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

    赚钱能力,利润持续增长

    **PE ratio < 15**

    **PB ratio <1.5**

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


    ### 这是收益图
    ![alt text]( https://alicdn.ricequant.com/upload/b1/b9ae956b997775b69e3bbfc62e797eb1.png)

    ### 这是源码
    源码在 <a herf="www.ricequant.com">Ricequant</a>实现

    ```
    # 可以自己 import 我们平台支持的第三方 python 模块,、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
    ```
    4ever911
        1
    4ever911  
       2017-07-11 20:11:46 +08:00
    life is short, so please don't spam here.
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   989 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 19:33 · PVG 03:33 · LAX 12:33 · JFK 15:33
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.