您現(xiàn)在的位置:程序化交易>> 期貨公式>> 交易開拓者(TB)>> 開拓者知識(shí)>>正文內(nèi)容

請問這個(gè)策略有偷價(jià)或者未來函數(shù)行為嗎?回測效果很好 [開拓者 TB]

  • 咨詢內(nèi)容: import pandas as pd
    import numpy as np

    def init(context):
        context.s1 = '000001.XSHG'
        context.max_num_stocks = 40
        context.days = 0
        context.period_days = 1
        context.relative_strength_6m = {}

    def period_passed(context):
        return context.days % context.period_days == 0
       
    def before_trading(context):
        context.days += 1
        if not period_passed(context):
            return
       
        dofilter(context)
        update_universe(context.fundamental_df.columns.values)

    def dofilter(context):
       
        fundamental_df = get_fundamentals(
            query(fundamentals.eod_derivative_indicator.market_cap)
            .order_by(fundamentals.eod_derivative_indicator.market_cap.asc())
            .limit(context.max_num_stocks)
        )
       
        #Update context
        context.stocks = [stock for stock in fundamental_df]
        context.fundamental_df = fundamental_df
       
    def rebalance(context, bar_dict):
       
        for stock in context.portfolio.positions:
            if stock not in context.fundamental_df:
                order_target_percent(stock, 0)
                
        context.stocks = [stock for stock in context.stocks
                          if stock in bar_dict and bar_dict[stock].is_trading and context.relative_strength_6m[stock] <-0.5]
       
        if len(context.stocks) == 0:
            return
       
        weight = 1.0/len(context.stocks)
       
        for stock in context.stocks:
            order_target_percent(stock, weight)
       
    def handle_bar(context, bar_dict):
       
        his = history(10, '1d', 'close')['000001.XSHG']
       
        if period_passed(context):
            if his[9]/his[8]< 0.97:
                if len(context.portfolio.positions)>0:
                    for stock in context.portfolio.positions.keys():
                        order_target_percent(stock, 0)
                return
       
        if not period_passed(context):
            return
       
        compute_relative_strength(context,bar_dict)
        rebalance(context, bar_dict)
       
    def compute_relative_strength(context,bar_dict):
       
        prices = history (150, '1d', 'close')

        #過去六個(gè)月的價(jià)格變化率
        pct_change = (prices.ix[149] - prices.ix[19]) / prices.ix[19]
        #print(prices.ix[19])
        #print(pct_change)
        priceofbase = history (150, '1d', 'close')[context.s1]
        pct_changeforbase = (priceofbase.ix[149] - priceofbase.ix[19]) / priceofbase.ix[19]
        pct_change = pct_change - pct_changeforbase
        print(pct_change.index)
        print(bar_dict)
        if pct_changeforbase != 0:
            pct_change = pct_change / abs(pct_changeforbase)
        context.relative_strength_6m = pct_change

     

  • TB技術(shù)人員: 你這個(gè)代碼都不是TB的,怎么回測的?

     

  • TB客服: 本帖最后由 bahuang 于 2016-2-26 08:40 編輯

    這里也有人用python

 

有思路,想編寫各種指標(biāo)公式,程序化交易模型,選股公式,預(yù)警公式的朋友

可聯(lián)系技術(shù)人員 QQ: 511411198  點(diǎn)擊這里給我發(fā)消息進(jìn)行 有償 編寫!不貴!點(diǎn)擊查看價(jià)格!


【字體: 】【打印文章】【查看評論

相關(guān)文章

    沒有相關(guān)內(nèi)容
主站蜘蛛池模板: 国产男靠女免费视频网站| 成人片黄网站色大片免费观看app| 免费无码黄网站在线观看| 免费观看成人羞羞视频软件| 好男人影视社区www在线观看| 五月开心播播网| 狠狠色噜噜狠狠狠狠av| 国产乱子伦在线观看| 18禁美女裸体无遮挡网站| 年轻人影院www你懂的| 久久精品国产精品青草| 毛片免费观看网站| 可以看污的网站| 黄页在线播放网址| 国内精品一区二区三区最新| 中文字幕一区二区三区在线播放| 极品人体西西44f大尺度| 人妻中文字幕乱人伦在线| 高清韩国a级特黄毛片| 国产精品爽黄69天堂a| silk131中字在线观看| 无码熟妇αⅴ人妻又粗又大| 亚洲av综合色区无码一区爱av | 久久久受www免费人成| 欧美国产日本高清不卡| 人妻无码久久一区二区三区免费| 胸大的姑娘动漫视频| 国产在线视频网| 884hutv四虎永久7777| 在线天堂中文www官网| 一区视频在线播放| 日产精品久久久久久久性色| 亚洲av无码乱码国产精品fc2| 正在播放高级会所丰满女技师| 别揉我胸啊嗯~| 色一情一区二区三区四区| 国产女高清在线看免费观看| 老司机精品视频在线观看| 国产视频一区二区在线播放| freexx性欧美另类hd偷拍| 影音先锋女人aa鲁色资源|