Python中如何实现格雷厄姆价值投资策略
Life is short,I use python to invest…囧
### 今天给大家分享

这个 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
这是价值投资的一个大概思路。每个月调仓一次。看下来中长期的投资回报还是相对稳健的。有兴趣的同学可以尝试修改完善。
### 这是收益图

### 这是源码
源码在 <a herf=“www.ricequant.com”>Ricequant</a>实现
<br># 可以自己 import 我们平台支持的第三方 python 模块,、numpy 等。 <br>import pandas as pd <br>import numpy as np <br>import datetime <br>import math <br> <br># 在这个方法中编写任何的初始化逻辑。context 对象将会在你的算法策略的任何方法之间做传递。 <br>def init(context): <br> <br> <br> scheduler.run_monthly(rebalance,8) <br> <br> <br> <br># 你选择的证券的数据更新将会触发此段逻辑,例如日或分钟历史数据切片或者是实时数据切片更新 <br>def handle_bar(context, bar_dict): <br> <br> pass <br> <br>def before_trading(context): <br> num_stocks = 10 <br> <br> #删选股票 <br> fundamental_df = get_fundamentals( <br> query( <br> fundamentals.eod_derivative_indicator.pb_ratio, <br> fundamentals.eod_derivative_indicator.pe_ratio, <br> fundamentals.financial_indicator.inc_earnings_per_share, <br> fundamentals.financial_indicator.inc_profit_before_tax, <br> fundamentals.financial_indicator.quick_ratio, <br> fundamentals.financial_indicator.earnings_per_share, <br> fundamentals.financial_indicator.book_value_per_share, <br> ) <br> .filter( <br> fundamentals.eod_derivative_indicator.pe_ratio<15 <br> ) <br> .filter( <br> fundamentals.eod_derivative_indicator.pb_ratio<1.5 <br> ) <br> .filter( <br> fundamentals.financial_indicator.inc_earnings_per_share>0 <br> ) <br> .filter( <br> fundamentals.financial_indicator.inc_profit_before_tax>0 <br> ) <br> .filter( <br> fundamentals.financial_indicator.current_ratio>2 <br> ) <br> .filter( <br> fundamentals.financial_indicator.quick_ratio>1 <br> ) <br> .order_by( <br> fundamentals.eod_derivative_indicator.market_cap.desc() <br> ).limit( <br> num_stocks <br> ) <br> ) <br> <br> <br> <br> context.fundamental_df = fundamental_df <br> context.stocks = context.fundamental_df.columns.values <br> <br> <br> <br>def rebalance(context,bar_dict): <br> <br> #调仓 <br> for stock in context.portfolio.positions: <br> if stock not in context.fundamental_df: <br> order_target_percent(stock, 0) <br> <br> <br> <br> weight = update_weights(context, context.stocks) <br> <br> for stock in context.fundamental_df: <br> if weight != 0 and stock in context.fundamental_df: <br> order_target_percent(stock,weight) <br> <br> <br>def update_weights(context,stocks): <br> if len(stocks) == 0: <br> return 0 <br> else: <br> <br> weight = .95/len(stocks) <br> return weight <br>
Python中如何实现格雷厄姆价值投资策略
我无法理解你的问题
life is short, so please don’t spam here.

