【问题标题】:from numexpr import evaluate on Quantopian从 numexpr 导入评估 Quantopian
【发布时间】:2019-10-24 18:55:37
【问题描述】:

我正在尝试获取一些技术信息。使用此链接中的一些命令:https://github.com/enigmampc/catalyst/blob/master/catalyst/pipeline/factors/equity/technical.py, 但在 quant.notebook 中我无法获得“从 numexpr 导入评估”,因此未定义评估。 我该如何解决这个问题?

从 numexpr 导入评估

class FastochasticOscillator(CustomFactor):  
inputs=(USEquityPricing.close,USEquityPricing.high,USEquityPricing.low)  
window_safe=True  
window_length=14  

def compute(self, today, assets, out, closes, highs, lows):  
    highest_high= nanmax(highs, axis=0)  
    lowest_low= nanmin(lows, axis=0)  
    latest_close= closes[-1]  

    evaluate(  
        '((tc - ll) / (hh - ll)) * 100',  
        local_dict={  
            'tc':latest_close,  
            'll':lowest_low,  
            'hh':highest_high,  
        },  
        global_dict={},  
    out=out,  
    )  

K= FastochasticOscillator(window_length=14)

返回管道(列={
'K':K,

},screen=base)

我正在使用 Quantopian 笔记本,当我尝试导入时,它给了我这个:InputRejected:从 numexpr 导入评估引发了 ImportError。你的意思是从 numpy 导入 errstate 吗?

【问题讨论】:

  • 由于python对间距很敏感,请正确缩进源代码。
  • 间距有什么问题?它给我的错误是关于未识别的评估函数
  • 当您尝试导入 from numexpr import evaluate 时会发生什么?貌似贴出来的代码本身没有问题,但是无法导入才是问题。
  • @NicholasM,我正在使用 Quantopian 笔记本,当我尝试导入它时,它给了我这个:InputRejected:从 numexpr 导入评估引发了 ImportError。您的意思是从 numpy 导入 errstate 吗?
  • 您应该编辑您的问题以包含该输出。您发布的代码不包含问题(它只是调用evaluate 函数)。真正的问题是尝试导入该函数时失败。

标签: pipeline quantopian


【解决方案1】:

实际上我没有找到在 Quantopian 上导入 numexpr 的方法,但在 Jupyter 上它不会出现问题。因此问题与在线IDE有关。此外,我只是重新编写了 FastOsc ind。以另一种方式在 quantopian 在线 IDE 的管道中使用它。

class Fast(CustomFactor):
    inputs=(USEquityPricing.close,USEquityPricing.high,USEquityPricing.low)  
    window_length=14  
    def compute(self, today, assets, out, close, high, low):
        highest_high= nanmax(high, axis=0)  
        lowest_low= nanmin(low, axis=0)  
        latest_close= close[-1] 

        out[:]= ((latest_close - lowest_low) / (highest_high - lowest_low)*100)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-03-25
    • 1970-01-01
    • 2013-08-17
    • 1970-01-01
    • 2017-04-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多