【量化】【量化】4天学会天学会python机器学习与量化交易机器学习与量化交易-笔记笔记2(p16~p20)
文章目录文章目录p16 案例:多因子的市值因子选股介绍p17 案例:多因子的市值因子选股演示p18 多因子策略流程、因子数据组成、去极值介绍p19 案例:中位数去极值和3背中位数去极值
p20 案例:3sigma法去极值
平台:https://www.ricequant.com/quant/#?tag=algorithm-ol&id=1339040
api1:https://www.ricequant.com/doc/rqdata-institutional#research-API-get_fundamentals
api2:https://www.ricequant.com/doc/api/python/chn#wizard-stock
p16 案例:多因子的市值因子选股介绍案例:多因子的市值因子选股介绍
多读书,多看“报”(证券研究报告)
p17 案例:多因子的市值因子选股演示案例:多因子的市值因子选股演示
视频:https://www.bilibili.com/video/av55456917?p=17
代码:
def init(context):
context.hs300 = index_components("000300.XSHG")
# before_trading此函数会在每天策略交易开始前被调用,当天只会被调用一次
def before_trading(context):
# 获取过滤的股票
q = query(
fundamentals.eod_derivative_indicator.market_cap
).order_by(
fundamentals.eod_derivative_indicator.market_cap
).filter(
fundamentals.stockcode.in_(context.hs300)
).limit(20)
funds = get_fundamentals(q)
# 获得10只股票的名字
context.stock_list = funds.T.index
def handle_bar(context, bar_dict):
# 卖出
# 去positions里面获取仓位
for stock in context.portfolio.positions.keys():
if stock not in context.stock_list:
order_target_percent(stock, 0)
# 买入
for stock in context.stock_list:
order_target_percent(stock, 1.0/20)
结果:
p18 多因子策略流程、因子数据组成、去极值介绍多因子策略流程、因子数据组成、去极值介绍
视频:https://www.bilibili.com/video/av55456917?p=18
notebook位置:https://www.ricequant.com/research/user/user_358930/tree?
(原来以为功能被删了,后来直接输入网址找到了)
评论5