Let's say I have a list of values like this:
100
99
90
79
62
94
88
75
80
72
74
87
84
90
I would like to look for the peaks and troughs in the numbers. However, I want to ignore small movements because the data may not go down consecutively until it reaches the trough and I would like to remove the ‘noise’ from the data.
I want to ignore small changes in price that are 10% or lower than the original peak or trough. This 10% move could span over several rows, it's a cumulative move.
It’s easy to see from the data that the first trough comes at 62. That is because there is no movement that goes in the opposite direction that is over 10%
It is also easy to see the next peak because 94 is way higher than 10% and it starts moving back down after that.
However the tricky part is after 75 it goes upwards to 80 which I’d like to ignore because the next row finally reaches a trough of 72. This small upward movement isn't enough to invalidate the trend.
Then it goes to 74, 87, 84 & 90 which qualifies for a new peak because it is over 10% and doesn’t get invalidated by a 10% movement in the opposite direction.
So if I were a great programmer, I’d like to make a printout of the data like this:
First peak = 100
First trough = 62
Second peak = 94
Second trough = 72
Third peak = 90
It’s quite easy to do this as a human but I’m having a lot of trouble programming it in python. I would be extremely grateful if anyone could help me with this problem.
100
99
90
79
62
94
88
75
80
72
74
87
84
90
I would like to look for the peaks and troughs in the numbers. However, I want to ignore small movements because the data may not go down consecutively until it reaches the trough and I would like to remove the ‘noise’ from the data.
I want to ignore small changes in price that are 10% or lower than the original peak or trough. This 10% move could span over several rows, it's a cumulative move.
It’s easy to see from the data that the first trough comes at 62. That is because there is no movement that goes in the opposite direction that is over 10%
It is also easy to see the next peak because 94 is way higher than 10% and it starts moving back down after that.
However the tricky part is after 75 it goes upwards to 80 which I’d like to ignore because the next row finally reaches a trough of 72. This small upward movement isn't enough to invalidate the trend.
Then it goes to 74, 87, 84 & 90 which qualifies for a new peak because it is over 10% and doesn’t get invalidated by a 10% movement in the opposite direction.
So if I were a great programmer, I’d like to make a printout of the data like this:
First peak = 100
First trough = 62
Second peak = 94
Second trough = 72
Third peak = 90
It’s quite easy to do this as a human but I’m having a lot of trouble programming it in python. I would be extremely grateful if anyone could help me with this problem.