• 数据分析--动量策略vs反转策略(选股)


    动量策略:

      如果某只股票在前一段时期表现较好,那么下一段时期该股票扔将有良好表现。

    反转策略:

      如果某只股票在前一段时期表现不好,那么下一段时期该股票将会反转,即表现变好。

    动量策略&反转策略

      计算股票池中所有股票在前一段时间的收益率

      选择收益率最大(最小)的N只股票调仓,动量策略选最大,反转策略选最小

    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.N = 10 
        g.benchmark = '000300.XSHG'
        run_monthly(handle, 1)
        
    def handle(context):
        
        stocks = get_index_stocks(g.benchmark)
        
        df_close = history(30, field='close', security_list=list(stocks)).T
        
        df_close['ret'] = (df_close.iloc[:,-1]-df_close.iloc[:,0])/df_close.iloc[:,0]
        sorted_stocks = df_close.sort_values('ret', ascending=False).index
        
        to_hold = sorted_stocks[:g.N]
    
        for stock in context.portfolio.positions:
            if stock not in to_hold:
                order_target_value(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)
    动量策略

    把里面的“sorted_stocks = df_close.sort_values('ret', ascending=False).index” False 改为True就是反转策略

  • 相关阅读:
    segnet 编译与测试
    ubuntu(已经配置了python2+opencv)简易配置python3的opencv:
    OCR光学字符识别--STN-OCR 测试
    阿里云图形界面
    win10+UEFI下u盘安装ubuntu16.04
    ubuntu16.04+cuda8.0+cudnn5.0+caffe
    Angular 组件通讯、生命周期钩子 小结
    Angular 路由⑦要素
    关于克隆gitlab项目的一些 问题列表
    RxJS学习笔记
  • 原文地址:https://www.cnblogs.com/staff/p/10963985.html
Copyright © 2020-2023  润新知