1

I am using Pyalgotrade (usually in combination with ta-lib indicators), but I am missing a function to find a local maxima and minima in the data series.

I am aware of the min and max functions, but this is not what I am looking for. E. g. MIN(low, count=5) would give me the lowest of 5 bars, but this does not look outside the 5 values. I am looking for a function returning the value of a "local low" over a certain period, i. e. the value was lower then two days before and after that day.

Example

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

I hope it's clear what I mean. Is ther any function for this purpose that I might have overlooked.

EDIT

To find a low in a data series, I came up with something like this ...

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

... but I am not very happy with this solution, because I think it's not very efficient to parse the series backwards. I assume something built-in running natively would probably be way faster.

Kind Regards,

Ale

Ale
  • 247
  • 3
  • 10

3 Answers3

1

PyAlgoTrade has a method that can help you for ta-lib called bar_ds_close_to_numpy or more generally value_ds_to_numpy where count is the count of bars that you are looking back. Convert your Dataseries to a numpy array and simply use the min and max functions

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)
Vinay Gode
  • 111
  • 4
0

I like to help you here sense we share interest (algotrading), though I sit in node.js and I'm not to familiar with python, though I have some experience...

...anyway, the solution is imo very simple, just slice the array.
...sense it's imo this easy, I could ofc have misunderstood the question. If so, pls comment and I see if I can update my answer to help you.


Edit


MIN/MAX takes some parameters:

  • inReal : array of data
  • startIdx : where to start looking from
  • endIdx : where to stop looking
  • optInTimePeriod : not sure what it does in this context :/

Idk if these are exposed to you..? but sounds like this is where you should look to solve what you want to do..

superhero
  • 6,281
  • 11
  • 59
  • 91
  • Sure the solution is simple, but using an optimized package or external library like ta-lib is usually an order of magnitude faster during execution. My hope was, that there is something I could reuse – Ale May 09 '17 at 20:47
0

I am looking for something similar yet a simple solution would be to arrange the data array in order numerically ascending.

Then take the first item in the array as the MIN and the last item in the array as the MAX value.

Im not sure if this is the best approach yet, however it seems to work logically correct.

The problem i am facing is how to know when the peak and the floors need to be measured each time to match the charts. However this maybe an accurate way of doing it.

centralhubb.com
  • 2,705
  • 19
  • 17