<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之旅 廣告
                # 市值最小300指數 > 來源:https://uqer.io/community/share/5604fbe6f9f06c597665ef37 刷爆滬深300 策略名稱: 市值最小300指數 回測時間:2013-01-01 到 2015-09-24 調倉期 :20交易日 策略思想:找A股市場市值最小的300只股票,等權重構建最小300指數 注意 : + 內存不夠請自行縮短回測時間或universe + 此貼有4個!!! ```py import pandas as pd import numpy as np from pandas import Series, DataFrame start = '2013-01-01' # 回測起始時間 end = '2015-09-24' # 回測結束時間 benchmark = 'HS300' # 策略參考標準 universe0 = set_universe('A') # 證券池,支持股票和基金 universe1 = set_universe('HS300') universe2 = set_universe('ZZ500') universe = list(set(universe0).difference(set(universe1+universe2))) #最小市值股一定不在中證500和滬深300 pass capital_base = 100000000 # 起始資金 freq = 'd' # 策略類型,'d'表示日間策略使用日線回測,'m'表示日內策略使用分鐘線回測 refresh_rate = 20 # 調倉頻率,表示執行handle_data的時間間隔,若freq = 'd'時間間隔的單位為交易日,若freq = 'm'時間間隔為分鐘 def initialize(account): # 初始化虛擬賬戶狀態 pass def handle_data(account): # 每個交易日的買入賣出指令 total_money = account.referencePortfolioValue prices = account.referencePrice buylist = [] marketValue = DataFrame() today = account.current_date.strftime('%Y%m%d') for s in range(len(account.universe)/40 + 1): if s == len(account.universe)/40: temp_list = account.universe[s*40:] else : temp_list = account.universe[s*40:(s+1)*40] #MktEqudGet接口一次最多選50個 try: #排除最后一次temp_list為零的可能 marketValue_temp = DataAPI.MktEqudGet(secID = temp_list,tradeDate= today, field=u"secID,marketValue",pandas="1") except : pass marketValue = pd.concat([marketValue,marketValue_temp]) marketValue = marketValue.sort('marketValue',ascending=True).drop_duplicates('secID') marketValue.set_index('secID',inplace=True) marketValue = marketValue.dropna() #排除新股發行日 for s in list(marketValue.index) : if not (np.isnan(prices[s]) or prices[s] == 0) : buylist.append(s) if len(buylist) >= 300 : break sell_list = [x for x in account.valid_secpos if x not in buylist] for stk in sell_list: order_to(stk, 0) for stk in buylist: order_to(stk, int(total_money/300/prices[stk]/100)*100) ``` ![](https://box.kancloud.cn/2016-07-30_579cbdb0b0220.jpg) 更改權重比例 :加權流通市值倒數(越小越買) 買買買! ```py import pandas as pd import numpy as np from pandas import Series, DataFrame start = '2013-01-01' # 回測起始時間 end = '2015-09-24' # 回測結束時間 benchmark = 'HS300' # 策略參考標準 universe0 = set_universe('A') # 證券池,支持股票和基金 universe1 = set_universe('HS300') universe2 = set_universe('ZZ500') universe = list(set(universe0).difference(set(universe1+universe2))) capital_base = 100000000 # 起始資金 freq = 'd' # 策略類型,'d'表示日間策略使用日線回測,'m'表示日內策略使用分鐘線回測 refresh_rate = 20 # 調倉頻率,表示執行handle_data的時間間隔,若freq = 'd'時間間隔的單位為交易日,若freq = 'm'時間間隔為分鐘 def initialize(account): # 初始化虛擬賬戶狀態 pass def handle_data(account): # 每個交易日的買入賣出指令 total_money = account.referencePortfolioValue prices = account.referencePrice buylist = [] marketValue = DataFrame() today = account.current_date.strftime('%Y%m%d') for s in range(len(account.universe)/40 + 1): if s == len(account.universe)/40: temp_list = account.universe[s*40:] else : temp_list = account.universe[s*40:(s+1)*40] #MktEqudGet接口一次最多選50個 try: #排除最后一次temp_list為零的可能 marketValue_temp = DataAPI.MktEqudGet(secID = temp_list,tradeDate= today, field=u"secID,marketValue,negMarketValue",pandas="1") except : pass marketValue = pd.concat([marketValue,marketValue_temp]) marketValue = marketValue.sort('marketValue',ascending=True).drop_duplicates('secID') marketValue.set_index('secID',inplace=True) marketValue = marketValue.dropna() #排除新股發行日 for s in list(marketValue.index) : if not (np.isnan(prices[s]) or prices[s] == 0) : buylist.append(s) if len(buylist) >= 300 : break sell_list = [x for x in account.valid_secpos if x not in buylist] for stk in sell_list: order_to(stk, 0) #加權流通市值倒數購買 weight_list = [] for stk in buylist: weight_list.append(1.0/marketValue['negMarketValue'][stk]) temp_sum = 0 for temp in weight_list: temp_sum += temp weight_list = [x/temp_sum for x in weight_list] i = 0 for stk in buylist: order_to(stk, int(total_money*weight_list[i]/prices[stk]/100)*100) i += 1 ``` ![](https://box.kancloud.cn/2016-07-30_579cbdb0cc785.jpg) 是不是在想賺錢分分鐘了? 您有買300只個股的毛爺爺嗎,啊! 〇_〇- . . 木有?我會告訴你買十只也很叼嗎??? ```py import pandas as pd import numpy as np from pandas import Series, DataFrame start = '2013-01-01' # 回測起始時間 end = '2015-09-24' # 回測結束時間 benchmark = 'HS300' # 策略參考標準 universe0 = set_universe('A') # 證券池,支持股票和基金 universe1 = set_universe('HS300') universe2 = set_universe('ZZ500') universe = list(set(universe0).difference(set(universe1+universe2))) capital_base = 100000000 # 起始資金 freq = 'd' # 策略類型,'d'表示日間策略使用日線回測,'m'表示日內策略使用分鐘線回測 refresh_rate = 20 # 調倉頻率,表示執行handle_data的時間間隔,若freq = 'd'時間間隔的單位為交易日,若freq = 'm'時間間隔為分鐘 def initialize(account): # 初始化虛擬賬戶狀態 pass def handle_data(account): # 每個交易日的買入賣出指令 total_money = account.referencePortfolioValue prices = account.referencePrice buylist = [] marketValue = DataFrame() today = account.current_date.strftime('%Y%m%d') for s in range(len(account.universe)/40 + 1): if s == len(account.universe)/40: temp_list = account.universe[s*40:] else : temp_list = account.universe[s*40:(s+1)*40] #MktEqudGet接口一次最多選50個 try: #排除最后一次temp_list為零的可能 marketValue_temp = DataAPI.MktEqudGet(secID = temp_list,tradeDate= today, field=u"secID,marketValue",pandas="1") except : pass marketValue = pd.concat([marketValue,marketValue_temp]) marketValue = marketValue.sort('marketValue',ascending=True).drop_duplicates('secID') marketValue.set_index('secID',inplace=True) marketValue = marketValue.dropna() #排除新股發行日 for s in list(marketValue.index) : if not (np.isnan(prices[s]) or prices[s] == 0) : buylist.append(s) if len(buylist) >= 10 : break sell_list = [x for x in account.valid_secpos if x not in buylist] for stk in sell_list: order_to(stk, 0) #只買最優十只 for stk in buylist: order_to(stk, int(total_money/10/prices[stk]/100)*100) ``` ![](https://box.kancloud.cn/2016-07-30_579cbdb0e832e.jpg) 我會告訴你有莊家(機構持股)的股票更容易飛 ???   小注 :此策略中`DataAPI.JY.EquInstShJYGet`(恒生聚源接口)暫不開放!!!活躍用戶自行申請 ```py import pandas as pd import numpy as np from pandas import Series, DataFrame start = '2013-01-01' # 回測起始時間 end = '2015-09-24' # 回測結束時間 benchmark = 'HS300' # 策略參考標準 universe0 = set_universe('A') # 證券池,支持股票和基金 universe1 = set_universe('HS300') universe2 = set_universe('ZZ500') universe = list(set(universe0).difference(set(universe1+universe2))) capital_base = 100000000 # 起始資金 freq = 'd' # 策略類型,'d'表示日間策略使用日線回測,'m'表示日內策略使用分鐘線回測 refresh_rate = 20 # 調倉頻率,表示執行handle_data的時間間隔,若freq = 'd'時間間隔的單位為交易日,若freq = 'm'時間間隔為分鐘 def initialize(account): # 初始化虛擬賬戶狀態 pass def handle_data(account): # 每個交易日的買入賣出指令 total_money = account.referencePortfolioValue prices = account.referencePrice buylist = [] marketValue = DataFrame() today = account.current_date.strftime('%Y%m%d') for s in range(len(account.universe)/40 + 1): if s == len(account.universe)/40: temp_list = account.universe[s*40:] else : temp_list = account.universe[s*40:(s+1)*40] #MktEqudGet接口一次最多選50個 try: #排除最后一次temp_list為零的可能 marketValue_temp = DataAPI.MktEqudGet(secID = temp_list,tradeDate= today, field=u"secID,marketValue",pandas="1") except : pass marketValue = pd.concat([marketValue,marketValue_temp]) marketValue = marketValue.sort('marketValue',ascending=True).drop_duplicates('secID') marketValue.set_index('secID',inplace=True) marketValue = marketValue.dropna() # 機構持股 非第一天上市新股 for s in list(marketValue.index) : try : # 處理巨源的數據接口沒有此股 temp = DataAPI.JY.EquInstShJYGet ( secID = s , field = u"instNrfaPct" , pandas = "1" ) except : print account.current_date.strftime('%Y-%m-%d'),' ',s,' ','DataAPI.JY.EquInstShJYGet get wrong' continue #有機構持股 > 30% if temp['instNrfaPct'][0] > 30 and not (np.isnan(prices[s]) or prices[s] == 0) : buylist.append(s) if len(buylist) >= 10 : break sell_list = [x for x in account.valid_secpos if x not in buylist] for stk in sell_list: order_to(stk, 0) for stk in buylist: order_to(stk, int(total_money/10/prices[stk]/100)*100) ``` ![](https://box.kancloud.cn/2016-07-30_579cbdb10f512.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>

                              哎呀哎呀视频在线观看