<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>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                # 最經典的Momentum和Contrarian在中國市場的測試-yanheven改進 > 來源:https://uqer.io/community/share/5663f369f9f06c6c8a91b3af ## Momentum 策略思路 + Momentum:業績好的股票會繼續保持其上漲的勢頭,業績差的股票會保持其下跌的勢頭 策略實現 + Momentum:每次調倉將股票按照前一段時間的累計收益率排序并分組,買入歷史累計收益 最高 的那一組 ```py start = datetime(2011, 1, 1) # 回測起始時間 end = datetime(2015, 12, 5) # 回測結束時間 benchmark = 'HS300' # 使用滬深 300 作為參考標準 universe = set_universe('HS300') # 股票池,滬深 300 capital_base = 100000 # 起始資金 refresh_rate = 10 def initialize(account): # 初始化虛擬賬戶狀態 pass def handle_data(account): # 每個交易日的買入賣出指令 history = account.get_attribute_history('closePrice', 20) momentum = [] holding = account.valid_secpos for stk in history: if stk in account.universe: his = history[stk] change = his[-1] / his[0] momentum.append((stk, change)) momentum = sorted(momentum, key=lambda x: x[1]) momentum = momentum[:10] momentum_list = [i[0] for i in momentum] buy_list = set(momentum_list) - set(holding) sell_list = set(holding) - set(momentum_list) for i in buy_list: try: order_pct_to(i, 0.1) except Exception as e: log.warn(i + str(e)) for i in sell_list: order_to(i, 0) ``` ![](https://box.kancloud.cn/2016-07-30_579cbb05ddc07.jpg) ## Contrarian 策略思路 + Contrarian:股票在經過一段時間的上漲之后會出現回落,一段時間的下跌之后會出現反彈 策略實現 + Contrarian:每次調倉將股票按照前一段時間的累計收益率排序并分組,買入歷史累計收益 最低 的那一組 ```py start = datetime(2011, 1, 1) # 回測起始時間 end = datetime(2015, 12, 5) # 回測結束時間 benchmark = 'HS300' # 使用滬深 300 作為參考標準 universe = set_universe('HS300') # 股票池,滬深 300 capital_base = 100000 # 起始資金 refresh_rate = 10 def initialize(account): # 初始化虛擬賬戶狀態 pass def handle_data(account): # 每個交易日的買入賣出指令 history = account.get_attribute_history('closePrice', 20) momentum = [] holding = account.valid_secpos for stk in history: if stk in account.universe: his = history[stk] change = his[-1] / his[0] momentum.append((stk, change)) momentum = sorted(momentum, key=lambda x: x[1], reverse=True) # if momentum[-1][1] < 1: # log.info(holding) # for i in holding: # order_to(i, 0) # # return momentum = momentum[:10] momentum_list = [i[0] for i in momentum] buy_list = set(momentum_list) - set(holding) sell_list = set(holding) - set(momentum_list) for i in buy_list: try: order_pct_to(i, 0.1) except Exception as e: log.warn(i + str(e)) for i in sell_list: order_to(i, 0) ``` ![](https://box.kancloud.cn/2016-07-30_579cbda7c1cfa.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>

                              哎呀哎呀视频在线观看