Python 金叉判定

def jincha (context , bar_dict , his ):

     #站上5日线

     def zs5 (context , bar_dict , his ):

        ma_n  = pd. rolling_mean (his ,  5 )

        temp  = his - ma_n

        #temp_s包含了前一天站上五日线得股票代码

        temp_s  =  list (temp [temp > 0 ]. iloc [- 1 ,: ]. dropna ( ). index )

         return temp_s

     #站上10日线

     def zs10 (context , bar_dict , his ):

        ma_n  = pd. rolling_mean (his ,  10 )

        temp  = his - ma_n

        temp_s  =  list (temp [temp > 0 ]. iloc [- 1 ,: ]. dropna ( ). index )

         return temp_s

    

     #金叉突破

     def jc (context , bar_dict , his ):

        mas  = pd. rolling_mean (his , 5 )

        mal  = pd. rolling_mean (his ,  10 )

        temp  = mas - mal

         #temp_jc昨天大于0股票代码

         #temp_r前天大于0股票代码

        temp_jc  =  list (temp [temp > 0 ]. iloc [- 1 ,: ]. dropna ( ). index )

        temp_r  =  list (temp [temp > 0 ]. iloc [- 2 ,: ]. dropna ( ). index )

        temp  =  [ ]

         for stock  in temp_jc:

             if stock  not  in temp_r:

                temp. append (stock )

         return temp

    

     #求三种条件下的股票代码交集

    con1  = zs5 (context , bar_dict , his )

    con2  = zs10 (context , bar_dict , his )

    con3  = jc (context , bar_dict , his )

    tar_list = [con1 ,con2 ,con3 ]

    tarstock  = tar_list [ 0 ]

     for i  in tar_list:

        tarstock  =  list ( set (tarstock ). intersection ( set (i ) ) )

     return tarstock


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部