jbn / ZigZag

Python library for identifying the peaks and valleys of a time series.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to segment data using peak and valleys?

bestazad opened this issue · comments

Hi,
Thank you for your great job. I used the following code to find the peaks and valleys of a stock prince and it worked for that, but what I like to do is slice the time-series based on these peaks and valleys. I will put a picture to explain what I mean:

X = dataset_train.iloc[:, 4]
pivots = peak_valley_pivots(X.values , 0.2, -0.2)
ts_pivots = pd.Series(X, index=X.index)
ts_pivots = ts_pivots[pivots != 0]
plt.figure(0)
X.plot()
ts_pivots.plot(style='g-o');
modes = pivots_to_modes(pivots)
pd.Series(X).pct_change().groupby(modes).describe().unstack()

compute_segment_returns(X, pivots)

http://uupload.ir/files/31v6_sliced.jpeg

In the above pic, I sliced the chart/array using peaks/valleys by hand ti the 12 sub arrays, but what I want to do is doing this by code and make these 12 sub arrays from the original array. How can I do that?