I have timeseries data for stocks at minute intervals.

What is the best way to calculate incremental growth, for example if I have a stock's price from 9am to 2pm at minute intervals, how can calcule the incremental growth. I don't want to simply calculate the difference between the price at 2pm and 9am, I want to be able to identify stocks which have risen steadily between the two time intervals


3 Answers 3


What stops you looking at lags?

df = data.frame(c(1,2,3,4,4,3,4,5,6,7))
df$delta=lag(df$price, 1)
df$inc = df$price-df$delta

Would yield:

   price delta inc
1      1    NA  NA
2      2     1   1
3      3     2   1
4      4     3   1
5      4     4   0
6      3     4  -1
7      4     3   1
8      5     4   1
9      6     5   1
10     7     6   1

The condition here would be that each value of inc (except the first one) must be $>0$.


Simply calculate the derivative of the price level with respect to your time unit (in other words between two subsequent measurements).

If the derivative is 0 at some interval, it means that the price has been stable. If the derivative is positive, it means that the price has increased in that range. If the derivative is negative, then the price has decreased.

The value of the derivative (regardless of the sign) shows the slope of the change. In other words, the higher the derivative the more aggressive the change towards the direction that is denoted by the sign.

You can easily do this with numpy.diff.

Note: Differentiation is a "noisy" process and can lead to a very edgy graph of the derivative when you plot it, especially if you have sudden changes in the price level. To solve this, you should consider some smoothing tactics such as a moving average filter applied on the calculated values of the derivative or any other low-pass filter.


You could consider something like the Sharpe Ratio (https://en.wikipedia.org/wiki/Sharpe_ratio) with the goal of maximizing that value. Essentially this would translate to finding a stock with the highest return and least volatility. You could calculate a simple version like the following:

$ {Percent Change over Whole Time}/StandardDeviationOfRelativeDifferences $

Relative differences could be the percent change between each minute to minute change divided by the previous minute's value.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.