请 [注册] 或 [登录]  | 返回主站

量化交易吧 /  量化平台 帖子:3364736 新帖:0

改进版多头排列

K线达人发表于:5 月 10 日 07:53回复(1)

提高一点效率

import time
# 改进版多头排列,提高效率
def dtpl(stock_list=None):
    if stock_list is None:
        stock_list=stocksum=get_all_securities('stock').index
    dtpl=[]
    for i in stock_list:
        close = attribute_history(i, 60, '1d', ['close'])['close']
        current_price=close[-1]
        ma5=close[-5:].mean()
        if current_price>ma5:
            ma10=close[-10:].mean()
            if ma5>ma10:    
                ma20=close[-20:].mean()
                if ma10>ma20:    
                    ma60=close[-60:].mean()
                    if ma20>ma60:
                        dtpl.append(i)
    return dtpl

t1=time.time()
dt=dtpl()
time.time()-t1,dt
(5.197290897369385,
 ['000002.XSHE',
  '000017.XSHE',
  '000024.XSHE',
  '000027.XSHE',
  '000035.XSHE',
  '000036.XSHE',
  '000043.XSHE',
  '000049.XSHE',
  '000063.XSHE',
  '000068.XSHE',
  '000159.XSHE',
  '000166.XSHE',
  '000400.XSHE',
  '000409.XSHE',
  '000415.XSHE',
  '000416.XSHE',
  '000502.XSHE',
  '000505.XSHE',
  '000506.XSHE',
  '000509.XSHE',
  '000525.XSHE',
  '000532.XSHE',
  '000549.XSHE',
  '000562.XSHE',
  '000563.XSHE',
  '000576.XSHE',
  '000589.XSHE',
  '000603.XSHE',
  '000606.XSHE',
  '000608.XSHE',
  '000609.XSHE',
  '000616.XSHE',
  '000617.XSHE',
  '000618.XSHE',
  '000622.XSHE',
  '000628.XSHE',
  '000656.XSHE',
  '000659.XSHE',
  '000667.XSHE',
  '000668.XSHE',
  '000686.XSHE',
  '000691.XSHE',
  '000695.XSHE',
  '000712.XSHE',
  '000719.XSHE',
  '000723.XSHE',
  '000726.XSHE',
  '000728.XSHE',
  '000739.XSHE',
  '000750.XSHE',
  '000757.XSHE',
  '000767.XSHE',
  '000777.XSHE',
  '000783.XSHE',
  '000787.XSHE',
  '000791.XSHE',
  '000800.XSHE',
  '000802.XSHE',
  '000803.XSHE',
  '000806.XSHE',
  '000811.XSHE',
  '000812.XSHE',
  '000835.XSHE',
  '000850.XSHE',
  '000876.XSHE',
  '000902.XSHE',
  '000906.XSHE',
  '000913.XSHE',
  '000922.XSHE',
  '000931.XSHE',
  '000936.XSHE',
  '000960.XSHE',
  '000962.XSHE',
  '000966.XSHE',
  '000968.XSHE',
  '000987.XSHE',
  '000997.XSHE',
  '001696.XSHE',
  '001979.XSHE',
  '002002.XSHE',
  '002004.XSHE',
  '002026.XSHE',
  '002032.XSHE',
  '002054.XSHE',
  '002058.XSHE',
  '002061.XSHE',
  '002072.XSHE',
  '002080.XSHE',
  '002085.XSHE',
  '002090.XSHE',
  '002112.XSHE',
  '002124.XSHE',
  '002126.XSHE',
  '002127.XSHE',
  '002146.XSHE',
  '002150.XSHE',
  '002152.XSHE',
  '002157.XSHE',
  '002174.XSHE',
  '002182.XSHE',
  '002187.XSHE',
  '002188.XSHE',
  '002194.XSHE',
  '002199.XSHE',
  '002201.XSHE',
  '002204.XSHE',
  '002208.XSHE',
  '002209.XSHE',
  '002211.XSHE',
  '002219.XSHE',
  '002248.XSHE',
  '002250.XSHE',
  '002260.XSHE',
  '002266.XSHE',
  '002267.XSHE',
  '002272.XSHE',
  '002281.XSHE',
  '002295.XSHE',
  '002306.XSHE',
  '002311.XSHE',
  '002326.XSHE',
  '002328.XSHE',
  '002331.XSHE',
  '002337.XSHE',
  '002349.XSHE',
  '002358.XSHE',
  '002364.XSHE',
  '002376.XSHE',
  '002381.XSHE',
  '002385.XSHE',
  '002388.XSHE',
  '002391.XSHE',
  '002394.XSHE',
  '002399.XSHE',
  '002404.XSHE',
  '002406.XSHE',
  '002413.XSHE',
  '002416.XSHE',
  '002421.XSHE',
  '002425.XSHE',
  '002451.XSHE',
  '002453.XSHE',
  '002455.XSHE',
  '002463.XSHE',
  '002473.XSHE',
  '002476.XSHE',
  '002486.XSHE',
  '002490.XSHE',
  '002495.XSHE',
  '002514.XSHE',
  '002530.XSHE',
  '002532.XSHE',
  '002537.XSHE',
  '002539.XSHE',
  '002543.XSHE',
  '002546.XSHE',
  '002555.XSHE',
  '002560.XSHE',
  '002567.XSHE',
  '002569.XSHE',
  '002584.XSHE',
  '002595.XSHE',
  '002604.XSHE',
  '002608.XSHE',
  '002616.XSHE',
  '002622.XSHE',
  '002633.XSHE',
  '002634.XSHE',
  '002643.XSHE',
  '002644.XSHE',
  '002661.XSHE',
  '002673.XSHE',
  '002674.XSHE',
  '002678.XSHE',
  '002679.XSHE',
  '002687.XSHE',
  '002697.XSHE',
  '002698.XSHE',
  '002702.XSHE',
  '002708.XSHE',
  '002714.XSHE',
  '002715.XSHE',
  '002722.XSHE',
  '002731.XSHE',
  '002736.XSHE',
  '002752.XSHE',
  '002757.XSHE',
  '002760.XSHE',
  '002761.XSHE',
  '002768.XSHE',
  '002785.XSHE',
  '002786.XSHE',
  '002796.XSHE',
  '002797.XSHE',
  '002803.XSHE',
  '002812.XSHE',
  '002816.XSHE',
  '002821.XSHE',
  '002825.XSHE',
  '002839.XSHE',
  '002841.XSHE',
  '002846.XSHE',
  '002849.XSHE',
  '002877.XSHE',
  '002878.XSHE',
  '002884.XSHE',
  '002888.XSHE',
  '002896.XSHE',
  '002901.XSHE',
  '002916.XSHE',
  '002926.XSHE',
  '300001.XSHE',
  '300009.XSHE',
  '300025.XSHE',
  '300033.XSHE',
  '300037.XSHE',
  '300044.XSHE',
  '300057.XSHE',
  '300059.XSHE',
  '300061.XSHE',
  '300068.XSHE',
  '300073.XSHE',
  '300074.XSHE',
  '300089.XSHE',
  '300094.XSHE',
  '300096.XSHE',
  '300103.XSHE',
  '300104.XSHE',
  '300126.XSHE',
  '300130.XSHE',
  '300135.XSHE',
  '300162.XSHE',
  '300169.XSHE',
  '300170.XSHE',
  '300189.XSHE',
  '300201.XSHE',
  '300204.XSHE',
  '300214.XSHE',
  '300224.XSHE',
  '300226.XSHE',
  '300227.XSHE',
  '300230.XSHE',
  '300232.XSHE',
  '300261.XSHE',
  '300267.XSHE',
  '300274.XSHE',
  '300276.XSHE',
  '300278.XSHE',
  '300281.XSHE',
  '300283.XSHE',
  '300300.XSHE',
  '300305.XSHE',
  '300340.XSHE',
  '300341.XSHE',
  '300368.XSHE',
  '300381.XSHE',
  '300388.XSHE',
  '300394.XSHE',
  '300448.XSHE',
  '300449.XSHE',
  '300452.XSHE',
  '300457.XSHE',
  '300473.XSHE',
  '300483.XSHE',
  '300492.XSHE',
  '300495.XSHE',
  '300498.XSHE',
  '300499.XSHE',
  '300505.XSHE',
  '300509.XSHE',
  '300515.XSHE',
  '300521.XSHE',
  '300525.XSHE',
  '300529.XSHE',
  '300530.XSHE',
  '300531.XSHE',
  '300535.XSHE',
  '300539.XSHE',
  '300541.XSHE',
  '300543.XSHE',
  '300548.XSHE',
  '300550.XSHE',
  '300551.XSHE',
  '300573.XSHE',
  '300575.XSHE',
  '300576.XSHE',
  '300581.XSHE',
  '300590.XSHE',
  '300598.XSHE',
  '300600.XSHE',
  '300610.XSHE',
  '300615.XSHE',
  '300632.XSHE',
  '300642.XSHE',
  '300645.XSHE',
  '300650.XSHE',
  '300651.XSHE',
  '300652.XSHE',
  '300662.XSHE',
  '300667.XSHE',
  '300670.XSHE',
  '300680.XSHE',
  '300683.XSHE',
  '300688.XSHE',
  '300689.XSHE',
  '300690.XSHE',
  '300699.XSHE',
  '300702.XSHE',
  '300727.XSHE',
  '300730.XSHE',
  '300735.XSHE',
  '600018.XSHG',
  '600020.XSHG',
  '600025.XSHG',
  '600039.XSHG',
  '600048.XSHG',
  '600053.XSHG',
  '600061.XSHG',
  '600064.XSHG',
  '600074.XSHG',
  '600080.XSHG',
  '600082.XSHG',
  '600089.XSHG',
  '600090.XSHG',
  '600091.XSHG',
  '600095.XSHG',
  '600107.XSHG',
  '600109.XSHG',
  '600120.XSHG',
  '600123.XSHG',
  '600128.XSHG',
  '600130.XSHG',
  '600133.XSHG',
  '600143.XSHG',
  '600150.XSHG',
  '600152.XSHG',
  '600155.XSHG',
  '600156.XSHG',
  '600165.XSHG',
  '600167.XSHG',
  '600177.XSHG',
  '600191.XSHG',
  '600193.XSHG',
  '600198.XSHG',
  '600202.XSHG',
  '600205.XSHG',
  '600208.XSHG',
  '600210.XSHG',
  '600212.XSHG',
  '600215.XSHG',
  '600223.XSHG',
  '600235.XSHG',
  '600242.XSHG',
  '600250.XSHG',
  '600259.XSHG',
  '600270.XSHG',
  '600275.XSHG',
  '600283.XSHG',
  '600284.XSHG',
  '600287.XSHG',
  '600290.XSHG',
  '600296.XSHG',
  '600301.XSHG',
  '600302.XSHG',
  '600306.XSHG',
  '600333.XSHG',
  '600350.XSHG',
  '600355.XSHG',
  '600369.XSHG',
  '600372.XSHG',
  '600373.XSHG',
  '600376.XSHG',
  '600377.XSHG',
  '600383.XSHG',
  '600385.XSHG',
  '600387.XSHG',
  '600390.XSHG',
  '600392.XSHG',
  '600419.XSHG',
  '600420.XSHG',
  '600446.XSHG',
  '600455.XSHG',
  '600462.XSHG',
  '600467.XSHG',
  '600469.XSHG',
  '600478.XSHG',
  '600479.XSHG',
  '600483.XSHG',
  '600491.XSHG',
  '600493.XSHG',
  '600498.XSHG',
  '600505.XSHG',
  '600510.XSHG',
  '600511.XSHG',
  '600529.XSHG',
  '600533.XSHG',
  '600539.XSHG',
  '600546.XSHG',
  '600553.XSHG',
  '600556.XSHG',
  '600573.XSHG',
  '600578.XSHG',
  '600587.XSHG',
  '600591.XSHG',
  '600593.XSHG',
  '600599.XSHG',
  '600604.XSHG',
  '600605.XSHG',
  '600607.XSHG',
  '600611.XSHG',
  '600615.XSHG',
  '600621.XSHG',
  '600623.XSHG',
  '600624.XSHG',
  '600630.XSHG',
  '600635.XSHG',
  '600638.XSHG',
  '600639.XSHG',
  '600643.XSHG',
  '600650.XSHG',
  '600655.XSHG',
  '600657.XSHG',
  '600658.XSHG',
  '600662.XSHG',
  '600671.XSHG',
  '600675.XSHG',
  '600687.XSHG',
  '600689.XSHG',
  '600695.XSHG',
  '600696.XSHG',
  '600705.XSHG',
  '600716.XSHG',
  '600745.XSHG',
  '600746.XSHG',
  '600749.XSHG',
  '600750.XSHG',
  '600753.XSHG',
  '600757.XSHG',
  '600767.XSHG',
  '600774.XSHG',
  '600783.XSHG',
  '600784.XSHG',
  '600807.XSHG',
  '600817.XSHG',
  '600828.XSHG',
  '600830.XSHG',
  '600836.XSHG',
  '600837.XSHG',
  '600847.XSHG',
  '600861.XSHG',
  '600864.XSHG',
  '600873.XSHG',
  '600875.XSHG',
  '600880.XSHG',
  '600883.XSHG',
  '600885.XSHG',
  '600891.XSHG',
  '600893.XSHG',
  '600895.XSHG',
  '600896.XSHG',
  '600897.XSHG',
  '600908.XSHG',
  '600909.XSHG',
  '600917.XSHG',
  '600919.XSHG',
  '600958.XSHG',
  '600961.XSHG',
  '600973.XSHG',
  '600981.XSHG',
  '600991.XSHG',
  '600997.XSHG',
  '600999.XSHG',
  '601011.XSHG',
  '601019.XSHG',
  '601066.XSHG',
  '601098.XSHG',
  '601099.XSHG',
  '601111.XSHG',
  '601113.XSHG',
  '601158.XSHG',
  '601168.XSHG',
  '601177.XSHG',
  '601179.XSHG',
  '601198.XSHG',
  '601211.XSHG',
  '601226.XSHG',
  '601313.XSHG',
  '601375.XSHG',
  '601377.XSHG',
  '601519.XSHG',
  '601555.XSHG',
  '601616.XSHG',
  '601668.XSHG',
  '601688.XSHG',
  '601788.XSHG',
  '601866.XSHG',
  '601878.XSHG',
  '601880.XSHG',
  '601881.XSHG',
  '601928.XSHG',
  '601958.XSHG',
  '601968.XSHG',
  '601989.XSHG',
  '603010.XSHG',
  '603027.XSHG',
  '603033.XSHG',
  '603038.XSHG',
  '603040.XSHG',
  '603058.XSHG',
  '603059.XSHG',
  '603088.XSHG',
  '603208.XSHG',
  '603222.XSHG',
  '603266.XSHG',
  '603268.XSHG',
  '603269.XSHG',
  '603300.XSHG',
  '603305.XSHG',
  '603313.XSHG',
  '603323.XSHG',
  '603326.XSHG',
  '603330.XSHG',
  '603338.XSHG',
  '603357.XSHG',
  '603366.XSHG',
  '603456.XSHG',
  '603519.XSHG',
  '603558.XSHG',
  '603580.XSHG',
  '603586.XSHG',
  '603601.XSHG',
  '603608.XSHG',
  '603617.XSHG',
  '603637.XSHG',
  '603639.XSHG',
  '603655.XSHG',
  '603660.XSHG',
  '603665.XSHG',
  '603685.XSHG',
  '603689.XSHG',
  '603708.XSHG',
  '603718.XSHG',
  '603778.XSHG',
  '603787.XSHG',
  '603811.XSHG',
  '603819.XSHG',
  '603843.XSHG',
  '603858.XSHG',
  '603882.XSHG',
  '603887.XSHG',
  '603895.XSHG',
  '603908.XSHG',
  '603917.XSHG',
  '603922.XSHG',
  '603978.XSHG',
  '603985.XSHG',
  '603989.XSHG'])

全部回复

0/140

量化课程

    移动端课程