系统编译器问题

用户成长系列
标签: #<Tag:0x00007fa19efe4d30>

(arthur_2008) #1

感觉平台系统的编译器很差啊,我在主函数体中自定义稍微复杂一些的函数就编译不过去(在其他Python平台可以通过),请问怎样解决呢,感觉给个人的算法自由度空间太小了


(adhaha111) #2

您可以分享下策略吗


(arthur_2008) #3

不是策略,是一个编码函数,对K线编码,参数与编码由机器学习模型计算得出。整个函数用到的逻辑运算比较多,但也不应该有问题啊。在聚宽平台上通过测试的,想移植到宽邦平台发现移植不了。
def coder(open_0,high_0,low_0,close_0,open_1,high_1,low_1,close_1):
close_open = (close_0 - open_0)/close_1
rise_range = (high_0 - low_0)/close_1
drop_range = (min(open_0,close_0) - low_0)/close_1
coder = 102

# 参数
level1 = 0.05
level2 = 0.04
level3 = -0.03
level4 = 0.02
level5 = 0.04
level6 = -0.03
level7 = 0.03
level8 = 0.02
    
if(open_0 > high_1):       
    if((close_open>=level5) and (drop_range<level7) and (rise_range>level8)):
        coder = 11
    elif((close_open>=level5) and (drop_range<level7) and (rise_range<level8)):
        coder = 12
    elif((close_open>=level5) and (drop_range>level7) and (rise_range>level8)):
        coder = 13
    elif((close_open>=level5) and (drop_range>level7) and (rise_range<level8)):
        coder = 14
    elif((close_open>=0) and (close_open<level5) and (drop_range<level7) and (rise_range>level8)):
        coder = 23
    elif((close_open>=0) and (close_open<level5) and (drop_range<level7) and (rise_range<level8)):
        coder = 24
    elif((close_open>=0) and (close_open<level5) and (drop_range>level7) and (rise_range>level8)):
        coder = 25
    elif((close_open>=0) and (close_open<level5) and (drop_range>level7) and (rise_range<level8)):
        coder = 26
    else:
        pass

    if(close_0 >= close_1):       
        if((close_open<=level6) and (drop_range<level7) and (rise_range>level8)):
            coder = 15
        elif((close_open<=level6) and (drop_range<level7) and (rise_range<level8)):
            coder = 16
        elif((close_open<=level6) and (drop_range>level7) and (rise_range>level8)):
            coder = 17
        elif((close_open<=level6) and (drop_range>level7) and (rise_range<level8)):
            coder = 18
        elif((close_open<0) and (close_open>level6) and (drop_range<level7) and (rise_range>level8)):
            coder = 27
        elif((close_open<0) and (close_open>level6) and (drop_range<level7) and (rise_range<level8)):
            coder = 28
        elif((close_open<0) and (close_open>level6) and (drop_range>level7) and (rise_range>level8)):
            coder = 29
        elif((close_open<0) and (close_open>level6) and (drop_range>level7) and (rise_range<level8)):
            coder = 30
        else:
            pass

    if(close_0 < close_1):       
        if((close_open<=level6) and (drop_range<level7) and (rise_range>level8)):
            coder = 19
        elif((close_open<=level6) and (drop_range<level7) and (rise_range<level8)):
            coder = 20
        elif((close_open<=level6) and (drop_range>level7) and (rise_range>level8)):
            coder = 21
        elif((close_open<=level6) and (drop_range>level7) and (rise_range<level8)):
            coder = 22
        elif((close_open<0) and (close_open>level6) and (drop_range<level7) and (rise_range>level8)):
            coder = 31
        elif((close_open<0) and (close_open>level6) and (drop_range<level7) and (rise_range<level8)):
            coder = 32
        elif((close_open<0) and (close_open>level6) and (drop_range>level7) and (rise_range>level8)):
            coder = 33
        elif((close_open<0) and (close_open>level6) and (drop_range>level7) and (rise_range<level8)):
            coder = 34
        else:
            pass

elif(open_0 < low_1):   
    if(close_0 >= close_1):       
        if((close_open>=level5) and (drop_range<level7) and (rise_range>level8)):
            coder = 39
        elif((close_open>=level5) and (drop_range<level7) and (rise_range<level8)):
            coder = 40
        elif((close_open>=level5) and (drop_range>level7) and (rise_range>level8)):
            coder = 41
        elif((close_open>=level5) and (drop_range>level7) and (rise_range<level8)):
            coder = 42
        elif((close_open>=0) and (close_open<level5) and (drop_range<level7) and (rise_range>level8)):
            coder = 51
        elif((close_open>=0) and (close_open<level5) and (drop_range<level7) and (rise_range<level8)):
            coder = 52
        elif((close_open>=0) and (close_open<level5) and (drop_range>level7) and (rise_range>level8)):
            coder = 53
        elif((close_open>=0) and (close_open<level5) and (drop_range>level7) and (rise_range<level8)):
            coder = 54
        else:
            pass

    if(close_0 < close_1):      
        if((close_open>=level5) and (drop_range<level7) and (rise_range>level8)):
            coder = 35
        elif((close_open>=level5) and (drop_range<level7) and (rise_range<level8)):
            coder = 36
        elif((close_open>=level5) and (drop_range>level7) and (rise_range>level8)):
            coder = 37
        elif((close_open>=level5) and (drop_range>level7) and (rise_range<level8)):
            coder = 38
        elif((close_open>=0) and (close_open<level5) and (drop_range<level7) and (rise_range>level8)):
            coder = 47
        elif((close_open>=0) and (close_open<level5) and (drop_range<level7) and (rise_range<level8)):
            coder = 48
        elif((close_open>=0) and (close_open<level5) and (drop_range>level7) and (rise_range>level8)):
            coder = 49
        elif((close_open>=0) and (close_open<level5) and (drop_range>level7) and (rise_range<level8)):
            coder = 50
        else:
            pass

    if((close_open<=level6) and (drop_range<level7) and (rise_range>level8)):
        coder = 43
    elif((close_open<=level6) and (drop_range<level7) and (rise_range<level8)):
        coder = 44
    elif((close_open<=level6) and (drop_range>level7) and (rise_range>level8)):
        coder = 45
    elif((close_open<=level6) and (drop_range>level7) and (rise_range<level8)):
        coder = 46
    elif((close_open<0) and (close_open>level6) and (drop_range<level7) and (rise_range>level8)):
        coder = 55
    elif((close_open<0) and (close_open>level6) and (drop_range<level7) and (rise_range<level8)):
        coder = 56
    elif((close_open<0) and (close_open>level6) and (drop_range>level7) and (rise_range>level8)):
        coder = 57
    elif((close_open<0) and (close_open>level6) and (drop_range>level7) and (rise_range<level8)):
        coder = 58
    else:
        pass

else:     
    if(close_0 >= close_1):       
        if((close_open>=level5) and (drop_range<level7) and (rise_range>level8)):
            coder = 63
        elif((close_open>=level5) and (drop_range<level7) and (rise_range<level8)):
            coder = 64
        elif((close_open>=level5) and (drop_range>level7) and (rise_range>level8)):
            coder = 65
        elif((close_open>=level5) and (drop_range>level7) and (rise_range<level8)):
            coder = 66
        elif((close_open>=0) and (close_open<level5) and (drop_range<level7) and (rise_range>level8)):
            coder = 79
        elif((close_open>=0) and (close_open<level5) and (drop_range<level7) and (rise_range<level8)):
            coder = 80
        elif((close_open>=0) and (close_open<level5) and (drop_range>level7) and (rise_range>level8)):
            coder = 81
        elif((close_open>=0) and (close_open<level5) and (drop_range>level7) and (rise_range<level8)):
            coder = 82 
        elif((close_open<=level6) and (drop_range<level7) and (rise_range>level8)):
            coder = 67
        elif((close_open<=level6) and (drop_range<level7) and (rise_range<level8)):
            coder = 68
        elif((close_open<=level6) and (drop_range>level7) and (rise_range>level8)):
            coder = 69
        elif((close_open<=level6) and (drop_range>level7) and (rise_range<level8)):
            coder = 70
        elif((close_open<0) and (close_open>level6) and (drop_range<level7) and (rise_range>level8)):
            coder = 83
        elif((close_open<0) and (close_open>level6) and (drop_range<level7) and (rise_range<level8)):
            coder = 84
        elif((close_open<0) and (close_open>level6) and (drop_range>level7) and (rise_range>level8)):
            coder = 85
        elif((close_open<0) and (close_open>level6) and (drop_range>level7) and (rise_range<level8)):
            coder = 86
        else:
            pass

    if(close_0 < close_1):       
        if((close_open>=level5) and (drop_range<level7) and (rise_range>level8)):
            coder = 59
        elif((close_open>=level5) and (drop_range<level7) and (rise_range<level8)):
            coder = 60
        elif((close_open>=level5) and (drop_range>level7) and (rise_range>level8)):
            coder = 61
        elif((close_open>=level5) and (drop_range>level7) and (rise_range<level8)):
            coder = 62
        elif((close_open>=0) and (close_open<level5) and (drop_range<level7) and (rise_range>level8)):
            coder = 75
        elif((close_open>=0) and (close_open<level5) and (drop_range<level7) and (rise_range<level8)):
            coder = 76
        elif((close_open>=0) and (close_open<level5) and (drop_range>level7) and (rise_range>level8)):
            coder = 77
        elif((close_open>=0) and (close_open<level5) and (drop_range>level7) and (rise_range<level8)):
            coder = 78
        elif((close_open<=level6) and (drop_range<level7) and (rise_range>level8)):
            coder = 71
        elif((close_open<=level6) and (drop_range<level7) and (rise_range<level8)):
            coder = 72
        elif((close_open<=level6) and (drop_range>level7) and (rise_range>level8)):
            coder = 73
        elif((close_open<=level6) and (drop_range>level7) and (rise_range<level8)):
            coder = 74
        elif((close_open<0) and (close_open>level6) and (drop_range<level7) and (rise_range>level8)):
            coder = 87
        elif((close_open<0) and (close_open>level6) and (drop_range<level7) and (rise_range<level8)):
            coder = 88
        elif((close_open<0) and (close_open>level6) and (drop_range>level7) and (rise_range>level8)):
            coder = 89
        elif((close_open<0) and (close_open>level6) and (drop_range>level7) and (rise_range<level8)):
            coder = 90
        else:
            pass
               
return coder

(adhaha111) #4

您好,如果您是在回测模块中进行的编写,那么是无法编译的,预计算因子close_0等目前只能在特征列表和标注模块使用


(arthur_2008) #5

您好,我在空白策略中编译测试的。问题是这样,整个函数可以编译通过并输出结果,但耗时太长,一般要3-4个小时;如果将函数体后面代码隐去,速度就快很多,感觉后面代码不复杂啊,只是一些简单逻辑运算组合而已;在回测模块中编译测试就更慢了,可以输出结果,但要一昼夜,第二天早晨才能看到结果。感觉宽邦平台模块化是方便了很多,但封装了太多东西,离python底层平台太远,反倒降低了专业python编程者的效率。


(adhaha111) #6

好的,您的问题已经向工程师反映,后续会进行相应改正