均線+MACD+成交額選股

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

用米筐的框架跑的,主要考慮短線量?jī)r(jià)因素,選出來(lái)的股票池比較大,據(jù)說(shuō)效果還是比較好的。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容