A single-factor stock selection strategies - Small Cap Strategies
Second, multi-factor stock selection strategies - market value + ROE (return on equity) stock-picking strategy
A single-factor stock selection strategies - Small Cap Strategies
Factor stock selection strategies
Factor: Select the stock of a certain standard
Growth rate, market value, earnings, ROE (return on equity) ............
Stock-picking strategy:
For a factor, select the best performance (maximum or minimum factor) in N positions stocks
Every once in a while to adjust positions once, if no period of time can sell up change
Small-cap strategy: Choose the smallest market capitalization of the stock pool of stocks positions N
For example: Select 20 minimum market capitalization of stocks held once a month tune warehouse:
from jqdata Import * DEF the initialize (context): set_benchmark ( ' 000300.XSHG ' ) Set_Option ( ' use_real_price ' , True) set_order_cost (OrderCost (close_tax = from 0.001, open_commission = 0.0003, = 0.0003 close_commission, min_commission =. 5), type = ' Stock ' ) g.security = get_index_stocks ( ' 000300.XSHG ' ) # selected from the market as factors, from the table of valuation market_cap of fields taken query object sqlachmy GQ = query (valuation) .filter (valuation.code.in_ (G. Security)) gN = 20 # 20 minimum stock market # assumption factor stock picking is performed every 30 days # Mode 1: # g.days = -1 # DEF the handle_data (context, Data): # g.days. 1 = + # IF % 30 == 0 g.days: # Pass # way: # a timing to execute the function, the first trading day of each month handle functions performed run_monthly (handle, 1 ) DEF handle (context): DF = get_fundamentals (GQ) [ [ ' code ' , ' market_cap ' ]] DF = df.sort_values ( ' market_cap ').iloc[:g.N,:] #选出20支 print(df) to_hold = df['code'].values for stock in context.portfolio.positions: if stock not in to_hold: order_target(stock, 0) to_buy = [stock for stock in to_hold if stock not in context.portfolio.positions] if len(to_buy) > 0: cash_per_stock = context.portfolio.available_cash / len(to_buy) for stock in to_buy: order_value(stock, cash_per_stock)
Second, multi-factor stock selection strategies - market value + ROE (return on equity) stock-picking strategy
Multi-factor stock selection strategies
How to simultaneously integrated multiple factor stock selection?
Scoring model:
Each stock is scored for each factor, the scores are added
The total score of N elect largest stock holdings
How to calculate the score in a stock factors: normalization (standardization), Below are two standardized way
For example, choose two factors: market value and ROE (return on equity) as the stock selection evaluation criteria
from jqdata import * def initialize(context): set_benchmark('000300.XSHG') set_option('use_real_price', True) set_order_cost(OrderCost(close_tax=0.001, open_commission=0.0003, close_commission=0.0003, min_commission=5), type='stock') g.security = get_index_stocks('000300.XSHG') # 选市值作为因子,要从表valuation中market_cap字段获取sqlachmy的query对象 g.q = query(valuation, indicator).filter(valuation.code.in_(g.security)) g.N = 20 #20支股票 run_monthly(handle, 1) def handle(context): df = get_fundamentals(g.q)[['code','market_cap','roe']] df['market_cap'] = (df['market_cap']-df['market_cap'].min())/(df['market_cap'].max()-df['market_cap'].min()) df['roe'] = (df['roe']-df['roe'].min())/(df['roe'].max()-df['roe'].min()) # 双因子评分:市盈率越大越好,市值越小越好 df['score'] = df['roe'] - df['market_cap'] # 对评分排序,选最大的20支股票 df = df.sort_values('score').iloc[-g.N:,:] to_hold = df['code'].values for stock in context.portfolio.positions: if stock not in to_hold: order_target(stock, 0) to_buy = [stock for stock in to_hold if stock not in context.portfolio.positions] if len(to_buy) > 0: cash_per_stock = context.portfolio.available_cash / len(to_buy) for stock in to_buy: order_value(stock, cash_per_stock)