Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/360.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Pyalgotrade在Dataseries中查找最近的峰值(最小值或最大值)_Python_Ta Lib_Pyalgotrade - Fatal编程技术网

Python Pyalgotrade在Dataseries中查找最近的峰值(最小值或最大值)

Python Pyalgotrade在Dataseries中查找最近的峰值(最小值或最大值),python,ta-lib,pyalgotrade,Python,Ta Lib,Pyalgotrade,我正在使用Pyalgotrade(通常与ta lib指标结合使用),但我缺少一个函数来查找数据系列中的局部最大值和最小值 我知道最小和最大函数,但这不是我想要的。 例如。MIN(low,count=5)将给出5条中的最低值,但这不会超出5条值。我正在寻找一个函数,它返回某个时间段内的“局部低点”值,即。E该值低于当天前后两天的值 范例 Series [2,3,2,1,3,4,5,6,6] MIN(5) -> returns 3, but the lowest value is on th

我正在使用Pyalgotrade(通常与ta lib指标结合使用),但我缺少一个函数来查找数据系列中的局部最大值和最小值

我知道最小和最大函数,但这不是我想要的。 例如。MIN(low,count=5)将给出5条中的最低值,但这不会超出5条值。我正在寻找一个函数,它返回某个时间段内的“局部低点”值,即。E该值低于当天前后两天的值

范例

Series [2,3,2,1,3,4,5,6,6]

MIN(5) -> returns 3, but the lowest value is on the left border of the observed window
          and the day before, the value was even lower!

whatiamlookingfor() -> should return 1, 
                       because it is the last local low over a +/-2 days period
我希望我的意思很清楚。有没有我可能忽略的功能

编辑

为了在数据系列中找到一个低点,我想出了这样的方法

def min_peak(series, interval):
    reference = -1
    left = reference - interval
    while -reference < len(series):
        if min(series[left:]) == min(series[reference:]):
            return min(series[left:])
        reference -= 1
        left -= 1
def最小峰值(系列、间隔):
引用=-1
左=参考-间隔
而-参考
。。。但是我对这个解决方案不是很满意,因为我认为向后解析序列不是很有效。我认为一些内置的本地运行可能会快得多

亲切问候,


Ale

我想在这里帮助您感受到我们的共同兴趣(algotrading),尽管我坐在node.js中,我对python不太熟悉,尽管我有一些经验

…无论如何,解决方案非常简单,只需对阵列进行切片。
…感觉到这很容易,我可能是ofc误解了这个问题。如果是这样,请评论,我看看我是否可以更新我的答案来帮助你


编辑


最小值/最大值采用一些参数:

  • inReal:数据数组
  • startIdx:从何处开始查看
  • endIdx:停止查看的位置
  • optInTimePeriod:不确定它在此上下文中的作用:/

Idk如果这些都暴露给你了。。?但听起来你应该在这里解决你想做的事情。

PyAlgoTrade有一种方法可以帮助你找到一个名为
bar\u-close\u-to\u-numpy
的ta库,或者更一般地说
value\u-ds\u-to\u-numpy
其中count是你正在回首的条数。将数据系列转换为numpy数组,只需使用
min
max
函数即可

from pyalgotrade.talibext.indicator import bar_ds_close_to_numpy

prices_close = bar_ds_close_to_numpy(resampled_bars, count)
highest_price = np.max(prices_close)
lowest_price = np.min(prices_close)

当然,解决方案很简单,但是在执行过程中,使用优化包或像ta lib这样的外部库通常要快一个数量级。我的希望是,有一些东西我可以重复使用