<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和Contrarian在中國市場的測試 > 來源:https://uqer.io/community/share/549b5bc8f9f06c4bb8863237 ## Momentum 策略思路 + Momentum:業績好的股票會繼續保持其上漲的勢頭,業績差的股票會保持其下跌的勢頭 策略實現 + Momentum:每次調倉將股票按照前一段時間的累計收益率排序并分組,買入歷史累計收益 最高 的那一組 ```py start = datetime(2011, 1, 1) # 回測起始時間 end = datetime(2014, 8, 1) # 回測結束時間 benchmark = 'HS300' # 使用滬深 300 作為參考標準 universe = set_universe('SH50') # 股票池,上證50 capital_base = 100000 # 起始資金 refresh_rate = 10 window = 20 def initialize(account): # 初始化虛擬賬戶狀態 account.amount = 300 account.universe = universe add_history('hist', window) def handle_data(account, data): # 每個交易日的買入賣出指令 momentum = {'symbol':[], 'c_ret':[]} for stk in account.hist: if 'closePrice' in account.hist[stk].columns: momentum['symbol'].append(stk) momentum['c_ret'].append(account.hist[stk].iloc[window-1,:]['closePrice']/account.hist[stk].iloc[0,:]['closePrice']) momentum = pd.DataFrame(momentum).sort(columns='c_ret').reset_index() momentum = momentum[len(momentum)*4/5:len(momentum)] buylist = momentum['symbol'].tolist() for stk in account.position.stkpos: if (stk not in buylist) and (account.position.stkpos[stk]>0): order_to(stk, 0) for stk in buylist: if account.position.stkpos.get(stk, 0)==0: order_to(stk, account.amount) ``` ![](https://box.kancloud.cn/2016-07-30_579cbb05affdc.jpg) ## Contrarian 策略思路 + Contrarian:股票在經過一段時間的上漲之后會出現回落,一段時間的下跌之后會出現反彈 策略實現 + Contrarian:每次調倉將股票按照前一段時間的累計收益率排序并分組,買入歷史累計收益 最低 的那一組 ```py start = datetime(2011, 1, 1) # 回測起始時間 end = datetime(2014, 8, 1) # 回測結束時間 benchmark = 'HS300' # 使用滬深 300 作為參考標準 universe = set_universe('SH50') # 股票池,上證50 capital_base = 100000 # 起始資金 refresh_rate = 10 window = 20 def initialize(account): # 初始化虛擬賬戶狀態 account.amount = 300 account.universe = universe add_history('hist', window) def handle_data(account, data): # 每個交易日的買入賣出指令 contrarian = {'symbol':[], 'c_ret':[]} for stk in account.hist: if 'closePrice' in account.hist[stk].columns: contrarian['symbol'].append(stk) contrarian['c_ret'].append(account.hist[stk].iloc[window-1,:]['closePrice']/account.hist[stk].iloc[0,:]['closePrice']) contrarian = pd.DataFrame(contrarian).sort(columns='c_ret').reset_index() contrarian = contrarian[:len(contrarian)/5] buylist = contrarian['symbol'].tolist() for stk in account.position.stkpos: if (stk not in buylist) and (account.position.stkpos[stk]>0): order_to(stk, 0) for stk in buylist: if account.position.stkpos.get(stk, 0)==0: order_to(stk, account.amount) ``` ![](https://box.kancloud.cn/2016-07-30_579cbb05c5552.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>

                              哎呀哎呀视频在线观看