美文网首页
均线+MACD+成交额选股

均线+MACD+成交额选股

作者: 哈劳斯军士 | 来源:发表于2017-12-07 14:13 被阅读117次
    import datetime
    import talib
    import numpy as np
    import math
    import pandas
    
    def init(context):
        context.stocknum = 30
        context.numberlist = []
    
    def before_trading(context):
        pass
    
    def handle_bar(context,bar_dict):
        pass
    
    def after_trading(context):
        context.pool = []
        for s in all_instruments(type='CS').order_book_id:
            price = history_bars(s,251,'1d','close')
            if len(price)==0 or math.isnan(price[0]):
                pass
            else:
                nowprice = price[-1]
    #            logger.info(str(price))
                ma250 = talib.MA(price, 250)[-1]
                ma200 = talib.MA(price, 200)[-1]
                ma120 = talib.MA(price, 120)[-1]
                # ma60 = talib.MA(price, 60)[-1]
                # ma30 = talib.MA(price, 30)[-1]
                ma20 = talib.MA(price, 20)[-1]
                turnover = history_bars(s,5,'1d','total_turnover')[-1]
                
                macd, signal, hist = talib.MACD(price, fastperiod=12, slowperiod=26, signalperiod=9)
                
                
                if math.isnan(ma250):
                    pass
                else:
                    if (ma250<nowprice) and (ma200<nowprice) and ma120<nowprice and (ma20<nowprice) and turnover>400000000 and macd[-1]>0  and hist[-1]>0:
                        context.pool.append(s)
                    else:
                        pass
                
        logger.info('共有'+str(len(context.poo
    

    用米筐的框架跑的,主要考虑短线量价因素,选出来的股票池比较大,据说效果还是比较好的。

    相关文章

      网友评论

          本文标题:均线+MACD+成交额选股

          本文链接:https://www.haomeiwen.com/subject/sjwwkxtx.html