Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to segment data using peak and valleys? #6

Open
bestazad opened this issue Apr 7, 2019 · 0 comments
Open

How to segment data using peak and valleys? #6

bestazad opened this issue Apr 7, 2019 · 0 comments

Comments

@bestazad
Copy link

bestazad commented Apr 7, 2019

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant