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

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                # 9.2 GMVP · Global Minimum Variance Portfolio (GMVP) > 來源:https://uqer.io/community/share/55461734f9f06c1c3d688030 ```py import pandas as pd import numpy as np start = '2011-07-01' # 回測起始時間 end = '2014-08-01' # 回測結束時間 benchmark = 'SH50' # 策略參考標準 universe = ['601398.XSHG','600028.XSHG', '601988.XSHG', '600036.XSHG','600030.XSHG','601318.XSHG', '600000.XSHG', '600019.XSHG', '600519.XSHG', '601166.XSHG'] capital_base = 100000 # 起始資金 longest_history = 40 # handle_data 函數中可以使用的歷史數據最長窗口長度 refresh_rate = 10 # 調倉頻率,即每 refresh_rate 個交易日執行一次 handle_data() 函數 def initialize(account): # 初始化虛擬賬戶狀態 pass def handle_data(account): # 每個交易日的買入賣出指令 history_data = account.get_attribute_history('closePrice',40) retmatrix = [] for s in account.universe: retmatrix.append([history_data[s][i]/ history_data[s][i - 1] for i in range(1,40) ]) retmatrix = np.array(retmatrix) covmatrix = np.cov(retmatrix, y=None, rowvar=1, bias=0, ddof=None) covmatrix = np.matrix(covmatrix) # 不加這句執行矩陣求逆報錯 covinv = np.linalg.inv(covmatrix) one_row = np.matrix(np.ones(len(account.universe))) one_vector = np.matrix(np.ones(len(account.universe))).transpose() up = np.dot(covinv, one_vector) down = np.dot(np.dot(one_row, covinv), one_vector) weights = up/down weightsum = 0 for a in weights: weightsum += a index= 0 for s in account.universe: weigh = weights[index]/weightsum index = index + 1 amount = account.cash * weigh / account.referencePrice[s] order_to(s,amount) ``` ![](https://box.kancloud.cn/2016-07-30_579cbdb389595.jpg) just implement the examples in the API doc
                  <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>

                              哎呀哎呀视频在线观看