# Finding Highest Consistent Rate of Increase in a Trend Curve

I want to find out the days if the [consistent] rate of increase is high / highest and alert to it. Lets say I am amazon and I am counting the numbers of orders placed per second on my store. So now I have orders/second and I find the rate of change by finding the slope between each second.

Now I want to detect the case where my rate of change has been consistently increasing and the time period this has happened in. So if two years ago during christmas for 89 minutes my rate of change has been consistently increasing, I want to detect this.

SO, I want to Find the time during a day for every day in the past year the highest consistent rate of change time period. How do i do this in the most optimal way? I have attached a diagram to help with this. I want to capture the movements within the red boundaries. The graph is the rate of change on the y axis plotted with time on the x axis. So micro movements within this upward trend can be ignored?

(Not sure I understand your question, but I'll give it a shot.)

Say you have a list $$A$$ containing the orders per second at each time step. I.e. $$A[i]$$ contains the orders per sec at step $$i$$.

Then compute the list of differences: $$D[i] := A[i+1] - A[i]$$. This list gives you the ´rate of change´. Now, to find the longest period in which this rate is increasing, just loop through the list:

• Call the length of the longest period of increase $$L_{max}$$. At the beginning we know nothing, so set it to $$0$$.
• Start looping through the list $$D$$, starting at $$D[0]$$.
• If the value of the next cell is bigger than the current one, then we have an increase. This means we have found an interval of length $$1$$ where we have an increase. We temporarily store the length of that interval so set $$L_{{max}_{temp}} = 1$$.
• Go to the next cell. If we again have an increase, we increment $$L_{{max}_{temp}}$$.
• We go on like this, till the increasing stops, which means we have found the end of the 'increasing interval'. At that point, $$L_{{max}_{temp}}$$ contains the length of the $$\textit{increasing interval }$$ we just traveled. This is the longest $$\textit{increasing interval }$$ we have seen so far, so we set $$L_{max} = L_{{max}_{temp}}$$.
• Continue looping through the list in the same way, i.e: when you find a place where you have an increase, start recording its length in $$L_{{max}_{temp}}$$. When the increasing stops, you have reached the end of the current increasing interval, so stop incrementing $$L_{{max}_{temp}}$$. Compare its value to the one of $$L_{max}$$, which contains the length of the biggest increasing interval you have seen so far. If $$L_{{max}_{temp}}$$ is bigger, then you have found a longer increasing interval, so set $$L_{max} = L_{{max}_{temp}}$$.

When you reach the end of the list, $$L_{max}$$ will contain the lenght of the longest increasing interval in the list.

Not sure this description is clear, hope it helps.

• Dear Cedric, Thank you for the answer. I think this is a very good way of solving the problem. I have added a futher diagram to explain a little more of the nuance that i am trying to capture. Also i am not sure if looping through the entire day per second will be optimal computationally (though i will try this) – CodeGeek123 Nov 29 '18 at 12:12