<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                # 輕松跑贏大盤 - 主題Momentum策略 > 來源:https://uqer.io/community/share/551d02c2f9f06c8f33904502 ## 策略原理 在我們的觀點中,Momentum這樣的思路在主題中也有體現, 業績好的主題會繼續保持其上漲的勢頭, 本策略測試了這個思路, 具體實現方式為: 按20個交易日為一個調倉周期, 在調倉日賣出以前所有持倉, 買入選出的最好的20個主題中最好的5只股票總共100只股票 本策略的回測參數如下: + 起始日期: 2014年12月24日 + 結束日期: 2015年4月24日 + 股票池: 3月25日所有活躍主題關聯的所有股票 + 業績基準: 滬深300 + 起始資金: 1000萬元 + 調倉周期: 20個交易日 本策略使用的主要數據API有: + `DataAPI.ActiveThemesGet` 獲取某天活躍的主題數據,輸入一個日期,獲取在該日期活躍的主題。 + `DataAPI.TickersByThemesGet` 獲取主題關聯的證券 還有很多可以根據基本面調優的辦法, 讀者可以自己嘗試 ```py from datetime import datetime,timedelta from heapq import nlargest #ticker轉換為id tk2id=lambda x: x+'.XSHG' if x[0]=='6'else x+'.XSHE' #獲取3月25日活躍主題對應的所有股票 themeList = DataAPI.ActiveThemesGet('20150325').themeID.tolist() sa = [] for t in themeList: sa += DataAPI.TickersByThemesGet(themeID=str(t)).ticker.tolist() sa = list(set(sa)) #以下為回測參數 start = '2014-12-24' end = '2015-04-24' benchmark = 'HS300' universe = map(tk2id, sa) capital_base = 10000000 refresh_rate = 20 longest_history = 20 def initialize(account): pass def handle_data(account): # 獲取調倉日活躍主題相關股票tickers themeList = DataAPI.ActiveThemesGet(account.current_date.strftime('%Y%m%d')).themeID.tolist() ta = {} for t in themeList: ta[t] = DataAPI.TickersByThemesGet(themeID=str(t)).ticker.tolist() # 獲取過去20個交易日的收盤價 p = account.get_attribute_history('closePrice', 20) #找調倉日內按照等權return加和最大的20個主題 sa = {} for stock in account.universe: sa[stock] = p[stock][-1] / p[stock][0] -1 #從調倉日之前20天的return tb = {} for t in ta: tb[t] = sum(sa.get(s,0) for s in ta[t]) tb = nlargest(20,tb,tb.get) # 找這最好的20個主題中最好的5只股票 sc = [] for t in tb: sc += nlargest(5,[s for s in map(tk2id,ta[t]) if s in sa],sa.get) sc = list(set(sc)) for stock in account.valid_secpos: # 賣出目前所有持有的股票 order_to(stock, 0) for stock in sc: # 買進新選出的100只股票 order(stock, account.referencePortfolioValue / len(sc) / p[stock][-1]) ``` ![](https://box.kancloud.cn/2016-07-30_579cbdab98f0a.jpg)
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看