<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之旅 廣告
                # 5.8 SMIA · 基于歷史狀態空間相似性匹配的行業配置 SMIA 模型—取交集 > 來源:https://uqer.io/community/share/55e00e38f9f06c521f156a86 ## 行業輪動分析 本文主要參考廣發金工的研報《基于歷史狀態空間相似性匹配的行業配置SMIA 模型》中所用的方法,通過量化實驗室平臺完成實證的過程。 ## 1.策略思想 隨機過程可以劃分為有記憶性特征和無記憶性特征兩種。行業輪動具有記憶性,即當期行業的相對表現會影響下一期行業的相對表現,這是由行業之間錯綜復雜的經濟關系所決定的。我們通過尋找歷史狀態空間中與當期行業收益率排名相似的一些時間點,觀察這些時間點之后一期行業輪動的變化特征,從中選取統計上表現較好的行業,作為當前時間點下一期的推薦超配行業,從而實現相似性匹配行業配置(Similarity Matching Industry Allocation,縮寫為SMIA)量化模型的構建。 ## 2.實證過程 ```py def distanceGet(history, test): #計算歐式距離 distance = sum((history - test).values**2) return distance ``` 下面的策略作了一些改變,變成行業之間取交集。需要測試別的距離的效果,也可以在上面的函數直接改哦。 ```py start = '2014-01-01' # 回測起始時間 end = '2015-01-01' # 回測結束時間 benchmark = 'HS300' # 策略參考標準 universe = universeGet(getIndustryInfo()) # 證券池,支持股票和基金 capital_base = 1000000 # 起始資金 freq = 'd' # 策略類型,'d'表示日間策略使用日線回測,'m'表示日內策略使用分鐘線回測 refresh_rate = 22 # 調倉頻率,表示執行handle_data的時間間隔,若freq = 'd'時間間隔的單位為交易日,若freq = 'm'時間間隔為分鐘 Select_Match = 3 # 選取三個最相似的行業市場排名狀態 Select_Order = 14 # 選取收益率最高的十四個行業 fixYield = DataFrame(fixInd_meanYield).rank(axis=1) #將收益率矩陣變為序號矩陣 def initialize(account): # 初始化虛擬賬戶狀態 pass #總體思路是根據調倉時期,將最近22個交易日的的收益率按行業排序,拿之前所有數據源進行匹配,用歐式距離找出最接近的排序的3期,選取它們的下一期,再挑選出這些期行業收益率前兩個名的行業。 def handle_data(account): # 每個交易日的買入賣出指令 today = account.current_date if today.strftime("%Y-%m-%d") == '2014-01-02' : #當回測開始調倉時(2014-01-01元旦不交易,順延到1月2號),不需要調用addYield(current_date)函數 fixYield_history = fixYield.ix[:len(fixYield)-2] #將最后一期之前的數據,作為匹配數據源 fixYield_test = fixYield.ix[len(fixYield)-1] #選取最后一期數據來和其他數據源做匹配 distance = pd.Series(np.zeros(len(fixYield_history ))) #初始化 for i in xrange(len(fixYield_history)): distance[i] = distanceGet(fixYield_history.ix[i],fixYield_test ) sort_distance = distance.order() #按distance中的值排序,然而其索引值仍保留 indexSort = sort_distance.index #distance的索引并沒有改變,我們得到了它的索引,就可以反過來在fixYield中找到最匹配的源數據 #industryList = [] industryList = set() intersectionList = set() for i in xrange(Select_Match): Match_Period = dict(fixYield.ix[indexSort[i]+1]) #取distance值在前3的索引,將這個索引加1,得到最匹配的數據源的下一期 #industryList = industryList + nlargest(Select_Order, Match_Period, key=Match_Period.get) #取收益率最高的四個索引(行業) industryList = set(nlargest(Select_Order, Match_Period, key=Match_Period.get)) if i == 0: intersectionList = industryList else: intersectionList = intersectionList & industryList #industryList = list(set(industryList)) #得到我們選出的行業 intersectionList = list(intersectionList) else: addInd_meanYield = addYield(account.current_date) #除去最開始調倉,我們都需要調用addYield(current_date)得到更多的數據源 addInd_meanYield = DataFrame(addInd_meanYield).rank(axis=1) #將收益率矩陣變序號矩陣 addInd_meanYield_history = addInd_meanYield.ix[:len(addInd_meanYield)-2] #將這些數據也作為匹配數據源 addInd_meanYield_test = addInd_meanYield.ix[len(addInd_meanYield)-1] #選取最后一期數據來和其他數據源做匹配 distance = pd.Series(np.zeros(len(addInd_meanYield_history)+len(fixYield ))) for i in xrange(len(fixYield)): distance[i] = distanceGet(fixYield.ix[i],addInd_meanYield_test) for i in xrange(len(fixYield),len(fixYield) + len(addInd_meanYield_history)): distance[i] = distanceGet(addInd_meanYield_history.ix[i-len(fixYield)],addInd_meanYield_test) sort_distance = distance.order() indexSort = sort_distance.index #industryList = [] industryList = set() intersectionList = set() for i in xrange(Select_Match): #選取3個匹配 if indexSort[i]+1 < len(fixYield): #若找的日期不超過fixYield的范圍,直接計算。 Match_Period = dict(fixYield.ix[indexSort[i]+1]) #industryList = industryList + nlargest(Select_Order, Match_Period, key=Match_Period.get) industryList = set(nlargest(Select_Order, Match_Period, key=Match_Period.get)) elif indexSort[i]+1 < len(distance) : #若找到的日期不超過所有數據期數減一,但超過了fixYield的范圍,則匹配在addInd_meanYield_history中 Match_Period = dict(addInd_meanYield_history.ix[indexSort[i]+1-len(fixYield)]) #industryList = industryList + nlargest(Select_Order, Match_Period, key=Match_Period.get) industryList = set(nlargest(Select_Order, Match_Period, key=Match_Period.get)) else: #這里其實就是找到了本身,其匹配源數據找到了上一期 Match_Period = dict(addInd_meanYield_test) #industryList = industryList + nlargest(Select_Order, Match_Period, key=Match_Period.get) industryList = set(nlargest(Select_Order, Match_Period, key=Match_Period.get)) if i == 0: intersectionList = industryList else: intersectionList = intersectionList & industryList #industryList = list(set(industryList)) intersectionList = list(intersectionList) buyList = [] for key in indContent: if key in intersectionList: buyList = buyList + indContent[key] #除去不在account.universe以及停牌和新股 for stk in buyList[:]: if stk not in account.universe or account.referencePrice[stk] == 0 or np.isnan(account.referencePrice[stk]): buyList.remove(stk) for stk in account.valid_secpos: order_to(stk, 0) for stk in buyList: order(stk, account.referencePortfolioValue/account.referencePrice[stk]/len(buyList)) ``` ![](https://box.kancloud.cn/2016-07-30_579cbdad0aae6.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>

                              哎呀哎呀视频在线观看